Skip to content

Commit 9319ba9

Browse files
committed
Merge pull request #117 from JakeGinnivan/GenerateFluentApi
Generate fluent api
2 parents 2f4f094 + 7cd1216 commit 9319ba9

19 files changed

Lines changed: 586 additions & 468 deletions

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public void Dispose()
7373

7474
public static IEnumerable<Step> GetSteps(ScenarioToBeScannedUsingFluentScanner testObject)
7575
{
76-
var fluentScanner = testObject
76+
var fluentScanner = TestContext.GetContext(testObject
7777
.Given(s => s.GivenSomeState(1, 2))
7878
.And(s => s.WhenSomeStepUsesIncompatibleNamingConvention())
7979
.And(s => s.AndAMethodTakesArrayInputs(new[] {"1", "2"}, new[] {3, 4}, 5))
@@ -85,9 +85,9 @@ public static IEnumerable<Step> GetSteps(ScenarioToBeScannedUsingFluentScanner t
8585
.Then(s => s.ThenTheFollowingAssertionsShouldBeCorrect())
8686
.And(s => s.AndIncorrectAttributeWouldNotMatter())
8787
.And(s => s.ThenTitleFormatingWorksToo(InputDate), InputDateStepTitleTemplate)
88-
.TearDownWith(s => s.Dispose());
88+
.TearDownWith(s => s.Dispose())).FluentScanner;
8989

90-
return ((IFluentScanner)fluentScanner).GetScanner(null, null).Scan().Scenarios.SelectMany(s => s.Steps).ToList();
90+
return fluentScanner.GetScanner(null, null).Scan().Scenarios.SelectMany(s => s.Steps).ToList();
9191
}
9292
}
9393
}

TestStack.BDDfy/BDDfyExtensions.cs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,21 @@ static Engine InternalLazyBDDfy(
4949
string storyCategory,
5050
Type explicitStoryType = null)
5151
{
52-
var storyScanner = GetFluentScanner(testObject, scenarioTitle, explicitStoryType) ?? GetReflectiveScanner(testObject, scenarioTitle, explicitStoryType);
52+
var testContext = TestContext.GetContext(testObject);
53+
54+
var storyScanner = testContext.FluentScanner != null ?
55+
testContext.FluentScanner.GetScanner(scenarioTitle, explicitStoryType) :
56+
GetReflectiveScanner(testContext, scenarioTitle, explicitStoryType);
5357

5458
return new Engine(storyCategory, storyScanner);
5559
}
5660

57-
static IScanner GetReflectiveScanner(object testObject, string scenarioTitle = null, Type explicitStoryType = null)
61+
static IScanner GetReflectiveScanner(ITestContext testContext, string scenarioTitle = null, Type explicitStoryType = null)
5862
{
59-
var testContext = TestContext.GetContext(testObject);
6063
var stepScanners = Configurator.Scanners.GetStepScanners(testContext).ToArray();
6164
var reflectiveScenarioScanner = new ReflectiveScenarioScanner(scenarioTitle, stepScanners);
6265

6366
return new DefaultScanner(testContext, reflectiveScenarioScanner, explicitStoryType);
6467
}
65-
66-
static IScanner GetFluentScanner(object testObject, string scenarioTitle, Type explicitStoryType)
67-
{
68-
IScanner scanner = null;
69-
70-
var fluentScanner = testObject as IFluentScanner;
71-
72-
if (fluentScanner != null)
73-
scanner = fluentScanner.GetScanner(scenarioTitle, explicitStoryType);
74-
75-
return scanner;
76-
}
7768
}
7869
}

TestStack.BDDfy/ExecutionOrder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public enum ExecutionOrder
99
ConsecutiveTransition = 5,
1010
Assertion = 6,
1111
ConsecutiveAssertion = 7,
12-
TearDown = 8
12+
TearDown = 8,
13+
ConsecutiveStep
1314
}
1415
}

TestStack.BDDfy/ITestContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ public interface ITestContext
44
{
55
object TestObject { get; }
66
ExampleTable Examples { get; set; }
7+
IFluentScanner FluentScanner { get; set; }
78
}
89
}

TestStack.BDDfy/Processors/StoryCache.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public void Process(Story story)
1515
{
1616
foreach (var scenario in story.Scenarios)
1717
{
18+
TestContext.ClearContextFor(scenario.TestObject);
1819
scenario.TestObject = null;
1920
foreach (var step in scenario.Steps)
2021
step.Action = null;

0 commit comments

Comments
 (0)