public void Dispose_NotCalled_DisposeMethodsAreNotInvoked() { // Arrange var cut = new DisposableUnderTest(); // Assert Assert.False(cut.IsDisposeManagedCalled); Assert.False(cut.IsDisposeUnmanagedCalled); }
public void IsDisposed_NotDisposed_ReturnsFalse() { // Arrange using var sut = new DisposableUnderTest(); // Act var actual = sut.IsDisposed; // Assert Assert.False(actual); }
public void IsDisposed_Disposed_ReturnsTrue() { // Arrange var sut = new DisposableUnderTest(); // Act sut.Dispose(); // Assert Assert.True(sut.IsDisposed); }
public void ThrowIfDisposed_NotDisposed_DoesNotThrow() { // Arrange using var sut = new DisposableUnderTest(); // Act void ThrowIfDisposed() => sut.ThrowIfDisposed(); // Assert Assert.DoesNotThrow(ThrowIfDisposed); }
public void ThrowIfDisposed_Disposed_Throws() { // Arrange var sut = new DisposableUnderTest(); // Act sut.Dispose(); void ThrowIfDisposed() => sut.ThrowIfDisposed(); // Assert Assert.Throws <ObjectDisposedException>(ThrowIfDisposed); }
public void Dispose_Called_InvokesDisposeMethods() { // Arrange var cut = new DisposableUnderTest(); // Act cut.Dispose(); // Assert Assert.True(cut.IsDisposeManagedCalled); Assert.True(cut.IsDisposeUnmanagedCalled); }
public void Dispose_CalledMultipleTimes_DisposesResourcesOnce() { // Arrange var sut = new DisposableUnderTest(); // Act sut.Dispose(); sut.Dispose(); // Assert Assert.AreEqual(1, sut.DisposeCalledCount); }
public void Dispose_CalledMultipleTimes_DoesNotThrow() { // Arrange var sut = new DisposableUnderTest(); // Act void DisposeManyTimes() { for (var i = 0; i < 15; i++) { sut.Dispose(); } } // Assert Assert.DoesNotThrow(DisposeManyTimes); }