| | | 1 | | namespace Nabs.Tests; |
| | | 2 | | |
| | | 3 | | public abstract class FixtureTestBase<TTestFixture> |
| | | 4 | | : IClassFixture<TTestFixture>, IAsyncLifetime |
| | | 5 | | where TTestFixture : TestFixtureBase |
| | | 6 | | { |
| | | 7 | | |
| | | 8 | | protected FixtureTestBase(ITestOutputHelper testOutputHelper, TTestFixture testFixture) |
| | | 9 | | { |
| | | 10 | | var testClassName = GetType().Name; |
| | 5 | 11 | | var message = $"[{testClassName}] is constructing..."; |
| | | 12 | | |
| | 5 | 13 | | TestFixture = testFixture; |
| | 5 | 14 | | TestFixture.TestOutputHelper = testOutputHelper; |
| | | 15 | | |
| | 5 | 16 | | TestFixture.OutputLine(message); |
| | 5 | 17 | | TestFixture.OutputLine(new string('=', message.Length)); |
| | | 18 | | |
| | 5 | 19 | | } |
| | | 20 | | |
| | | 21 | | protected TTestFixture TestFixture { get; } = default!; |
| | | 22 | | |
| | | 23 | | public void OutputScenario(string scenario = "default", [CallerMemberName] string? caller = null) |
| | | 24 | | { |
| | 1 | 25 | | TestFixture.OutputLine($"[{caller}] - Scenario: {scenario}"); |
| | 1 | 26 | | } |
| | | 27 | | |
| | | 28 | | public void OutputStep(string stepName) |
| | | 29 | | { |
| | 1 | 30 | | TestFixture.OutputLine($"Step: {stepName}"); |
| | 1 | 31 | | } |
| | | 32 | | |
| | | 33 | | protected virtual async Task StartTest() |
| | | 34 | | { |
| | 5 | 35 | | await Task.CompletedTask; |
| | 5 | 36 | | } |
| | | 37 | | |
| | | 38 | | protected virtual async Task TeardownTest() |
| | | 39 | | { |
| | 5 | 40 | | await Task.CompletedTask; |
| | 5 | 41 | | } |
| | | 42 | | |
| | | 43 | | public async Task InitializeAsync() |
| | | 44 | | { |
| | 5 | 45 | | TestFixture.OutputLine("Test is initialising"); |
| | 5 | 46 | | TestFixture.Initialise(); |
| | 5 | 47 | | await StartTest(); |
| | 5 | 48 | | } |
| | | 49 | | |
| | | 50 | | public async Task DisposeAsync() |
| | | 51 | | { |
| | 5 | 52 | | await TeardownTest(); |
| | 5 | 53 | | TestFixture.OutputLine("Test has ended"); |
| | 5 | 54 | | } |
| | | 55 | | } |