-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathStepExecutorTests.cs
More file actions
67 lines (59 loc) · 1.99 KB
/
StepExecutorTests.cs
File metadata and controls
67 lines (59 loc) · 1.99 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
using System.Text;
using Shouldly;
using TestStack.BDDfy.Configuration;
using TestStack.BDDfy.Tests.Concurrency;
using Xunit;
namespace TestStack.BDDfy.Tests.Configuration
{
[Collection(TestCollectionName.ModifiesConfigurator)]
public class StepExecutorTests
{
private class TestStepExecutor : StepExecutor
{
readonly StringBuilder _builder = new();
public string Results
{
get { return _builder.ToString(); }
}
public override object Execute(Step step, object testObject)
{
try
{
_builder.AppendLine(string.Format("About to run step '{0}'", step.Title));
return base.Execute(step, testObject);
}
finally
{
_builder.AppendLine(string.Format("Finished running step '{0}'", step.Title));
}
}
}
[Fact]
public void CustomizingStepExecutionByOverridingStepExecutor()
{
try
{
var testStepExecutor = new TestStepExecutor();
Configurator.StepExecutor = testStepExecutor;
new EmptyScenario()
.Given(s => s.GivenSomething())
.When(s => s.WhenSomething())
.Then(s => s.ThenSomething())
.BDDfy();
string expected =
@"About to run step 'Given something'
Finished running step 'Given something'
About to run step 'When something'
Finished running step 'When something'
About to run step 'Then something'
Finished running step 'Then something'
".Replace("\r", string.Empty).Trim();
testStepExecutor.Results.Replace("\r", string.Empty).Trim().ShouldBe(expected);
}
finally
{
Configurator.StepExecutor = new StepExecutor();
}
}
}
}