private static void DisposableBase_ThrowIfDisposed(IDisposableDummy testObj) { Assert.NotNull(testObj); Assert.False(testObj.IsDisposed); testObj.ThrowIfDisposed(); testObj.Dispose(); Assert.Throws <ObjectDisposedException>(() => testObj.ThrowIfDisposed()); }
private static void DisposableBase_ExactlyOneDispose(IDisposableDummy testObj) { Assert.NotNull(testObj); // initially not disposed Assert.False(testObj.IsDisposed); Assert.AreEqual(0, testObj.Dummy.Value); // first Dispose executes testObj.Dispose(); Assert.True(testObj.IsDisposed); Assert.AreEqual(1, testObj.Dummy.Value); // subsequent calls have no effect foreach (var i in Enumerable.Range(0, 3)) { testObj.Dispose(); Assert.True(testObj.IsDisposed); Assert.AreEqual(1, testObj.Dummy.Value); } }