public void TestLatestException_Clear_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 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.Clear();
            target.LatestException.Should()
            .BeOfType <AggregateException>()
            .Which.InnerExceptions.Should().Equal(ex4, ex2);
        }
        public void TestLatestException_Clear_Single()
        {
            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 ex4 = new Exception("4");

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

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

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

            target.Clear();
            target.LatestException.Should()
            .BeOfType <Exception>()
            .Which.Should().BeSameAs(ex4);
        }
        public void TestClear_NoDispose()
        {
            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 target = new CombinedDisposables();

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

            target.DisposeOnRemove.Should().Be(false, "念のため前提を確認");
            target.Clear();
            target.Should().HaveCount(0);

            item1.Verify(o => o.Dispose(), Times.Never());
            item2.Verify(o => o.Dispose(), Times.Never());
            item3.Verify(o => o.Dispose(), Times.Never());
            item4.Verify(o => o.Dispose(), Times.Never());
            item5.Verify(o => o.Dispose(), Times.Never());
        }
        public void TestClear_WithDispose_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: true);

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

            target.DisposeOnRemove.Should().Be(true, "念のため前提を確認");
            target.Clear();
            target.Should().HaveCount(0);
            target.IsDisposed.Should().Be(false);

            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
                );
        }