public async ValueTask TestAsync() { var instance = new TestCoreDisposable(); var disposed1 = instance.Disposed; await instance.DisposeAsync(); Assert.False(disposed1); Assert.True(instance.Disposed); }
public void Test1() { var instance = new TestCoreDisposable(); var disposed1 = instance.Disposed; instance.Dispose(); Assert.False(disposed1); Assert.True(instance.Disposed); }
public void TestException() { var instance = new TestCoreDisposable(); Exception nullExc = null; try { instance.ThrowIfDisposed("a test method"); } catch (Exception e) { nullExc = e; } instance.Dispose(); Exception exc0 = null; Exception exc1 = null; try { instance.ThrowIfDisposed("a test method"); } catch (Exception e) { exc0 = e; } try { instance.ThrowIfDisposed(); } catch (Exception e2) { exc1 = e2; } Assert.Null(nullExc); Assert.NotNull(exc0); Assert.NotNull(exc1); Assert.True(exc0 is ObjectDisposedException); Assert.True(exc1 is ObjectDisposedException); }