Skip to content

Commit 452ec82

Browse files
committed
Merge branch 'ComplexFluent' into examples
2 parents 9107453 + 4101627 commit 452ec82

16 files changed

Lines changed: 706 additions & 298 deletions

TestStack.BDDfy.Tests/Processors/TestRunnerTests.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Linq;
34
using NUnit.Framework;
45
using TestStack.BDDfy.Processors;
@@ -22,11 +23,11 @@ public void InitialisesScenarioWithExampleBeforeRunning()
2223

2324
var sut = new TestRunner();
2425
Action<object> action = o => actualValue = ExampleValue;
25-
var steps = new[]{new Step(action, new StepTitle("A Step"), true, ExecutionOrder.Initialize, true) };
26-
26+
var steps = new List<Step> { new Step(action, new StepTitle("A Step"), true, ExecutionOrder.Initialize, true) };
27+
2728
var scenarioWithExample = new Scenario("id", this, steps, "Scenario Text", exampleTable);
2829
var story = new Story(new StoryMetadata(typeof(TestRunnerTests), new StoryNarrativeAttribute()),
29-
new[]{ scenarioWithExample});
30+
new[] { scenarioWithExample });
3031

3132
sut.Process(story);
3233

TestStack.BDDfy.Tests/Reporters/ReportTestData.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public IEnumerable<Story> CreateTwoStoriesEachWithOneFailingScenarioAndOnePassin
5555

5656
private Scenario[] GetScenarios(bool includeFailingScenario, bool includeExamples)
5757
{
58-
var sadExecutionSteps = GetSadExecutionSteps().ToArray();
58+
var sadExecutionSteps = GetSadExecutionSteps().ToList();
5959
if (includeFailingScenario)
6060
{
6161
var last = sadExecutionSteps.Last();
@@ -78,7 +78,7 @@ private Scenario[] GetScenarios(bool includeFailingScenario, bool includeExample
7878
{"positive", "is"},
7979
{"negative", "is not"}
8080
};
81-
var exampleExecutionSteps = GetExampleExecutionSteps().ToArray();
81+
var exampleExecutionSteps = GetExampleExecutionSteps().ToList();
8282
if (includeFailingScenario)
8383
{
8484
var last = exampleExecutionSteps.Last();
@@ -126,7 +126,7 @@ private Scenario[] GetOneOfEachScenarioResult()
126126
return scenarios.ToArray();
127127
}
128128

129-
private IEnumerable<Step> GetHappyExecutionSteps()
129+
private List<Step> GetHappyExecutionSteps()
130130
{
131131
var steps = new List<Step>
132132
{
@@ -137,7 +137,7 @@ private IEnumerable<Step> GetHappyExecutionSteps()
137137
return steps;
138138
}
139139

140-
private IEnumerable<Step> GetExampleExecutionSteps()
140+
private List<Step> GetExampleExecutionSteps()
141141
{
142142
var steps = new List<Step>
143143
{
@@ -148,7 +148,7 @@ private IEnumerable<Step> GetExampleExecutionSteps()
148148
return steps;
149149
}
150150

151-
private IEnumerable<Step> GetSadExecutionSteps()
151+
private List<Step> GetSadExecutionSteps()
152152
{
153153
var steps = new List<Step>
154154
{
@@ -159,7 +159,7 @@ private IEnumerable<Step> GetSadExecutionSteps()
159159
return steps;
160160
}
161161

162-
private IEnumerable<Step> GetInconclusiveExecutionSteps()
162+
private List<Step> GetInconclusiveExecutionSteps()
163163
{
164164
var steps = new List<Step>
165165
{
@@ -176,7 +176,7 @@ private IEnumerable<Step> GetInconclusiveExecutionSteps()
176176
}
177177

178178

179-
private IEnumerable<Step> GetNotImplementedExecutionSteps()
179+
private List<Step> GetNotImplementedExecutionSteps()
180180
{
181181
var steps = new List<Step>
182182
{
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NUnit.Framework;
2+
using Shouldly;
3+
4+
namespace TestStack.BDDfy.Tests.Scanner.FluentScanner
5+
{
6+
[TestFixture]
7+
public class ComplexStepsTests
8+
{
9+
private int count;
10+
11+
[Test]
12+
public void ShouldBeAbleToChainComplexTestWithFluentApi()
13+
{
14+
this.Given(_ => count.ShouldBe(0))
15+
.When(() => count++.ShouldBe(0), "When I do something")
16+
.Given(() => count++.ShouldBe(1), "Given I am doing things in different order")
17+
.Then(() => count++.ShouldBe(2), "Then they should run in defined order")
18+
.When(() => count++.ShouldBe(3), "When I have whens after thens things still work")
19+
.And(() => count++.ShouldBe(4), "And we should still be able to use ands")
20+
.BDDfy();
21+
}
22+
}
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using NSubstitute;
2+
using NUnit.Framework;
3+
4+
namespace TestStack.BDDfy.Tests.Scanner.FluentScanner
5+
{
6+
public class DoesNotConflictWithnSubstitute
7+
{
8+
private ITestContext _subsitute;
9+
private ExampleTable _exampleTable;
10+
11+
[Test]
12+
public void CanUseFluentApiWithNSubstitute()
13+
{
14+
this.Given(_ => GivenSomeStuff())
15+
.When(_ => WhenSomethingHappens())
16+
.Then(_ => ThenICanStillUseNSubsitute())
17+
.BDDfy();
18+
}
19+
20+
private void ThenICanStillUseNSubsitute()
21+
{
22+
_subsitute.Received().Examples = _exampleTable;
23+
}
24+
25+
private void WhenSomethingHappens()
26+
{
27+
_exampleTable = new ExampleTable();
28+
_subsitute.Examples = _exampleTable;
29+
}
30+
31+
private void GivenSomeStuff()
32+
{
33+
_subsitute = Substitute.For<ITestContext>();
34+
}
35+
}
36+
}

TestStack.BDDfy.Tests/Scanner/FluentScanner/FluentWithExamples.FluentCanBeUsedWithExamples.approved.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ Scenario: Fluent can be used with examples
55
Given a different method with random arg 2
66
Given a different method with <Prop2>
77
When method using <example string>
8+
And I use a <Multi word heading>
89
Then all is good
910

1011
Examples:
11-
| Prop 1 | Prop2 | Prop 3 |
12-
| 1 | foo | ConsecutiveAssertion |
13-
| 2 | bar | Initialize |
12+
| Prop 1 | Prop2 | Prop 3 | Multi word heading |
13+
| 1 | foo | ConsecutiveAssertion | |
14+
| 2 | bar | Initialize | val2 |
1415

TestStack.BDDfy.Tests/Scanner/FluentScanner/FluentWithExamples.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ public void FluentCanBeUsedWithExamples()
1717
.And(_ => GivenADifferentMethodWithRandomArg(2))
1818
.And(_ => GivenADifferentMethodWith(_prop2))
1919
.When(_ => WhenMethodUsing__ExampleString__())
20+
.When(_ => AndIUseA(multiWordHeading))
2021
.Then(_ => ThenAllIsGood())
21-
.WithExamples(new ExampleTable("Prop 1", "Prop2", "Prop 3")
22+
.WithExamples(new ExampleTable("Prop 1", "Prop2", "Prop 3", "Multi word heading")
2223
{
23-
{1, "foo", ExecutionOrder.ConsecutiveAssertion },
24-
{2, "bar", ExecutionOrder.Initialize }
24+
{1, "foo", ExecutionOrder.ConsecutiveAssertion, "" },
25+
{2, "bar", ExecutionOrder.Initialize, "val2" }
2526
})
2627
.BDDfy();
2728

@@ -30,6 +31,12 @@ public void FluentCanBeUsedWithExamples()
3031
Approvals.Verify(textReporter.ToString());
3132
}
3233

34+
private void AndIUseA(string multiWordHeading)
35+
{
36+
multiWordHeading.ShouldBeOneOf("", "val2");
37+
this.multiWordHeading.ShouldBeOneOf("", "val2");
38+
}
39+
3340
private void GivenADifferentMethodWith(string prop2)
3441
{
3542
_prop2.ShouldBeOneOf("foo", "bar");
@@ -58,6 +65,7 @@ private void GivenMethodTaking__ExampleInt__(int exampleInt)
5865

5966
public int Prop1 { get; set; }
6067
private string _prop2 = null;
68+
private string multiWordHeading = null;
6169
public ExecutionOrder Prop_3 { get; set; }
6270
}
6371
}

TestStack.BDDfy.Tests/TestStack.BDDfy.Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
<Compile Include="Reporters\Html\TemporaryCulture.cs" />
8585
<Compile Include="Reporters\Html\TestableHtmlReporter.cs" />
8686
<Compile Include="Reporters\ReportApprover.cs" />
87+
<Compile Include="Scanner\FluentScanner\ComplexStepsTests.cs" />
88+
<Compile Include="Scanner\FluentScanner\DoesNotConflictWithnSubstitute.cs" />
8789
<Compile Include="Scanner\FluentScanner\FluentWithExamples.cs" />
8890
<Compile Include="Scanner\FluentScanner\InlineAssertions.cs" />
8991
<Compile Include="Scanner\ReflectiveScanner\ReflectiveWithExamples.cs" />

TestStack.BDDfy.sln.DotSettings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=CheckNamespace/@EntryIndexedValue">DO_NOT_SHOW</s:String></wpf:ResourceDictionary>

TestStack.BDDfy/Scanners/ScenarioScanners/FluentScenarioScanner.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace TestStack.BDDfy
88
public class FluentScenarioScanner : IScenarioScanner
99
{
1010
private readonly string _title;
11-
private readonly IEnumerable<Step> _steps;
11+
private readonly List<Step> _steps;
1212

13-
public FluentScenarioScanner(IEnumerable<Step> steps, string title)
13+
public FluentScenarioScanner(List<Step> steps, string title)
1414
{
1515
_title = title;
1616
_steps = steps;
@@ -29,9 +29,9 @@ public IEnumerable<Scenario> Scan(ITestContext testContext)
2929
return new[] { new Scenario(testContext.TestObject, _steps, scenarioText) };
3030
}
3131

32-
private IEnumerable<Step> CloneSteps(IEnumerable<Step> steps)
32+
private List<Step> CloneSteps(IEnumerable<Step> steps)
3333
{
34-
return steps.Select(step => new Step(step));
34+
return steps.Select(step => new Step(step)).ToList();
3535
}
3636

3737
private static string GetTitleFromMethodNameInStackTrace(object testObject)

TestStack.BDDfy/Scanners/ScenarioScanners/ReflectiveScenarioScanner.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ public virtual IEnumerable<Scenario> Scan(ITestContext testContext)
3333
scenarioType = testContext.TestObject.GetType();
3434
scenarioTitle = _scenarioTitle ?? GetScenarioText(scenarioType);
3535

36-
yield return new Scenario(testContext.TestObject, steps, scenarioTitle);
36+
var orderedSteps = steps.OrderBy(o => o.ExecutionOrder).ThenBy(o => o.ExecutionSubOrder).ToList();
37+
yield return new Scenario(testContext.TestObject, orderedSteps, scenarioTitle);
3738
yield break;
3839
}
3940

@@ -45,7 +46,8 @@ public virtual IEnumerable<Scenario> Scan(ITestContext testContext)
4546
foreach (var example in testContext.Examples)
4647
{
4748
var steps = ScanScenarioForSteps(testContext, example);
48-
yield return new Scenario(scenarioId, testContext.TestObject, steps, scenarioTitle, example);
49+
var orderedSteps = steps.OrderBy(o => o.ExecutionOrder).ThenBy(o => o.ExecutionSubOrder).ToList();
50+
yield return new Scenario(scenarioId, testContext.TestObject, orderedSteps, scenarioTitle, example);
4951
}
5052
}
5153

0 commit comments

Comments
 (0)