Ejemplo n.º 1
0
 public void ActionIsExecutedOnDisposeMethodCall()
 {
     bool actionExecuted = false;
     IDisposable disposable = new ActionOnDispose(() => actionExecuted = true);
     Assert.False(actionExecuted);
     disposable.Dispose();
     Assert.True(actionExecuted);
 }
Ejemplo n.º 2
0
        public void ActionIsExecutedPostUsing()
        {
            bool actionExecuted = false;
            using (IDisposable disposable = new ActionOnDispose(() => actionExecuted = true))
            {
                Assert.False(actionExecuted);
            }

            Assert.True(actionExecuted);
        }
Ejemplo n.º 3
0
        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);
        }