Beispiel #1
0
        public void ListClearsOnDisposal()
        {
            DisposingList <DisposalbleItem> test = new DisposingList <DisposalbleItem>();

            const int MAX = 10;

            for (int i = 0; i < MAX; i++)
            {
                test.Add(new DisposalbleItem());
            }

            // We pass the references off somewhere else so we can keep track of them.
            List <DisposalbleItem> check = new List <DisposalbleItem>();

            for (int i = 0; i < test.Count; i++)
            {
                check.Add(test[i]);
                Assert.IsFalse(test[i].IsDisposed);
            }


            // Now dispose it.
            test.Dispose();
            Assert.AreEqual(0, test.Count, "There should be no more items in the list!");

            for (int i = 0; i < check.Count; i++)
            {
                Assert.IsTrue(check[i].IsDisposed, "The item at index {0} should be disposed!", i);
            }
        }
Beispiel #2
0
        /// <summary> Disposes of the stream and then all objects in the disposable list </summary>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                _disposables.Dispose();
            }
        }
Beispiel #3
0
        public void Dispose_Then_ItemsShouldBeDisposedInExpectedOrder()
        {
            var expectedOrder = new[] { 1, 2 };
            var testee        = new DisposingList <DisposeAction>();
            var disposeOrder  = new List <int>();

            testee.Add(new DisposeAction(() => disposeOrder.Add(1)));
            testee.Add(new DisposeAction(() => disposeOrder.Add(2)));

            testee.Dispose();

            disposeOrder.Should().Equal(expectedOrder);
        }
Beispiel #4
0
        public void TestGeneric()
        {
            disposeOrder.Clear();
            DisposingList <DisposeInOrder> list = new DisposingList <DisposeInOrder>();

            DisposeInOrder a = new DisposeInOrder();
            DisposeInOrder b = new DisposeInOrder();

            list.Add(a);
            list.Add(b);
            list.Add(null);
            list.Dispose();

            //Removed from list?
            Assert.AreEqual(0, list.Count);
            //All were disposed?
            Assert.AreEqual(2, disposeOrder.Count);
            //Disposed in reverse order of creation?
            Assert.IsTrue(object.ReferenceEquals(b, disposeOrder[0]));
            Assert.IsTrue(object.ReferenceEquals(a, disposeOrder[1]));

            Assert.AreEqual(2, new DisposingList <DisposeInOrder>(new DisposeInOrder[] { a, b }).Count);
            Assert.AreEqual(0, new DisposingList <DisposeInOrder>(5).Count);
        }
        public void TestGeneric()
        {
            disposeOrder.Clear();
            DisposingList<DisposeInOrder> list = new DisposingList<DisposeInOrder>();

            DisposeInOrder a = new DisposeInOrder();
            DisposeInOrder b = new DisposeInOrder();

            list.Add(a);
            list.Add(b);
            list.Add(null);
            list.Dispose();

            //Removed from list?
            Assert.AreEqual(0, list.Count);
            //All were disposed?
            Assert.AreEqual(2, disposeOrder.Count);
            //Disposed in reverse order of creation?
            Assert.IsTrue(object.ReferenceEquals(b, disposeOrder[0]));
            Assert.IsTrue(object.ReferenceEquals(a, disposeOrder[1]));

            Assert.AreEqual(2, new DisposingList<DisposeInOrder>(new DisposeInOrder[] { a, b }).Count);
            Assert.AreEqual(0, new DisposingList<DisposeInOrder>(5).Count);
        }
Beispiel #6
0
 public void Dispose()
 {
     _disposables.Dispose();
 }