コード例 #1
0
        public void DisposeInstances_WithMultipleItemsThatThrow_WillBubbleUpTheLastThrownException()
        {
            // Arrange
            var disposables = new List <DisposableObject>
            {
                new DisposableObject(new Exception()),
                new DisposableObject(new Exception()),
                new DisposableObject(new Exception()),
                new DisposableObject(),
                new DisposableObject(new Exception()),
                new DisposableObject(new Exception())
            };

            try
            {
                // Act
                ScopedLifestyle.DisposeInstances(disposables.Cast <IDisposable>().ToList());

                // Assert
                Assert.Fail("Exception was expected to bubble up.");
            }
            catch (Exception ex)
            {
                Assert.IsTrue(object.ReferenceEquals(disposables.First().ExceptionToThrow, ex));
            }
        }
コード例 #2
0
        public void DisposeInstances_WithNullArgument_ThrowsExpectedException()
        {
            // Act
            Action action = () => ScopedLifestyle.DisposeInstances(null);

            // Assert
            AssertThat.ThrowsWithParamName <ArgumentNullException>("disposables", action);
        }
コード例 #3
0
        public void DisposeInstances_ListWithOneItem_DisposesItem()
        {
            // Arrange
            var disposable = new DisposableObject();

            var disposables = new List <IDisposable> {
                disposable
            };

            // Act
            ScopedLifestyle.DisposeInstances(disposables);

            // Assert
            Assert.AreEqual(1, disposable.DisposeCount);
        }
コード例 #4
0
        public void DisposeInstances_ListWithMultipleItems_DisposesAllItems()
        {
            // Arrange
            var disposables = new List <DisposableObject>
            {
                new DisposableObject(),
                new DisposableObject(),
                new DisposableObject()
            };

            // Act
            ScopedLifestyle.DisposeInstances(disposables.Cast <IDisposable>().ToList());

            // Assert
            Assert.IsTrue(disposables.All(d => d.DisposeCount == 1));
        }
コード例 #5
0
        public void DisposeInstances_ListWithMultipleItems_DisposesAllItemsInReversedOrder()
        {
            // Arrange
            var disposedItems = new List <DisposableObject>();

            var disposables = new List <DisposableObject>
            {
                new DisposableObject(disposedItems.Add),
                new DisposableObject(disposedItems.Add),
                new DisposableObject(disposedItems.Add)
            };

            // Act
            ScopedLifestyle.DisposeInstances(disposables.Cast <IDisposable>().ToList());

            disposedItems.Reverse();

            // Assert
            Assert.IsTrue(disposedItems.SequenceEqual(disposables));
        }
コード例 #6
0
        public void DisposeInstances_WithMultipleItemsThatThrow_StillDisposesAllItems()
        {
            // Arrange
            var disposables = new List <DisposableObject>
            {
                new DisposableObject(new Exception()),
                new DisposableObject(new Exception()),
                new DisposableObject(new Exception())
            };

            try
            {
                // Act
                ScopedLifestyle.DisposeInstances(disposables.Cast <IDisposable>().ToList());

                // Assert
                Assert.Fail("Exception was expected to bubble up.");
            }
            catch
            {
                Assert.IsTrue(disposables.All(d => d.DisposeCount == 1));
            }
        }