Provides a wrapper over IDisposable that invokes the provided delegate when IDisposable.Dispose() is called.
Inheritance: IDisposable
 public void ActionIsExecutedOnDisposeMethodCall()
 {
     bool actionExecuted = false;
     IDisposable disposable = new ActionOnDispose(() => actionExecuted = true);
     Assert.False(actionExecuted);
     disposable.Dispose();
     Assert.True(actionExecuted);
 }
        public void ActionIsExecutedOnDisposeMethodCall()
        {
            bool        actionExecuted = false;
            IDisposable disposable     = new ActionOnDispose(() => actionExecuted = true);

            Assert.IsFalse(actionExecuted);
            disposable.Dispose();
            Assert.IsTrue(actionExecuted);
        }
        public void ActionIsExecutedPostUsing()
        {
            bool actionExecuted = false;
            using (IDisposable disposable = new ActionOnDispose(() => actionExecuted = true))
            {
                Assert.False(actionExecuted);
            }

            Assert.True(actionExecuted);
        }
        public void ActionIsExecutedPostUsing()
        {
            bool actionExecuted = false;

            using (IDisposable disposable = new ActionOnDispose(() => actionExecuted = true))
            {
                Assert.IsFalse(actionExecuted);
            }

            Assert.IsTrue(actionExecuted);
        }
        public void ActionIsExecutedOnceWhenDisposeIsCalledTwice()
        {
            bool actionExecuted = false;
            IDisposable disposable = new ActionOnDispose(() => actionExecuted = true);
            Assert.False(actionExecuted);
            disposable.Dispose();
            Assert.True(actionExecuted);

            // the action should only fire the first time
            actionExecuted = false;
            disposable.Dispose();
            Assert.False(actionExecuted);
        }
        public void ActionIsExecutedOnceWhenDisposeIsCalledTwice()
        {
            bool        actionExecuted = false;
            IDisposable disposable     = new ActionOnDispose(() => actionExecuted = true);

            Assert.IsFalse(actionExecuted);
            disposable.Dispose();
            Assert.IsTrue(actionExecuted);

            // the action should only fire the first time
            actionExecuted = false;
            disposable.Dispose();
            Assert.IsFalse(actionExecuted);
        }