public void ReplaceIfNull() { var bd1 = new BooleanDisposable(); var bd2 = new BooleanDisposable(); var field = default(IDisposable); Assert.True(DisposableHelper.ReplaceIfNull(ref field, bd1)); Assert.False(bd1.IsDisposed()); Assert.False(bd2.IsDisposed()); Assert.False(DisposableHelper.ReplaceIfNull(ref field, bd2)); Assert.False(bd1.IsDisposed()); Assert.False(bd2.IsDisposed()); Assert.True(DisposableHelper.Dispose(ref field)); Assert.True(bd1.IsDisposed()); Assert.False(bd2.IsDisposed()); var bd3 = new BooleanDisposable(); Assert.False(DisposableHelper.SetIfNull(ref field, bd3)); Assert.True(bd3.IsDisposed()); }
public void SetIfNull_Null() { try { var field = default(IDisposable); DisposableHelper.SetIfNull(ref field, null); Assert.Fail("Should have thrown"); } catch (ArgumentNullException) { // expected } }