Beispiel #1
0
		public void TerminatingWorkItemCausesContainedObjectsToBeDisposed()
		{
			WorkItem wi = new TestableRootWorkItem();
			MockDisposableObject obj = wi.Items.AddNew<MockDisposableObject>();

			wi.Terminate();

			Assert.IsTrue(obj.WasDisposed);
		}
        public void DisposingContainerDisposesOwnedObjects()
        {
            ILifetimeContainer   container = new LifetimeContainer();
            MockDisposableObject mdo       = new MockDisposableObject();

            container.Add(mdo);
            container.Dispose();

            Assert.IsTrue(mdo.WasDisposed);
        }
		public void DisposingContainerDisposesOwnedObjects()
		{
			ILifetimeContainer container = new LifetimeContainer();
			MockDisposableObject mdo = new MockDisposableObject();

			container.Add(mdo);
			container.Dispose();

			Assert.IsTrue(mdo.WasDisposed);
		}
        public void RemovingItemsFromContainerDoesNotDisposeThem()
        {
            ILifetimeContainer   container = new LifetimeContainer();
            MockDisposableObject mdo       = new MockDisposableObject();

            container.Add(mdo);
            container.Remove(mdo);
            container.Dispose();

            Assert.IsFalse(mdo.WasDisposed);
        }
		public void RemovingItemsFromContainerDoesNotDisposeThem()
		{
			ILifetimeContainer container = new LifetimeContainer();
			MockDisposableObject mdo = new MockDisposableObject();

			container.Add(mdo);
			container.Remove(mdo);
			container.Dispose();

			Assert.IsFalse(mdo.WasDisposed);
		}
        public void ContainerEnsuresObjectsWontBeCollected()
        {
            ILifetimeContainer   container = new LifetimeContainer();
            MockDisposableObject mdo       = new MockDisposableObject();
            WeakReference        wref      = new WeakReference(mdo);

            container.Add(mdo);
            mdo = null;
            GC.Collect();

            Assert.AreEqual(1, container.Count);
            mdo = wref.Target as MockDisposableObject;
            Assert.IsNotNull(mdo);
            Assert.IsFalse(mdo.WasDisposed);
        }
		public void ContainerEnsuresObjectsWontBeCollected()
		{
			ILifetimeContainer container = new LifetimeContainer();
			MockDisposableObject mdo = new MockDisposableObject();
			WeakReference wref = new WeakReference(mdo);

			container.Add(mdo);
			mdo = null;
			GC.Collect();

			Assert.AreEqual(1, container.Count);
			mdo = wref.Target as MockDisposableObject;
			Assert.IsNotNull(mdo);
			Assert.IsFalse(mdo.WasDisposed);
		}
		public void CanEnumerateItemsInContainer()
		{
			ILifetimeContainer container = new LifetimeContainer();
			MockDisposableObject mdo = new MockDisposableObject();

			container.Add(mdo);

			int count = 0;
			bool foundMdo = false;

			foreach (object obj in container)
			{
				count++;

				if (ReferenceEquals(mdo, obj))
					foundMdo = true;
			}

			Assert.AreEqual(1, count);
			Assert.IsTrue(foundMdo);
		}
        public void CanEnumerateItemsInContainer()
        {
            ILifetimeContainer   container = new LifetimeContainer();
            MockDisposableObject mdo       = new MockDisposableObject();

            container.Add(mdo);

            int  count    = 0;
            bool foundMdo = false;

            foreach (object obj in container)
            {
                count++;

                if (ReferenceEquals(mdo, obj))
                {
                    foundMdo = true;
                }
            }

            Assert.AreEqual(1, count);
            Assert.IsTrue(foundMdo);
        }