/
TestBed.cs
53 lines (46 loc) · 1.45 KB
/
TestBed.cs
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
namespace Xunit.Microsoft.DependencyInjection.Abstracts;
public class TestBed<TFixture>(ITestOutputHelper testOutputHelper, TFixture fixture) : IDisposable, IClassFixture<TFixture>, IAsyncDisposable
where TFixture : class
{
protected readonly ITestOutputHelper _testOutputHelper = testOutputHelper;
protected readonly TFixture _fixture = fixture;
private bool _disposedValue;
private bool _disposedAsync;
protected virtual void Dispose(bool disposing)
{
if (!_disposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
Clear();
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
_disposedValue = true;
}
}
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
// ~AbstractTest()
// {
// // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
// Dispose(disposing: false);
// }
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
public async ValueTask DisposeAsync()
{
if (!_disposedAsync)
{
await DisposeAsyncCore();
GC.SuppressFinalize(this);
_disposedAsync = true;
}
}
protected virtual void Clear() { }
protected virtual ValueTask DisposeAsyncCore() => new();
}