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(); var resource = context.Services.GetRequiredService(); 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; } } }