public void dispose_of_managed_resources_is_called_only_once_under_exceptional_circumstances_when_explicitly_disposed() { var obj = new ThrowingDisposableObject(); Assert.Throws<Exception>(() => obj.Dispose()); Assert.Equal(1, obj.DisposeOfManagedResourcesCount); Assert.DoesNotThrow(() => obj.Dispose()); Assert.Equal(1, obj.DisposeOfManagedResourcesCount); }
public void SafeDisposal() { var exceptionHandler = new Moq.Mock<IExceptionHandler>(MockBehavior.Strict); exceptionHandler.Setup(x => x.Warn(It.IsAny<Exception>())).Returns<Exception>(x => x).Verifiable(); ExceptionHandler.Initialise(exceptionHandler.Object); var t = new ThrowingDisposableObject(); t.Dispose(); Assert.That(t.DisposeUnmanagedResourcesCount, Is.EqualTo(1)); Assert.That(t.DisposeManagedResourcesCount, Is.EqualTo(1)); exceptionHandler.Verify(x => x.Warn(It.IsAny<Exception>()), Times.Once()); }
public void is_disposing_is_false_when_dispose_of_managed_resources_throws() { var obj = new ThrowingDisposableObject(); Assert.Throws<Exception>(() => obj.Dispose()); Assert.False(obj.IsDisposingAccessor); }