public void TestDisposeTwice()
        {
            var obj = new ManagedDisposableObject();

            this.manager.Register(obj);
            obj.Dispose();
            obj.Dispose();
        }
        public void TestDisposeTwice()
        {
            var obj = new ManagedDisposableObject();

            this.manager.Register(obj);
            obj.Dispose();
            obj.Dispose();
        }
        public void VerifyManagedDisposableObjectDisposeSetsWasDisposedToTrue()
        {
            var object1 = new ManagedDisposableObject();

            object1.Dispose();
            Assert.IsTrue(object1.WasDisposed);
        }
        public void VerifyAllChildrenAreDisposedWhenParentIsDisposed()
        {
            var parent   = new ManagedDisposableObject();
            var children = new ManagedDisposableObject[]
            {
                new ManagedDisposableObject(),
                new ManagedDisposableObject(),
                new ManagedDisposableObject(),
                new ManagedDisposableObject(),
                new ManagedDisposableObject(),
                new ManagedDisposableObject(),
            };

            this.manager.Register(parent);
            foreach (ManagedDisposableObject child in children)
            {
                this.manager.RegisterAsDependent(child, parent);
            }

            parent.Dispose();
            foreach (ManagedDisposableObject child in children)
            {
                Assert.IsTrue(child.WasDisposed);
            }
        }
        public void VerifyParentIsNotDisposedWhenChildIsDisposed()
        {
            var parent = new ManagedDisposableObject();
            var child  = new ManagedDisposableObject();

            this.manager.Register(parent);
            this.manager.RegisterAsDependent(child, parent);

            child.Dispose();
            Assert.IsFalse(parent.WasDisposed);
        }
        public void VerifyChildObjectIsDisposedWhenParentIsDisposed()
        {
            var parent = new ManagedDisposableObject();
            var child  = new ManagedDisposableObject();

            this.manager.Register(parent);
            this.manager.RegisterAsDependent(child, parent);

            parent.Dispose();
            Assert.IsTrue(child.WasDisposed);
        }
        public void TestDisposingParentWhenSomeChildrenAreUnreferenced()
        {
            var parent = new ManagedDisposableObject();
            var child = new ManagedDisposableObject();

            this.manager.Register(parent);

            this.manager.RegisterAsDependent(new ManagedDisposableObject(), parent);
            this.manager.RegisterAsDependent(child, parent);
            this.manager.RegisterAsDependent(new ManagedDisposableObject(), parent);

            TestUtilities.FinalizeAndGCCollect();
            Assert.IsFalse(child.WasDisposed);
            parent.Dispose();
            Assert.IsTrue(child.WasDisposed);
        }
        public void TestDisposingParentWhenSomeChildrenAreUnreferenced()
        {
            var parent = new ManagedDisposableObject();
            var child  = new ManagedDisposableObject();

            this.manager.Register(parent);

            this.manager.RegisterAsDependent(new ManagedDisposableObject(), parent);
            this.manager.RegisterAsDependent(child, parent);
            this.manager.RegisterAsDependent(new ManagedDisposableObject(), parent);

            TestUtilities.FinalizeAndGCCollect();
            Assert.IsFalse(child.WasDisposed);
            parent.Dispose();
            Assert.IsTrue(child.WasDisposed);
        }
        public void VerifyAllChildrenAreDisposedWhenParentIsDisposed()
        {
            var parent = new ManagedDisposableObject();
            var children = new ManagedDisposableObject[]
            {
                new ManagedDisposableObject(),
                new ManagedDisposableObject(),
                new ManagedDisposableObject(),
                new ManagedDisposableObject(),
                new ManagedDisposableObject(),
                new ManagedDisposableObject(),
            };

            this.manager.Register(parent);
            foreach (ManagedDisposableObject child in children)
            {
                this.manager.RegisterAsDependent(child, parent);
            }

            parent.Dispose();
            foreach (ManagedDisposableObject child in children)
            {
                Assert.IsTrue(child.WasDisposed);
            }
        }
        public void VerifyParentIsNotDisposedWhenChildIsDisposed()
        {
            var parent = new ManagedDisposableObject();
            var child = new ManagedDisposableObject();

            this.manager.Register(parent);
            this.manager.RegisterAsDependent(child, parent);

            child.Dispose();
            Assert.IsFalse(parent.WasDisposed);
        }
 public void VerifyManagedDisposableObjectDisposeSetsWasDisposedToTrue()
 {
     var object1 = new ManagedDisposableObject();
     object1.Dispose();
     Assert.IsTrue(object1.WasDisposed);
 }
        public void VerifyChildObjectIsDisposedWhenParentIsDisposed()
        {
            var parent = new ManagedDisposableObject();
            var child = new ManagedDisposableObject();

            this.manager.Register(parent);
            this.manager.RegisterAsDependent(child, parent);

            parent.Dispose();
            Assert.IsTrue(child.WasDisposed);
        }