public void TestLatestException_Dispose_Reserve()
        {
            var item1 = new Mock <IDisposable>();
            var item2 = new Mock <IDisposable>();
            var item3 = new Mock <IDisposable>();
            var item4 = new Mock <IDisposable>();
            var item5 = new Mock <IDisposable>();

            var ex2 = new Exception("2");

            item2.Setup(o => o.Dispose()).Callback(() => throw ex2);

            var ex4 = new Exception("4");

            item4.Setup(o => o.Dispose()).Callback(() => throw ex4);

            var target = new CombinedDisposables(reverse: true, removeDispose: true);

            target.Add(item1.Object);
            target.Add(item2.Object);
            target.Add(item3.Object);
            target.Add(item4.Object);
            target.Add(item5.Object);

            target.Dispose();
            target.LatestException.Should()
            .BeOfType <AggregateException>()
            .Which.InnerExceptions.Should().Equal(ex4, ex2);
        }
        public void TestDispose_Reverse()
        {
            var item1 = new Mock <IDisposable>();
            var item2 = new Mock <IDisposable>();
            var item3 = new Mock <IDisposable>();
            var item4 = new Mock <IDisposable>();
            var item5 = new Mock <IDisposable>();

            var log = new List <IDisposable>();

            item1.Setup(o => o.Dispose()).Callback(() => log.Add(item1.Object));
            item2.Setup(o => o.Dispose()).Callback(() => log.Add(item2.Object));
            item3.Setup(o => o.Dispose()).Callback(() => log.Add(item3.Object));
            item4.Setup(o => o.Dispose()).Callback(() => log.Add(item4.Object));
            item5.Setup(o => o.Dispose()).Callback(() => log.Add(item5.Object));

            var target = new CombinedDisposables(reverse: true, removeDispose: false);

            target.Add(item1.Object);
            target.Add(item2.Object);
            target.Add(item3.Object);
            target.Add(item4.Object);
            target.Add(item5.Object);

            target.Dispose();

            target.Should().HaveCount(0);
            target.IsDisposed.Should().Be(true);
            item1.Verify(o => o.Dispose(), Times.Once());
            item2.Verify(o => o.Dispose(), Times.Once());
            item3.Verify(o => o.Dispose(), Times.Once());
            item4.Verify(o => o.Dispose(), Times.Once());
            item5.Verify(o => o.Dispose(), Times.Once());

            log.Should().Equal(
                item5.Object,
                item4.Object,
                item3.Object,
                item2.Object,
                item1.Object
                );

            var item6 = new Mock <IDisposable>();

            target.Add(item6.Object);
            item6.Verify(o => o.Dispose(), Times.Once());
        }