26 lines
741 B
C#
26 lines
741 B
C#
using Bunit;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Xunit;
|
|
public sealed class AsyncLifecycleTests
|
|
{
|
|
[Fact]
|
|
public async Task Context_awaits_async_service_disposal()
|
|
{
|
|
var context = new BunitContext();
|
|
context.Services.AddScoped<AsyncResource>();
|
|
var resource = context.Services.GetRequiredService<AsyncResource>();
|
|
Assert.False(resource.Disposed);
|
|
await context.DisposeAsync();
|
|
Assert.True(resource.Disposed);
|
|
}
|
|
public sealed class AsyncResource : IAsyncDisposable
|
|
{
|
|
public bool Disposed { get; private set; }
|
|
public async ValueTask DisposeAsync()
|
|
{
|
|
await Task.Yield();
|
|
Disposed = true;
|
|
}
|
|
}
|
|
}
|