Skip to content

Commit fb70611

Browse files
committed
Made the IKeyGenerator api a bit more future proof
1 parent 7e8364c commit fb70611

5 files changed

Lines changed: 13 additions & 26 deletions

File tree

TestStack.BDDfy.Tests/Configuration/SequentialKeyGeneratorTests.cs

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ public class SequentialKeyGeneratorTests
99
[Test]
1010
public void ShouldReturnOneForFirstScenario()
1111
{
12-
var sut = new SequentialKeyGenerator();
13-
14-
var result = sut.GetScenarioId();
15-
16-
Assert.That(result, Is.EqualTo("scenario-1"));
12+
Assert.That(new SequentialKeyGenerator().GetScenarioId(null), Is.EqualTo("scenario-1"));
1713
}
1814

1915
[Test]
@@ -23,18 +19,14 @@ public void ShouldIncrementScenarioIdForEachRequestForScenariId()
2319

2420
for (int i = 1; i <= 12; i++)
2521
{
26-
Assert.That(sut.GetScenarioId(), Is.EqualTo("scenario-" + i));
22+
Assert.That(sut.GetScenarioId(null), Is.EqualTo("scenario-" + i));
2723
}
2824
}
2925

3026
[Test]
3127
public void ShouldReturnOneOneForFirstStepOfFirstScenario()
3228
{
33-
var sut = new SequentialKeyGenerator();
34-
35-
var result = sut.GetStepId();
36-
37-
Assert.That(result, Is.EqualTo("step-1-1"));
29+
Assert.That(new SequentialKeyGenerator().GetStepId(null), Is.EqualTo("step-1-1"));
3830
}
3931

4032
[Test]
@@ -44,22 +36,18 @@ public void ShouldIncrementStepIdForEachRequestForStepId()
4436

4537
for (int i = 1; i <= 12; i++)
4638
{
47-
Assert.That(sut.GetStepId(), Is.EqualTo("step-1-" + i));
39+
Assert.That(sut.GetStepId(null), Is.EqualTo("step-1-" + i));
4840
}
4941
}
5042

5143
[Test]
5244
public void ShouldResetStepCountForNewScenario()
5345
{
5446
var sut = new SequentialKeyGenerator();
55-
sut.GetStepId();
56-
sut.GetScenarioId();
57-
58-
var result = sut.GetStepId();
47+
sut.GetStepId(null);
48+
sut.GetScenarioId(null);
5949

60-
Assert.That(result, Is.EqualTo("step-2-1"));
50+
Assert.That(sut.GetStepId(null), Is.EqualTo("step-2-1"));
6151
}
62-
6352
}
64-
6553
}

TestStack.BDDfy/Configuration/IKeyGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ namespace TestStack.BDDfy.Configuration
22
{
33
public interface IKeyGenerator
44
{
5-
string GetScenarioId();
6-
string GetStepId();
5+
string GetScenarioId(Scenario scenario);
6+
string GetStepId(Step step);
77
void Reset();
88
}
99
}

TestStack.BDDfy/Configuration/SequentialKeyGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ public class SequentialKeyGenerator : IKeyGenerator
55
private int _currentScenarioNumber = 1;
66
private int _currentStepNumber = 1;
77

8-
public string GetScenarioId()
8+
public string GetScenarioId(Scenario scenario)
99
{
1010
var id = string.Format("scenario-{0}", _currentScenarioNumber);
1111
_currentScenarioNumber++;
1212
_currentStepNumber = 1;
1313
return id;
1414
}
1515

16-
public string GetStepId()
16+
public string GetStepId(Step step)
1717
{
1818
var id = string.Format("step-{0}-{1}", _currentScenarioNumber, _currentStepNumber);
1919
_currentStepNumber++;

TestStack.BDDfy/Scenario.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ public Scenario(object testObject, IEnumerable<Step> steps, string scenarioText)
1212
{
1313
TestObject = testObject;
1414
_steps = steps.OrderBy(o => o.ExecutionOrder).ThenBy(o => o.ExecutionSubOrder).ToList();
15-
Id = Configurator.IdGenerator.GetScenarioId();
16-
1715
Title = scenarioText;
16+
Id = Configurator.IdGenerator.GetScenarioId(this);
1817
}
1918

2019
public string Title { get; private set; }

TestStack.BDDfy/Step.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public Step(
1717
ExecutionOrder = executionOrder;
1818
ShouldReport = shouldReport;
1919
Result = Result.NotExecuted;
20-
Id = Configurator.IdGenerator.GetStepId();
2120
Title = title;
2221
Action = action;
22+
Id = Configurator.IdGenerator.GetStepId(this);
2323
}
2424

2525
public string Id { get; private set; }

0 commit comments

Comments
 (0)