public void TestLatestException_Remove()
        {
            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.Remove(item1.Object).Should().Be(true);
            target.LatestException.Should().BeNull();

            target.Remove(item2.Object).Should().Be(true);
            target.LatestException.Should().BeSameAs(ex2);

            target.Remove(item3.Object).Should().Be(true);
            target.LatestException.Should().BeNull();

            target.Remove(item4.Object).Should().Be(true);
            target.LatestException.Should().BeSameAs(ex4);

            target.Remove(item5.Object).Should().Be(true);
            target.LatestException.Should().BeNull();
        }
        public void TestRemove_WithDispose()
        {
            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(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.Remove(item2.Object).Should().Be(true);
            target.Should().Equal(
                item1.Object,
                item3.Object,
                item4.Object,
                item5.Object
                );
            item2.Verify(o => o.Dispose(), Times.Once());

            target.Remove(item2.Object).Should().Be(false, "除去済みオブジェクトを再指定");
            target.Should().Equal(
                item1.Object,
                item3.Object,
                item4.Object,
                item5.Object
                );
            item2.Verify(o => o.Dispose(), Times.Exactly(2));

            target.Remove(item1.Object).Should().Be(true);
            target.Remove(item3.Object).Should().Be(true);
            target.Remove(item4.Object).Should().Be(true);
            target.Remove(item5.Object).Should().Be(true);
            target.Should().HaveCount(0);
            item1.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());

            var item6 = new Mock <IDisposable>();

            target.Remove(item6.Object).Should().Be(false);
            item6.Verify(o => o.Dispose(), Times.Once());
        }
        public void TestContains()
        {
            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(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.Should().HaveCount(5);

            target.Remove(item2.Object);
            target.Contains(item1.Object).Should().Be(true);
            target.Contains(item2.Object).Should().Be(false);
            target.Contains(item3.Object).Should().Be(true);
            target.Contains(item4.Object).Should().Be(true);
            target.Contains(item5.Object).Should().Be(true);

            target.Remove(item2.Object);    // 同じオブジェクトを再度指定
            target.Contains(item1.Object).Should().Be(true);
            target.Contains(item2.Object).Should().Be(false);
            target.Contains(item3.Object).Should().Be(true);
            target.Contains(item4.Object).Should().Be(true);
            target.Contains(item5.Object).Should().Be(true);

            target.Remove(item1.Object);
            target.Remove(item3.Object);
            target.Remove(item4.Object);
            target.Remove(item5.Object);
            target.Contains(item1.Object).Should().Be(false);
            target.Contains(item2.Object).Should().Be(false);
            target.Contains(item3.Object).Should().Be(false);
            target.Contains(item4.Object).Should().Be(false);
            target.Contains(item5.Object).Should().Be(false);
        }
        public void TestRemove_ArgNull()
        {
            var target = new CombinedDisposables();

            new Action(() => target.Remove(null)).Should().Throw <ArgumentNullException>();
        }