Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using Xunit.Microsoft.DependencyInjection.Abstracts;
using Xunit.Microsoft.DependencyInjection.ExampleTests.Services;

Expand All @@ -12,6 +13,9 @@ protected override void AddServices(IServiceCollection services, IConfiguration
.AddTransient<ICalculator, Calculator>()
.Configure<Options>(config => configuration.GetSection("Options").Bind(config));

protected override ValueTask DisposeAsyncCore()
=> new ValueTask();

protected override string GetConfigurationFile()
=> "appsettings.json";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Options;
using System.Threading.Tasks;
using Xunit.Abstractions;
using Xunit.Microsoft.DependencyInjection.Abstracts;
using Xunit.Microsoft.DependencyInjection.ExampleTests.Fixtures;
Expand Down Expand Up @@ -40,5 +41,8 @@ public void Test2(int x, int y)
protected override void Clear()
{
}

protected override ValueTask DisposeAsyncCore()
=> new ValueTask();
}
}
9 changes: 7 additions & 2 deletions src/Abstracts/TestBed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public abstract class TestBed<TFixture> : IDisposable, IClassFixture<TFixture>,
protected readonly ITestOutputHelper _testOutputHelper;
protected readonly TFixture _fixture;
private bool _disposedValue;
private bool _disposedAsync;

public TestBed(ITestOutputHelper testOutputHelper, TFixture fixture)
=> (_testOutputHelper, _fixture) = (testOutputHelper, fixture);
Expand Down Expand Up @@ -48,8 +49,12 @@ public void Dispose()

public async ValueTask DisposeAsync()
{
await DisposeAsyncCore();
GC.SuppressFinalize(this);
if (!_disposedAsync)
{
await DisposeAsyncCore();
GC.SuppressFinalize(this);
_disposedAsync = true;
}
}

protected abstract ValueTask DisposeAsyncCore();
Expand Down
9 changes: 7 additions & 2 deletions src/Abstracts/TestBedFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public abstract class TestBedFixture : IDisposable, IAsyncDisposable
private readonly IServiceCollection _services;
private IServiceProvider _serviceProvider;
private bool _disposedValue;
private bool _disposedAsync;

protected TestBedFixture()
{
Expand Down Expand Up @@ -99,8 +100,12 @@ public void Dispose()

public async ValueTask DisposeAsync()
{
await DisposeAsyncCore();
GC.SuppressFinalize(this);
if (!_disposedAsync)
{
await DisposeAsyncCore();
GC.SuppressFinalize(this);
_disposedAsync = true;
}
}

protected abstract ValueTask DisposeAsyncCore();
Expand Down