|
| 1 | +using System; |
| 2 | +using System.Linq; |
| 3 | +using NUnit.Framework; |
| 4 | +using TestStack.BDDfy.Configuration; |
| 5 | +using TestStack.BDDfy.Core; |
| 6 | +using TestStack.BDDfy.Scanners.StepScanners.ExecutableAttribute.GwtAttributes; |
| 7 | +using TestStack.BDDfy.Scanners.StepScanners.Fluent; |
| 8 | + |
| 9 | +namespace TestStack.BDDfy.Tests.Configuration |
| 10 | +{ |
| 11 | + public class TestRunnerTests |
| 12 | + { |
| 13 | + public class ScenarioWithFailingThen |
| 14 | + { |
| 15 | + [Given] |
| 16 | + public void PassingGiven() |
| 17 | + { |
| 18 | + } |
| 19 | + |
| 20 | + [When] |
| 21 | + public void PassingWhen() |
| 22 | + { |
| 23 | + } |
| 24 | + |
| 25 | + [Then] |
| 26 | + public void FailingThen() |
| 27 | + { |
| 28 | + throw new Exception(); |
| 29 | + } |
| 30 | + |
| 31 | + [AndThen] |
| 32 | + public void PassingAndThen() |
| 33 | + { |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + [TestFixture] |
| 38 | + public class When_StopExecutionOnFailingThen_IsSetToTrue |
| 39 | + { |
| 40 | + [Test] |
| 41 | + public void FailingThenStopsThePipelineWithReflectiveAPI() |
| 42 | + { |
| 43 | + Configurator.Processors.TestRunner.StopExecutionOnFailingThen = true; |
| 44 | + |
| 45 | + try |
| 46 | + { |
| 47 | + var testRun = new ScenarioWithFailingThen().LazyBDDfy(); |
| 48 | + Verify(testRun); |
| 49 | + } |
| 50 | + finally |
| 51 | + { |
| 52 | + Configurator.Processors.TestRunner.StopExecutionOnFailingThen = false; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + [Test] |
| 57 | + public void FailingThenStopsThePipelineWithFluentAPI() |
| 58 | + { |
| 59 | + Configurator.Processors.TestRunner.StopExecutionOnFailingThen = true; |
| 60 | + |
| 61 | + try |
| 62 | + { |
| 63 | + var testRun = new ScenarioWithFailingThen() |
| 64 | + .Given(x => x.PassingGiven()) |
| 65 | + .When(x => x.PassingWhen()) |
| 66 | + .Then(x => x.FailingThen()) |
| 67 | + .And(x => x.PassingAndThen()) |
| 68 | + .LazyBDDfy(); |
| 69 | + |
| 70 | + Verify(testRun); |
| 71 | + } |
| 72 | + finally |
| 73 | + { |
| 74 | + Configurator.Processors.TestRunner.StopExecutionOnFailingThen = false; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + private static void Verify(Engine testRun) |
| 79 | + { |
| 80 | + Assert.Throws<Exception>(() => testRun.Run()); |
| 81 | + var scenario = testRun.Story.Scenarios.First(); |
| 82 | + Assert.AreEqual(StepExecutionResult.Failed, scenario.Result); |
| 83 | + var steps = scenario.Steps; |
| 84 | + |
| 85 | + Assert.AreEqual(4, steps.Count); |
| 86 | + Assert.AreEqual(StepExecutionResult.Passed, steps[0].Result); |
| 87 | + Assert.AreEqual(ExecutionOrder.SetupState, steps[0].ExecutionOrder); |
| 88 | + Assert.AreEqual(StepExecutionResult.Passed, steps[1].Result); |
| 89 | + Assert.AreEqual(ExecutionOrder.Transition, steps[1].ExecutionOrder); |
| 90 | + Assert.AreEqual(StepExecutionResult.Failed, steps[2].Result); |
| 91 | + Assert.AreEqual(ExecutionOrder.Assertion, steps[2].ExecutionOrder); |
| 92 | + Assert.AreEqual(StepExecutionResult.NotExecuted, steps[3].Result); |
| 93 | + Assert.AreEqual(ExecutionOrder.ConsecutiveAssertion, steps[3].ExecutionOrder); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + [TestFixture] |
| 98 | + public class When_StopExecutionOnFailingThen_IsLeftAsDefault |
| 99 | + { |
| 100 | + [Test] |
| 101 | + public void FailingThenDoesNotStopThePipelineWithReflectiveAPI() |
| 102 | + { |
| 103 | + var testRun = new ScenarioWithFailingThen().LazyBDDfy(); |
| 104 | + Verify(testRun); |
| 105 | + } |
| 106 | + |
| 107 | + [Test] |
| 108 | + public void FailingThenDoesNotStopThePipelineWithFluentAPI() |
| 109 | + { |
| 110 | + var testRun = new ScenarioWithFailingThen() |
| 111 | + .Given(x => x.PassingGiven()) |
| 112 | + .When(x => x.PassingWhen()) |
| 113 | + .Then(x => x.FailingThen()) |
| 114 | + .And(x => x.PassingAndThen()) |
| 115 | + .LazyBDDfy(); |
| 116 | + |
| 117 | + Verify(testRun); |
| 118 | + } |
| 119 | + |
| 120 | + private static void Verify(Engine testRun) |
| 121 | + { |
| 122 | + Assert.Throws<Exception>(() => testRun.Run()); |
| 123 | + var scenario = testRun.Story.Scenarios.First(); |
| 124 | + Assert.AreEqual(StepExecutionResult.Failed, scenario.Result); |
| 125 | + var steps = scenario.Steps; |
| 126 | + |
| 127 | + Assert.AreEqual(4, steps.Count); |
| 128 | + Assert.AreEqual(StepExecutionResult.Passed, steps[0].Result); |
| 129 | + Assert.AreEqual(ExecutionOrder.SetupState, steps[0].ExecutionOrder); |
| 130 | + Assert.AreEqual(StepExecutionResult.Passed, steps[1].Result); |
| 131 | + Assert.AreEqual(ExecutionOrder.Transition, steps[1].ExecutionOrder); |
| 132 | + Assert.AreEqual(StepExecutionResult.Failed, steps[2].Result); |
| 133 | + Assert.AreEqual(ExecutionOrder.Assertion, steps[2].ExecutionOrder); |
| 134 | + Assert.AreEqual(StepExecutionResult.Passed, steps[3].Result); |
| 135 | + Assert.AreEqual(ExecutionOrder.ConsecutiveAssertion, steps[3].ExecutionOrder); |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | +} |
0 commit comments