Skip to content

Commit e9dbc63

Browse files
committed
Merge pull request #144 from JakeGinnivan/MovedArgumentsToStep
Moved the argument collection for local variable setting support to step...
2 parents cff0a51 + 6d248b5 commit e9dbc63

File tree

10 files changed

+50
-48
lines changed

10 files changed

+50
-48
lines changed

TestStack.BDDfy.Tests/Processors/TestRunnerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public void InitialisesScenarioWithExampleBeforeRunning()
2323

2424
var sut = new TestRunner();
2525
Action<object> action = o => actualValue = ExampleValue;
26-
var steps = new List<Step> { new Step(action, new StepTitle("A Step"), true, ExecutionOrder.Initialize, true) };
26+
var steps = new List<Step> { new Step(action, new StepTitle("A Step"), true, ExecutionOrder.Initialize, true, new List<StepArgument>()) };
2727

28-
var scenarioWithExample = new Scenario("id", this, steps, "Scenario Text", exampleTable, new List<StepArgument>(), new List<string>());
28+
var scenarioWithExample = new Scenario("id", this, steps, "Scenario Text", exampleTable, new List<string>());
2929
var story = new Story(new StoryMetadata(typeof(TestRunnerTests), new StoryNarrativeAttribute()),
3030
new[] { scenarioWithExample });
3131

TestStack.BDDfy.Tests/Reporters/ReportTestData.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ private Scenario[] GetScenarios(bool includeFailingScenario, bool includeExample
118118
}
119119
return new List<Scenario>
120120
{
121-
new Scenario(exampleId, typeof(ExampleScenario), GetExampleExecutionSteps(), "Example Scenario", exampleTable.ElementAt(0), new List<StepArgument>(), new List<string>()),
122-
new Scenario(exampleId, typeof(ExampleScenario), exampleExecutionSteps, "Example Scenario", exampleTable.ElementAt(1), new List<StepArgument>(), new List<string>())
121+
new Scenario(exampleId, typeof(ExampleScenario), GetExampleExecutionSteps(), "Example Scenario", exampleTable.ElementAt(0), new List<string>()),
122+
new Scenario(exampleId, typeof(ExampleScenario), exampleExecutionSteps, "Example Scenario", exampleTable.ElementAt(1), new List<string>())
123123
}.ToArray();
124124
}
125125

@@ -162,9 +162,9 @@ private List<Step> GetHappyExecutionSteps()
162162
{
163163
var steps = new List<Step>
164164
{
165-
new Step(null, new StepTitle("Given a positive account balance"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
166-
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
167-
new Step(null, new StepTitle("Then money is dispensed"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
165+
new Step(null, new StepTitle("Given a positive account balance"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
166+
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
167+
new Step(null, new StepTitle("Then money is dispensed"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
168168
};
169169
return steps;
170170
}
@@ -173,9 +173,9 @@ private List<Step> GetExampleExecutionSteps()
173173
{
174174
var steps = new List<Step>
175175
{
176-
new Step(null, new StepTitle("Given a <sign> account balance"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
177-
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
178-
new Step(null, new StepTitle("Then money <action> dispensed"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
176+
new Step(null, new StepTitle("Given a <sign> account balance"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
177+
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
178+
new Step(null, new StepTitle("Then money <action> dispensed"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
179179
};
180180
return steps;
181181
}
@@ -184,9 +184,9 @@ private List<Step> GetSadExecutionSteps()
184184
{
185185
var steps = new List<Step>
186186
{
187-
new Step(null, new StepTitle("Given a negative account balance"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
188-
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
189-
new Step(null, new StepTitle("Then no money is dispensed"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
187+
new Step(null, new StepTitle("Given a negative account balance"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
188+
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
189+
new Step(null, new StepTitle("Then no money is dispensed"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5), Result = Result.Passed},
190190
};
191191
return steps;
192192
}
@@ -195,9 +195,9 @@ private List<Step> GetFailingExecutionSteps()
195195
{
196196
var steps = new List<Step>
197197
{
198-
new Step(null, new StepTitle("Given a negative account balance"), true, ExecutionOrder.Assertion, true),
199-
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true),
200-
new Step(null, new StepTitle("Then no money is dispensed"), true, ExecutionOrder.Assertion, true),
198+
new Step(null, new StepTitle("Given a negative account balance"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()),
199+
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()),
200+
new Step(null, new StepTitle("Then no money is dispensed"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()),
201201
};
202202

203203
SetAllStepResults(steps, Result.Passed);
@@ -220,9 +220,9 @@ private List<Step> GetInconclusiveExecutionSteps()
220220
{
221221
var steps = new List<Step>
222222
{
223-
new Step(null, new StepTitle("Given a negative account balance"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
224-
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
225-
new Step(null, new StepTitle("Then no money is dispensed"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
223+
new Step(null, new StepTitle("Given a negative account balance"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
224+
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
225+
new Step(null, new StepTitle("Then no money is dispensed"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
226226
};
227227

228228
SetAllStepResults(steps, Result.Passed);
@@ -237,9 +237,9 @@ private List<Step> GetNotImplementedExecutionSteps()
237237
{
238238
var steps = new List<Step>
239239
{
240-
new Step(null, new StepTitle("Given a negative account balance"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
241-
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
242-
new Step(null, new StepTitle("Then no money is dispensed"), true, ExecutionOrder.Assertion, true) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
240+
new Step(null, new StepTitle("Given a negative account balance"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
241+
new Step(null, new StepTitle("When the account holder requests money"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
242+
new Step(null, new StepTitle("Then no money is dispensed"), true, ExecutionOrder.Assertion, true, new List<StepArgument>()) {Duration = new TimeSpan(0, 0, 0, 0, 5)},
243243
};
244244

245245
SetAllStepResults(steps, Result.Passed);

TestStack.BDDfy/Processors/ScenarioExecutor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void InitializeScenario()
2929
.OfType<FieldInfo>()
3030
.Select(f => new StepArgument(f, _scenario.TestObject))
3131
.Union(memberInfos.OfType<PropertyInfo>().Select(m => new StepArgument(m, _scenario.TestObject)))
32-
.Union(_scenario.Arguments)
32+
.Union(_scenario.Steps.SelectMany(s=>s.Arguments))
3333
.ToArray();
3434

3535
foreach (var cell in _scenario.Example.Values)

TestStack.BDDfy/Scanners/ScenarioScanners/FluentScenarioScanner.cs

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

14-
public FluentScenarioScanner(List<Step> steps, string title, List<StepArgument> arguments)
13+
public FluentScenarioScanner(List<Step> steps, string title)
1514
{
1615
_title = title;
17-
_arguments = arguments;
1816
_steps = steps;
1917
}
2018

@@ -25,7 +23,7 @@ public IEnumerable<Scenario> Scan(ITestContext testContext)
2523
{
2624
var scenarioId = Configurator.IdGenerator.GetScenarioId();
2725
return testContext.Examples.Select(example =>
28-
new Scenario(scenarioId, testContext.TestObject, CloneSteps(_steps), scenarioText, example, _arguments, testContext.Tags));
26+
new Scenario(scenarioId, testContext.TestObject, CloneSteps(_steps), scenarioText, example, testContext.Tags));
2927
}
3028

3129
return new[] { new Scenario(testContext.TestObject, _steps, scenarioText, testContext.Tags) };

TestStack.BDDfy/Scanners/ScenarioScanners/ReflectiveScenarioScanner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public virtual IEnumerable<Scenario> Scan(ITestContext testContext)
4747
{
4848
var steps = ScanScenarioForSteps(testContext, example);
4949
var orderedSteps = steps.OrderBy(o => o.ExecutionOrder).ThenBy(o => o.ExecutionSubOrder).ToList();
50-
yield return new Scenario(scenarioId, testContext.TestObject, orderedSteps, scenarioTitle, example, new List<StepArgument>(), testContext.Tags);
50+
yield return new Scenario(scenarioId, testContext.TestObject, orderedSteps, scenarioTitle, example, testContext.Tags);
5151
}
5252
}
5353

TestStack.BDDfy/Scanners/StepScanners/ExecutableAttribute/ExecutableAttributeStepScanner.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public IEnumerable<Step> Scan(ITestContext testContext, MethodInfo candidateMeth
4141
var runStepWithArgsAttributes = (RunStepWithArgsAttribute[])candidateMethod.GetCustomAttributes(typeof(RunStepWithArgsAttribute), false);
4242
if (runStepWithArgsAttributes.Length == 0)
4343
{
44-
yield return
45-
new Step(StepActionFactory.GetStepAction(candidateMethod, new object[0]), stepTitle, stepAsserts, executableAttribute.ExecutionOrder, true)
44+
var stepAction = StepActionFactory.GetStepAction(candidateMethod, new object[0]);
45+
yield return new Step(stepAction, stepTitle, stepAsserts, executableAttribute.ExecutionOrder, true, new List<StepArgument>())
4646
{
4747
ExecutionSubOrder = executableAttribute.Order
4848
};
@@ -60,9 +60,9 @@ public IEnumerable<Step> Scan(ITestContext testContext, MethodInfo candidateMeth
6060
else if (!string.IsNullOrEmpty(executableAttribute.StepTitle))
6161
methodName = string.Format(executableAttribute.StepTitle, flatInput);
6262

63-
yield return
64-
new Step(StepActionFactory.GetStepAction(candidateMethod, inputArguments), new StepTitle(methodName), stepAsserts,
65-
executableAttribute.ExecutionOrder, true)
63+
var stepAction = StepActionFactory.GetStepAction(candidateMethod, inputArguments);
64+
yield return new Step(stepAction, new StepTitle(methodName), stepAsserts,
65+
executableAttribute.ExecutionOrder, true, new List<StepArgument>())
6666
{
6767
ExecutionSubOrder = executableAttribute.Order
6868
};
@@ -100,7 +100,7 @@ public IEnumerable<Step> Scan(ITestContext testContext, MethodInfo method, Examp
100100
}
101101

102102
var stepAction = StepActionFactory.GetStepAction(method, inputs.ToArray());
103-
yield return new Step(stepAction, new StepTitle(stepTitle), stepAsserts, executableAttribute.ExecutionOrder, true);
103+
yield return new Step(stepAction, new StepTitle(stepTitle), stepAsserts, executableAttribute.ExecutionOrder, true, new List<StepArgument>());
104104
}
105105

106106

TestStack.BDDfy/Scanners/StepScanners/Fluent/FluentScanner.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ internal class FluentScanner<TScenario> : IFluentScanner
4141
private readonly List<Step> _steps = new List<Step>();
4242
private readonly TScenario _testObject;
4343
private readonly ITestContext _testContext;
44-
private readonly List<StepArgument> _arguments = new List<StepArgument>();
4544

4645
internal FluentScanner(TScenario testObject)
4746
{
@@ -51,17 +50,19 @@ internal FluentScanner(TScenario testObject)
5150

5251
IScanner IFluentScanner.GetScanner(string scenarioTitle, Type explicitStoryType)
5352
{
54-
return new DefaultScanner(_testContext, new FluentScenarioScanner(_steps, scenarioTitle, _arguments), explicitStoryType);
53+
return new DefaultScanner(_testContext, new FluentScenarioScanner(_steps, scenarioTitle), explicitStoryType);
5554
}
5655

5756
public void AddStep(Action stepAction, string title, bool reports, ExecutionOrder executionOrder, bool asserts)
5857
{
59-
_steps.Add(new Step(StepActionFactory.GetStepAction<object>(o => stepAction()), new StepTitle(title), FixAsserts(asserts, executionOrder), FixConsecutiveStep(executionOrder), reports));
58+
var action = StepActionFactory.GetStepAction<object>(o => stepAction());
59+
_steps.Add(new Step(action, new StepTitle(title), FixAsserts(asserts, executionOrder), FixConsecutiveStep(executionOrder), reports, new List<StepArgument>()));
6060
}
6161

6262
public void AddStep(Func<Task> stepAction, string title, bool reports, ExecutionOrder executionOrder, bool asserts)
6363
{
64-
_steps.Add(new Step(StepActionFactory.GetStepAction<object>(o => stepAction()), new StepTitle(title), FixAsserts(asserts, executionOrder), FixConsecutiveStep(executionOrder), reports));
64+
var action = StepActionFactory.GetStepAction<object>(o => stepAction());
65+
_steps.Add(new Step(action, new StepTitle(title), FixAsserts(asserts, executionOrder), FixConsecutiveStep(executionOrder), reports, new List<StepArgument>()));
6566
}
6667

6768
public void AddStep(Expression<Func<TScenario, Task>> stepAction, string stepTextTemplate, bool includeInputsInStepTitle, bool reports, ExecutionOrder executionOrder, bool asserts)
@@ -74,8 +75,8 @@ public void AddStep(Expression<Func<TScenario, Task>> stepAction, string stepTex
7475
}
7576

7677
var title = CreateTitle(stepTextTemplate, includeInputsInStepTitle, GetMethodInfo(stepAction), inputArguments);
77-
_arguments.AddRange(inputArguments.Where(s => !string.IsNullOrEmpty(s.Name)));
78-
_steps.Add(new Step(StepActionFactory.GetStepAction(action), title, FixAsserts(asserts, executionOrder), FixConsecutiveStep(executionOrder), reports));
78+
var args = inputArguments.Where(s => !string.IsNullOrEmpty(s.Name)).ToList();
79+
_steps.Add(new Step(StepActionFactory.GetStepAction(action), title, FixAsserts(asserts, executionOrder), FixConsecutiveStep(executionOrder), reports, args));
7980
}
8081

8182
public void AddStep(Expression<Action<TScenario>> stepAction, string stepTextTemplate, bool includeInputsInStepTitle, bool reports, ExecutionOrder executionOrder, bool asserts)
@@ -89,8 +90,8 @@ public void AddStep(Expression<Action<TScenario>> stepAction, string stepTextTem
8990
}
9091

9192
var title = CreateTitle(stepTextTemplate, includeInputsInStepTitle, GetMethodInfo(stepAction), inputArguments);
92-
_arguments.AddRange(inputArguments.Where(s => !string.IsNullOrEmpty(s.Name)));
93-
_steps.Add(new Step(StepActionFactory.GetStepAction(action), title, FixAsserts(asserts, executionOrder), FixConsecutiveStep(executionOrder), reports));
93+
var args = inputArguments.Where(s => !string.IsNullOrEmpty(s.Name)).ToList();
94+
_steps.Add(new Step(StepActionFactory.GetStepAction(action), title, FixAsserts(asserts, executionOrder), FixConsecutiveStep(executionOrder), reports, args));
9495
}
9596

9697
private bool FixAsserts(bool asserts, ExecutionOrder executionOrder)

TestStack.BDDfy/Scanners/StepScanners/MethodName/MethodNameStepScanner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ private Step GetStep(object testObject, MethodNameMatcher matcher, MethodInfo me
101101
}
102102

103103
var stepAction = GetStepAction(method, inputs.ToArray(), returnsItsText);
104-
return new Step(stepAction, new StepTitle(stepMethodName), matcher.Asserts, matcher.ExecutionOrder, matcher.ShouldReport);
104+
return new Step(stepAction, new StepTitle(stepMethodName), matcher.Asserts, matcher.ExecutionOrder, matcher.ShouldReport, new List<StepArgument>());
105105
}
106106

107107
private Step GetStep(object testObject, MethodNameMatcher matcher, MethodInfo method, bool returnsItsText, object[] inputs = null, RunStepWithArgsAttribute argAttribute = null)
108108
{
109109
var stepMethodName = GetStepTitle(method, testObject, argAttribute, returnsItsText);
110110
var stepAction = GetStepAction(method, inputs, returnsItsText);
111-
return new Step(stepAction, new StepTitle(stepMethodName), matcher.Asserts, matcher.ExecutionOrder, matcher.ShouldReport);
111+
return new Step(stepAction, new StepTitle(stepMethodName), matcher.Asserts, matcher.ExecutionOrder, matcher.ShouldReport, new List<StepArgument>());
112112
}
113113

114114
private string GetStepTitle(MethodInfo method, object testObject, RunStepWithArgsAttribute argAttribute, bool returnsItsText)

0 commit comments

Comments
 (0)