public void Create_DisposableOnceAction() { var n = 0; var src = new DisposableOnceAction(() => n++, e => n--); Assert.That(src.IgnoreTwice, Is.True); Assert.That(src.Invoked, Is.False); Assert.That(src.Disposed, Is.False); src.Invoke(); Assert.That(src.Invoked, Is.True); Assert.That(n, Is.EqualTo(1)); src.Invoke(); // ignore Assert.That(n, Is.EqualTo(1)); src.IgnoreTwice = false; Assert.That(() => src.Invoke(), Throws.TypeOf <TwiceException>()); Assert.That(n, Is.EqualTo(1)); src.Dispose(); Assert.That(src.Disposed, Is.True); Assert.That(n, Is.EqualTo(0)); src.Dispose(); // ignore src.IgnoreTwice = true; Assert.That(() => src.Invoke(), Throws.TypeOf <ObjectDisposedException>()); }
public void Create_Null() { var n = 0; using (var src = new DisposableOnceAction(() => ++ n, null)) { src.Invoke(); src.Invoke(); } Assert.That(n, Is.EqualTo(1)); }