Skip to content

Commit d07d2bd

Browse files
author
Gurpreet Singh
committed
add step title factory tests
1 parent a026935 commit d07d2bd

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using Shouldly;
2+
using System.Linq;
3+
using System.Reflection;
4+
using TestStack.BDDfy.Abstractions;
5+
using TestStack.BDDfy.Configuration;
6+
using Xunit;
7+
8+
namespace TestStack.BDDfy.Tests.Scanner.FluentScanner
9+
{
10+
public class UsingCustomStepTitleFactory
11+
{
12+
private class CustomStepTitleFactory : IStepTitleFactory
13+
{
14+
public StepTitle Create(
15+
string stepTextTemplate,
16+
bool includeInputsInStepTitle,
17+
MethodInfo methodInfo,
18+
StepArgument[] inputArguments,
19+
ITestContext testContext,
20+
string stepPrefix) => new StepTitle("Custom Step Title");
21+
22+
public StepTitle Create(string title, string stepPrefix, ITestContext testContext) => new StepTitle(title);
23+
}
24+
25+
[Fact]
26+
public void ShouldUseCustomStepTitleFactoryWhenSet()
27+
{
28+
var scenario = new UsingCustomStepTitleFactory();
29+
var configurator = TestContext.GetContext(scenario).Configurator;
30+
configurator.StepTitleFactory = new CustomStepTitleFactory();
31+
32+
var story = scenario
33+
.Given(_ => SomeState())
34+
.When(_ => SomethingHappens())
35+
.Then(_ => SomeResult())
36+
.BDDfy();
37+
38+
story.Scenarios.Single().Steps.ElementAt(0).Title.ShouldBe("Custom Step Title");
39+
story.Scenarios.Single().Steps.ElementAt(1).Title.ShouldBe("Custom Step Title");
40+
story.Scenarios.Single().Steps.ElementAt(2).Title.ShouldBe("Custom Step Title");
41+
}
42+
43+
[Fact]
44+
public void ShouldUseCustomStepTitleFactoryWhenSetWithStepTitles()
45+
{
46+
var scenario = new UsingCustomStepTitleFactory();
47+
var configurator = TestContext.GetContext(scenario).Configurator;
48+
configurator.StepTitleFactory = new CustomStepTitleFactory();
49+
var story = scenario
50+
.Given(_ => SomeState(), "Not this")
51+
.When(_ => SomethingHappens(), "Or this")
52+
.Then(_ => SomeResult(), "should not appear")
53+
.BDDfy();
54+
55+
story.Scenarios.Single().Steps.ElementAt(0).Title.ShouldBe("Custom Step Title");
56+
story.Scenarios.Single().Steps.ElementAt(1).Title.ShouldBe("Custom Step Title");
57+
story.Scenarios.Single().Steps.ElementAt(2).Title.ShouldBe("Custom Step Title");
58+
}
59+
60+
[StepTitle("given from attribute")]
61+
private void SomeState()
62+
{
63+
}
64+
65+
[StepTitle("when from attribute")]
66+
private void SomethingHappens()
67+
{
68+
}
69+
70+
[StepTitle("then from attribute")]
71+
private void SomeResult()
72+
{
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)