public void Test_Disposable()
        {
            var disposable = new DisposableStub();

            disposable.Dispose();
            Assert.IsTrue(disposable.IsDisposed);
            Assert.IsTrue(DisposeManagedResourcesCalled);
            Assert.IsTrue(DisposeUnmanagedResourcesCalled);
        }
Exemple #2
0
        public void Generic_Dispose_WithDisposable_CallsDispose()
        {
            DisposableStub disposableStub = new DisposableStub();

            using (Disposable <DisposableStub> disposable = new Disposable <DisposableStub>(disposableStub, () => { }))
            {
            }

            Assert.True(disposableStub.DisposeWasCalled);
        }
Exemple #3
0
        public void disposable_gets_and_sets_the_underlying_disposable()
        {
            var sut    = new SerialDisposable <DisposableStub>();
            var first  = new DisposableStub();
            var second = new DisposableStub();

            sut.Disposable = first;
            sut.Disposable = second;

            Assert.True(first.IsDisposed);
            Assert.False(second.IsDisposed);
        }
        public void ShouldDisposeOfDisposableItemsWithinGeneralCollection()
        {
            var stub1 = new DisposableStub();
            var stub2 = new DisposableStub();

            var list = new List<object>
                           {
                               stub1,
                               "string",
                               42,
                               null,
                               stub2,
                           };
            list.DisposeOfChildren();

            stub1.IsDisposed.ShouldBe(true);
            stub2.IsDisposed.ShouldBe(true);
        }