Exemple #1
0
        public void Dispose_NotCalled_DisposeMethodsAreNotInvoked()
        {
            // Arrange
            var cut = new DisposableUnderTest();

            // Assert
            Assert.False(cut.IsDisposeManagedCalled);
            Assert.False(cut.IsDisposeUnmanagedCalled);
        }
Exemple #2
0
        public void IsDisposed_NotDisposed_ReturnsFalse()
        {
            // Arrange
            using var sut = new DisposableUnderTest();

            // Act
            var actual = sut.IsDisposed;

            // Assert
            Assert.False(actual);
        }
Exemple #3
0
        public void IsDisposed_Disposed_ReturnsTrue()
        {
            // Arrange
            var sut = new DisposableUnderTest();

            // Act
            sut.Dispose();

            // Assert
            Assert.True(sut.IsDisposed);
        }
Exemple #4
0
        public void ThrowIfDisposed_NotDisposed_DoesNotThrow()
        {
            // Arrange
            using var sut = new DisposableUnderTest();

            // Act
            void ThrowIfDisposed() => sut.ThrowIfDisposed();

            // Assert
            Assert.DoesNotThrow(ThrowIfDisposed);
        }
Exemple #5
0
        public void ThrowIfDisposed_Disposed_Throws()
        {
            // Arrange
            var sut = new DisposableUnderTest();

            // Act
            sut.Dispose();
            void ThrowIfDisposed() => sut.ThrowIfDisposed();

            // Assert
            Assert.Throws <ObjectDisposedException>(ThrowIfDisposed);
        }
Exemple #6
0
        public void Dispose_Called_InvokesDisposeMethods()
        {
            // Arrange
            var cut = new DisposableUnderTest();

            // Act
            cut.Dispose();

            // Assert
            Assert.True(cut.IsDisposeManagedCalled);
            Assert.True(cut.IsDisposeUnmanagedCalled);
        }
Exemple #7
0
        public void Dispose_CalledMultipleTimes_DisposesResourcesOnce()
        {
            // Arrange
            var sut = new DisposableUnderTest();

            // Act
            sut.Dispose();
            sut.Dispose();

            // Assert
            Assert.AreEqual(1, sut.DisposeCalledCount);
        }
Exemple #8
0
        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);
        }