using NUnit.Framework; namespace Developpez.Dotnet.Tests { [TestFixture] public class DisposableActionTests { [Test] public void Test_ActionIsExecutedOnDispose() { bool executed = false; using (new DisposableAction(() => executed = true)) { } Assert.IsTrue(executed); } [Test] public void Test_ActionIsExecutedOnlyOnce() { bool executed = false; var d = new DisposableAction(() => executed = true); d.Dispose(); Assert.IsTrue(executed); executed = false; d.Dispose(); Assert.IsFalse(executed); } } }