forked from TestStack/TestStack.BDDfy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStepTitleTests.cs
More file actions
204 lines (172 loc) · 8.22 KB
/
StepTitleTests.cs
File metadata and controls
204 lines (172 loc) · 8.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System;
using System.Linq;
using Shouldly;
using TestStack.BDDfy.Configuration;
using Xunit;
namespace TestStack.BDDfy.Tests.Scanner.FluentScanner
{
public class StepTitleTests:IDisposable
{
public StepTitleTests()
{
Configurator.Scanners.SetDefaultStepTitleCreatorFunction(null);
}
private string _mutatedState;
[Fact]
public void MethodCallInStepTitle()
{
FooClass something = new FooClass();
var story = this
.Given(_ => GivenWeMutateSomeState())
.When(_ => something.Sub.SomethingHappens())
.And(_ => something.Sub.SomethingWithDifferentTitle())
.Then(_ => ThenTitleHas(AMethodCall()))
.And(_ => something.Sub.SomethingWithArg("foo"))
.And(_ => something.Sub.SomethingWithArg2("foo"))
.And(_ => something.Sub.SomethingWithArg3("foo"))
.BDDfy();
story.Scenarios.Single().Steps.ElementAt(2).Title.ShouldBe("And different title");
story.Scenarios.Single().Steps.ElementAt(3).Title.ShouldBe("Then title has Mutated state");
story.Scenarios.Single().Steps.ElementAt(4).Title.ShouldBe("And with arg foo");
story.Scenarios.Single().Steps.ElementAt(5).Title.ShouldBe("And with arg");
story.Scenarios.Single().Steps.ElementAt(6).Title.ShouldBe("And with foo arg");
}
[Fact]
public void TitleFunctionCanBeOverriden()
{
FooClass something = new FooClass();
var context = TestContext.GetContext(something);
Configurator.Scanners.SetDefaultStepTitleCreatorFunction((a, b, c, d, e) => new StepTitle("hello"));
new FluentStepBuilder<FooClass>(something);
var story = something
.Given(_ => GivenWeMutateSomeState())
.When(_ => something.Sub.SomethingHappens())
.And(_ => something.Sub.SomethingWithDifferentTitle())
.Then(_ => ThenTitleHas(AMethodCall()))
.And(_ => something.Sub.SomethingWithArg("foo"))
.And(_ => something.Sub.SomethingWithArg2("foo"))
.And(_ => something.Sub.SomethingWithArg3("foo"))
.BDDfy();
story.Scenarios.Single().Steps.ElementAt(2).Title.ShouldBe("hello");
story.Scenarios.Single().Steps.ElementAt(3).Title.ShouldBe("hello");
story.Scenarios.Single().Steps.ElementAt(4).Title.ShouldBe("hello");
story.Scenarios.Single().Steps.ElementAt(5).Title.ShouldBe("hello");
story.Scenarios.Single().Steps.ElementAt(6).Title.ShouldBe("hello");
}
[Fact]
public void TitleFunctionCanBeOverridenAndUseParameters()
{
GivenWeMutateSomeState();
FooClass something = new FooClass();
var context = TestContext.GetContext(something);
Configurator.Scanners.SetDefaultStepTitleCreatorFunction((a, b, c, d, e) => new StepTitle(e + " " + c.Name + " " + string.Join(",", d.Select(arg => arg.Value).ToArray())));
new FluentStepBuilder<FooClass>(something);
var story = something
.Given(_ => GivenWeMutateSomeState())
.When(_ => something.Sub.SomethingHappens())
.And(_ => something.Sub.SomethingWithDifferentTitle())
.Then(_ => ThenTitleHas(AMethodCall()))
.And(_ => something.Sub.SomethingWithArg("foo"))
.And(_ => something.Sub.SomethingWithArg2("foo2"))
.And(_ => something.Sub.SomethingWithArg3("foo3"))
.BDDfy();
story.Scenarios.Single().Steps.ElementAt(0).Title.ShouldBe("Given GivenWeMutateSomeState ");
story.Scenarios.Single().Steps.ElementAt(1).Title.ShouldBe("When SomethingHappens ");
story.Scenarios.Single().Steps.ElementAt(2).Title.ShouldBe("And SomethingWithDifferentTitle ");
story.Scenarios.Single().Steps.ElementAt(3).Title.ShouldBe("Then ThenTitleHas Mutated state");
story.Scenarios.Single().Steps.ElementAt(4).Title.ShouldBe("And SomethingWithArg foo");
story.Scenarios.Single().Steps.ElementAt(5).Title.ShouldBe("And SomethingWithArg2 foo2");
story.Scenarios.Single().Steps.ElementAt(6).Title.ShouldBe("And SomethingWithArg3 foo3");
}
[Fact]
public void TitleFunctionCanBeOverridenWithinTestAndUseParameters()
{
GivenWeMutateSomeState();
FooClass something = new FooClass();
var context = TestContext.GetContext(something);
Configurator.Scanners.SetDefaultStepTitleCreatorFunction((a, b, c, d, e) => new StepTitle(e + " " + c.Name + " " + string.Join(",", d.Select(arg => arg.Value).ToArray())));
new FluentStepBuilder<FooClass>(something);
var story = something
.Given(_ => GivenWeMutateSomeState())
.When(_ => something.Sub.SomethingHappens())
.And(_ => something.Sub.SomethingWithDifferentTitle())
.Then(_ => ThenTitleHas(AMethodCall()))
.And(_ => something.Sub.SomethingWithArg("foo"))
.And(_ => something.Sub.SomethingWithArg2("foo2"))
.And(_ => something.Sub.SomethingWithArg3("foo3"))
.BDDfy();
story.Scenarios.Single().Steps.ElementAt(0).Title.ShouldBe("Given GivenWeMutateSomeState ");
story.Scenarios.Single().Steps.ElementAt(1).Title.ShouldBe("When SomethingHappens ");
story.Scenarios.Single().Steps.ElementAt(2).Title.ShouldBe("And SomethingWithDifferentTitle ");
story.Scenarios.Single().Steps.ElementAt(3).Title.ShouldBe("Then ThenTitleHas Mutated state");
story.Scenarios.Single().Steps.ElementAt(4).Title.ShouldBe("And SomethingWithArg foo");
story.Scenarios.Single().Steps.ElementAt(5).Title.ShouldBe("And SomethingWithArg2 foo2");
story.Scenarios.Single().Steps.ElementAt(6).Title.ShouldBe("And SomethingWithArg3 foo3");
}
[Fact]
public void TitleFunctionCanBeOverridenFromThestartWithinTestAndUseParameters()
{
GivenWeMutateSomeState();
FooClass something = new FooClass();
var context = TestContext.GetContext(something);
new FluentStepBuilder<FooClass>(something);
var story = something
.SetStepTitleFunction((a, b, c, d, e) => new StepTitle("hello"))
.Given(_ => GivenWeMutateSomeState())
.When(_ => something.Sub.SomethingHappens())
.BDDfy();
story.Scenarios.Single().Steps.ElementAt(0).Title.ShouldBe("hello");
story.Scenarios.Single().Steps.ElementAt(1).Title.ShouldBe("hello");
var story2 = something
.Given(_ => GivenWeMutateSomeState())
.BDDfy();
story2.Scenarios.Single().Steps.ElementAt(0).Title.ShouldBe("Given we mutate some state");
}
public class FooClass
{
public FooClass()
{
Sub = new BarClass();
}
public BarClass Sub { get; set; }
}
public class BarClass
{
public void SomethingHappens()
{
}
[StepTitle("Different title")]
public void SomethingWithDifferentTitle()
{
}
[StepTitle("With arg")]
public void SomethingWithArg(string arg)
{
}
[StepTitle("With arg", false)]
public void SomethingWithArg2(string arg)
{
}
[StepTitle("With {0} arg", false)]
public void SomethingWithArg3(string arg)
{
}
}
private string AMethodCall()
{
return _mutatedState;
}
private void GivenWeMutateSomeState()
{
_mutatedState = "Mutated state";
}
private void ThenTitleHas(string result)
{
result.ShouldBe(_mutatedState);
}
public void Dispose()
{
Configurator.Scanners.SetDefaultStepTitleCreatorFunction(null);
}
}
}