Exemplo n.º 1
0
        public void AutodisposablesAreOnlyDisposedOnce()
        {
            //---------------Set up test pack-------------------
            var disposable = Substitute.For<IDisposable>();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var ad = new AutoDisposer();
            ad.Add(disposable);
            ad.Dispose();
            ad.Dispose();

            //---------------Test Result -----------------------
            disposable.Received(1).Dispose();
        }
Exemplo n.º 2
0
        public void AutodisposablesAreOnlyDisposedOnce()
        {
            //---------------Set up test pack-------------------
            var disposable = Substitute.For <IDisposable>();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var ad = new AutoDisposer();

            ad.Add(disposable);
            ad.Dispose();
            ad.Dispose();

            //---------------Test Result -----------------------
            disposable.Received(1).Dispose();
        }
 public void Dispose()
 {
     lock (_lock)
     {
         _disposer?.Dispose();
         _disposer = null;
     }
 }
Exemplo n.º 4
0
        public void Add_GenericVersion_ShouldReturnThing()
        {
            //---------------Set up test pack-------------------
            var disposer = new AutoDisposer();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var thing = disposer.Add(new SomeDisposable());

            //---------------Test Result -----------------------
            Assert.IsInstanceOf <SomeDisposable>(thing);
            Assert.IsFalse(thing.Disposed);
            disposer.Dispose();
            Assert.IsTrue(thing.Disposed);
        }
Exemplo n.º 5
0
        public void Add_GenericVersion_ShouldReturnThing()
        {
            //---------------Set up test pack-------------------
            var disposer = new AutoDisposer();

            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            var thing = disposer.Add(new SomeDisposable());

            //---------------Test Result -----------------------
            Assert.IsInstanceOf<SomeDisposable>(thing);
            Assert.IsFalse(thing.Disposed);
            disposer.Dispose();
            Assert.IsTrue(thing.Disposed);
        }