public void Dispose_MultipleObjectsInReverseOrder() { MultiDisposable subject = new MultiDisposable(); TestDisposable first = subject.Add(new TestDisposable()); TestDisposable middle = subject.Add(new TestDisposable()); TestDisposable last = subject.Add(new TestDisposable()); subject.Dispose(); Assert.IsTrue(first.DisposedOrderPosition > middle.DisposedOrderPosition && middle.DisposedOrderPosition > last.DisposedOrderPosition); }
public void Dispose_MultipleObjectsAllDisposed_LastExceptionThrown() { MultiDisposable subject = new MultiDisposable(); const string lastExceptionMessage = "Last exception"; Exception lastException = new Exception(lastExceptionMessage); TestDisposable first = subject.Add(new TestDisposable(lastException)); TestDisposable middle = subject.Add(new TestDisposable(new Exception())); TestDisposable last = subject.Add(new TestDisposable(new Exception())); try { subject.Dispose(); Assert.Fail("Exception should have been thrown"); } catch (Exception ex) { Assert.AreSame(lastException, ex); Assert.AreEqual(lastExceptionMessage, ex.Message); } Assert.IsTrue(last.DisposedOrderPosition > 0U); Assert.IsTrue(first.DisposedOrderPosition > middle.DisposedOrderPosition && middle.DisposedOrderPosition > last.DisposedOrderPosition); }