Repository navigation
Expand file tree
/
Copy pathSingleProcessControlStepDefinitions.cs
More file actions
100 lines (86 loc) · 2.72 KB
/
Copy pathSingleProcessControlStepDefinitions.cs
File metadata and controls
100 lines (86 loc) · 2.72 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
using System;
using TechTalk.SpecFlow;
using Xunit.Abstractions;
namespace TestProcessWrapper.Acceptance.Tests.Steps.Common
{
[Binding]
public sealed class SingleProcessControlStepDefinitions : IDisposable
{
private readonly ITestOutputHelper _testOutputHelper;
private bool _isDisposed;
private const BuildConfiguration DefaultBuildConfiguration =
#if DEBUG
BuildConfiguration.Debug;
#else
BuildConfiguration.Release;
#endif
public SingleProcessControlStepDefinitions(
ScenarioContext scenarioContext,
ITestOutputHelper testOutputHelper
) => _testOutputHelper = testOutputHelper;
public static TestProcessWrapper Client { get; private set; }
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
~SingleProcessControlStepDefinitions()
{
Dispose(false);
}
private void Dispose(bool disposing)
{
if (_isDisposed)
{
return;
}
if (disposing)
{
Client?.Dispose();
}
_isDisposed = true;
}
[Given(@"A long lived application was wrapped into TestProcessWrapper")]
public void GivenALongLivedApplicationWasWrappedIntoTestProcessWrapper()
{
Client = new TestProcessWrapper(
"TestProcessWrapper.LongLived.Application",
false,
DefaultBuildConfiguration
);
Client.TestOutputHelper = _testOutputHelper;
}
[Given(@"A short lived application was wrapped into TestProcessWrapper")]
public void GivenAShortLivedApplicationWasWrappedIntoTestProcessWrapper()
{
Client = new TestProcessWrapper(
"TestProcessWrapper.ShortLived.Application",
false,
DefaultBuildConfiguration
);
Client.TestOutputHelper = _testOutputHelper;
}
[Given(@"coverlet has been enabled")]
public static void GivenCoverletHasBeenEnabled()
{
Client.IsCoverletEnabled = true;
}
[When]
public static void WhenTheApplicationIsReady()
{
Client.Start();
}
[AfterScenario]
public static void ShutdownClient()
{
if (Client == null)
{
return;
}
Client.ShutdownGracefully();
Client.ForceTermination();
Client.Dispose();
Client = null; // Prevent Client from being shutdown twice when running multiple tests, because Client is static.
}
}
}