Ejemplo n.º 1
0
        public void NewInstance_ByDefault_IsNotDisposed()
        {
            // Arrange
            var resource = new DisposableResourceSpy();

            // Act

            // Assert
            Assert.IsFalse(resource.IsDisposed);
        }
Ejemplo n.º 2
0
        public void Dispose_ByDefault_Disposes()
        {
            // Arrange
            var resource = new DisposableResourceSpy();

            // Act
            resource.Dispose();

            // Assert
            Assert.IsTrue(resource.IsDisposed);
        }
Ejemplo n.º 3
0
        public async Task DisposeAsync_ByDefault_CallsAsyncHook()
        {
            // Arrange
            var resource = new DisposableResourceSpy();

            // Act
            await resource.DisposeAsync().ConfigureAwait(false);

            // Assert
            Assert.AreEqual(0, resource.ReleaseManagedResourcesCallCount);
            Assert.AreEqual(0, resource.ReleaseNativeResourcesCallCount);
            Assert.AreEqual(1, resource.ReleaseManagedResourcesAsyncCallCount);
        }
Ejemplo n.º 4
0
        public void Dispose_ByDefault_CallsAllSyncHooks()
        {
            // Arrange
            var resource = new DisposableResourceSpy();

            // Act
            resource.Dispose();

            // Assert
            Assert.AreEqual(1, resource.ReleaseManagedResourcesCallCount);
            Assert.AreEqual(1, resource.ReleaseNativeResourcesCallCount);
            Assert.AreEqual(0, resource.ReleaseManagedResourcesAsyncCallCount);
        }
Ejemplo n.º 5
0
        public void Dispose_CalledTwice_CallsSyncHooksOnlyOnce()
        {
            // Arrange
            var resource = new DisposableResourceSpy();

            // Act
            resource.Dispose();
            resource.Dispose();

            // Assert
            Assert.AreEqual(1, resource.ReleaseManagedResourcesCallCount);
            Assert.AreEqual(1, resource.ReleaseNativeResourcesCallCount);
            Assert.AreEqual(0, resource.ReleaseManagedResourcesAsyncCallCount);
        }