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)); } }
public void DisposeInstances_WithNullArgument_ThrowsExpectedException() { // Act Action action = () => ScopedLifestyle.DisposeInstances(null); // Assert AssertThat.ThrowsWithParamName <ArgumentNullException>("disposables", action); }
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); }
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)); }
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)); }
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)); } }