示例#1
0
        public void RefCountDisposable_PrimaryDisposesFirst()
        {
            var d = new BooleanDisposable();
            var r = new RefCountDisposable(d);
            Assert.IsFalse(d.IsDisposed);

            var d1 = r.GetDisposable();
            var d2 = r.GetDisposable();
            Assert.IsFalse(d.IsDisposed);

            d1.Dispose();
            Assert.IsFalse(d.IsDisposed);

            r.Dispose();
            Assert.IsFalse(d.IsDisposed);

            d2.Dispose();
            Assert.IsTrue(d.IsDisposed);
        }
示例#2
0
        public void RefCountDisposable_RefCounting()
        {
            var d = new BooleanDisposable();
            var r = new RefCountDisposable(d);
            Assert.IsFalse(d.IsDisposed);

            var d1 = r.GetDisposable();
            var d2 = r.GetDisposable();
            Assert.IsFalse(d.IsDisposed);

            d1.Dispose();
            Assert.IsFalse(d.IsDisposed);

            d2.Dispose();
            Assert.IsFalse(d.IsDisposed); // CHECK

            r.Dispose();
            Assert.IsTrue(d.IsDisposed);

            var d3 = r.GetDisposable(); // CHECK
            d3.Dispose();
        }