public async Task UsingAsync_CorrectlyDisposesDisposableObject() { var disposableStub = new DisposableStub(false); await Dispose.UsingAsync(() => disposableStub, async stub => { Assert.False(disposableStub.IsItDisposed); await Task.CompletedTask; }); Assert.True(disposableStub.IsItDisposed); }
public async Task UsingAsync_CorrectlyDisposesDisposableObjectAndReturnsValue() { var disposableStub = new DisposableStub(false); var result = await Dispose.UsingAsync(() => disposableStub, async stub => { Assert.False(disposableStub.IsItDisposed); return(await Task.FromResult(5)); }); Assert.Equal(5, result); Assert.True(disposableStub.IsItDisposed); }