Guest User

Untitled

a guest
Jun 24th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Reflection;
  4.  
  5. using Machine.Specifications.Example;
  6. using Machine.Specifications.Example.CleanupFailure;
  7. using Machine.Specifications.Runner;
  8. using Machine.Specifications.Runner.Impl;
  9.  
  10. namespace Machine.Specifications.Specs.Runner
  11. {
  12. public class running_specs
  13. {
  14. public static TestListener listener;
  15. public static AppDomainRunner runner;
  16.  
  17. Establish context = () =>
  18. {
  19. listener = new TestListener();
  20. runner = new AppDomainRunner(listener, RunOptions.Default);
  21. };
  22. }
  23.  
  24. public class when_running_specs_by_assembly : running_specs
  25. {
  26. Because of = () =>
  27. runner.RunAssembly(typeof(Account).Assembly);
  28.  
  29. It should_run_them_all = () =>
  30. listener.SpecCount.ShouldEqual(6);
  31. }
  32.  
  33. public class when_running_specs_in_an_assembly_with_a_reference_that_cannot_be_bound : running_specs
  34. {
  35. static Exception Exception;
  36. readonly static string ReferencedAssembly = GetPath("Machine.Specifications.Example.BindingFailure.Ref.dll");
  37.  
  38. Establish context = () =>
  39. {
  40. if (File.Exists(ReferencedAssembly))
  41. {
  42. File.Delete(ReferencedAssembly);
  43. }
  44. };
  45.  
  46. Because of = () =>
  47. runner.RunAssembly(Assembly.LoadFrom(GetPath("Machine.Specifications.Example.BindingFailure.dll")));
  48.  
  49. It should_fail = () =>
  50. listener.LastFatalError.ShouldNotBeNull();
  51. //Exception.ShouldBeOfType<TargetInvocationException>();
  52.  
  53. protected static string GetPath(string path)
  54. {
  55. return Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), path);
  56. }
  57.  
  58. }
  59.  
  60. [Ignore]
  61. public class when_running_specs_in_which_the_cleanup_throws_a_non_serializable_exception : running_specs
  62. {
  63. Because of = () =>
  64. runner.RunAssembly(typeof(cleanup_failure).Assembly);
  65.  
  66. It should_cause_a_fatal_error = () =>
  67. listener.LastFatalError.ShouldNotBeNull();
  68.  
  69. }
  70.  
  71. public class when_running_specs_by_namespace : running_specs
  72. {
  73. Because of = () =>
  74. runner.RunNamespace(typeof(Account).Assembly, "Machine.Specifications.Example");
  75.  
  76. It should_run_them_all = () =>
  77. listener.SpecCount.ShouldEqual(6);
  78. }
  79.  
  80. public class when_running_specs_by_member : running_specs
  81. {
  82. Because of = () =>
  83. runner.RunMember(typeof(Account).Assembly, typeof(when_transferring_an_amount_larger_than_the_balance_of_the_from_account).GetField("should_not_allow_the_transfer", BindingFlags.NonPublic | BindingFlags.Instance));
  84.  
  85. It should_run = () =>
  86. listener.SpecCount.ShouldEqual(1);
  87. }
  88.  
  89. public class TestListener : ISpecificationRunListener
  90. {
  91. public int SpecCount = 0;
  92. public Result LastResult;
  93. public void OnAssemblyStart(AssemblyInfo assembly)
  94. {
  95. }
  96.  
  97. public void OnAssemblyEnd(AssemblyInfo assembly)
  98. {
  99. }
  100.  
  101. public void OnRunStart()
  102. {
  103. LastResult = null;
  104. }
  105.  
  106. public void OnRunEnd()
  107. {
  108. }
  109.  
  110. public void OnContextStart(ContextInfo context)
  111. {
  112. }
  113.  
  114. public void OnContextEnd(ContextInfo context)
  115. {
  116. }
  117.  
  118. public void OnSpecificationStart(SpecificationInfo specification)
  119. {
  120. }
  121.  
  122. public void OnSpecificationEnd(SpecificationInfo specification, Result result)
  123. {
  124. LastResult = result;
  125. SpecCount++;
  126. }
  127.  
  128. public void OnFatalError(ExceptionResult exception)
  129. {
  130. LastFatalError = exception;
  131. }
  132.  
  133. public ExceptionResult LastFatalError { get; private set; }
  134. }
  135. }
Add Comment
Please, Sign In to add comment