public void FinalizeMethod() { var state = TestDisposable.CreateFinalizable(); Finalizer.RunUntil(() => state.IsDisposed); state.IsFinalized.Should().BeTrue(); }
public void IsDisposed_True() { var obj = new TestDisposable(); obj.Dispose(); obj.IsDisposed.Should().BeTrue(); }
public void RequireNotDisposed_Throw() { var obj = new TestDisposable(); obj.Dispose(); obj.Invoking(o => o.RequireNotDisposed()) .Should().Throw <ObjectDisposedException>(); }
public void AddDisposable_Disposed() { var objA = new TestDisposable(); var pool = new DisposablePool(); pool.Dispose(); pool.Invoking(p => p.AddDisposable(objA)) .Should().Throw <ObjectDisposedException>(); }
private (WeakReference, WeakReference) AddGarbageToPool(DisposablePool pool) { var objA = new TestDisposable(); var objB = new TestDisposable(); pool.AddDisposable(objA); pool.AddDisposable(objB); return(new WeakReference(objA), new WeakReference(objB)); }
public void Take_Disposed() { var obj = new TestDisposable(); var box = new DisposableBox <TestDisposable>(); box.Dispose(); box.Invoking(b => b.Take()) .Should().Throw <ObjectDisposedException>(); }
public void Set_Disposed() { var obj = new TestDisposable(); var box = new DisposableBox <TestDisposable>(); box.Dispose(); box.Invoking(b => b.Set(obj, owned: false)) .Should().Throw <ObjectDisposedException>(); }
public void Dispose() { var obj = new TestDisposable(); var state = obj.DisposalState; state.IsDisposed.Should().BeFalse(); obj.Dispose(); state.IsDisposed.Should().BeTrue(); state.IsFinalized.Should().BeFalse(); }
public void Construct_NotOwned() { var obj = new TestDisposable(); using (var box = new DisposableBox <TestDisposable>(obj, owned: false)) { box.Object.Should().BeSameAs(obj); box.IsOwned.Should().BeFalse(); } obj.IsDisposed.Should().BeFalse(); }
public void Dispose_NotOwned() { var obj = new TestDisposable(); var box = new DisposableBox <TestDisposable>(obj, owned: false); box.Dispose(); box.Invoking(b => { var _ = b.Object; }).Should().Throw <ObjectDisposedException>(); box.Invoking(b => { var _ = b.IsOwned; }).Should().Throw <ObjectDisposedException>(); obj.IsDisposed.Should().BeFalse(); }
public void AddDisposable_ThenDispose() { var objA = new TestDisposable(); var objB = new TestDisposable(); var pool = new DisposablePool(); pool.AddDisposable(objA).Should().BeSameAs(objA); pool.AddDisposable(objB).Should().BeSameAs(objB); pool.Dispose(); objA.IsDisposed.Should().BeTrue(); objB.IsDisposed.Should().BeTrue(); }
public void Dispose_Owned_Twice() { var obj = new TestDisposable(); var box = new DisposableBox <TestDisposable>(obj); box.Dispose(); box.Dispose(); box.Invoking(b => { var _ = b.Object; }).Should().Throw <ObjectDisposedException>(); box.Invoking(b => { var _ = b.IsOwned; }).Should().Throw <ObjectDisposedException>(); obj.IsDisposed.Should().BeTrue(); }
public void Clear_Owned() { var obj = new TestDisposable(); using (var box = new DisposableBox <TestDisposable>(obj)) { box.Clear(); obj.IsDisposed.Should().BeTrue(); box.Object.Should().BeNull(); box.IsOwned.Should().BeFalse(); // null can't be owned } }
public void Set_NotOwnedToNull() { var obj = new TestDisposable(); using (var box = new DisposableBox <TestDisposable>(obj, owned: false)) { box.Set(null); obj.IsDisposed.Should().BeFalse(); box.Object.Should().BeNull(); box.IsOwned.Should().BeFalse(); // null can't be owned } }
public void AddDisposable_ThenFinalize() { var objA = new TestDisposable(); var objB = new TestDisposable(); var pool = new DisposablePool(); pool.AddDisposable(objA).Should().BeSameAs(objA); pool.AddDisposable(objB).Should().BeSameAs(objB); pool.DisposeUnmanaged(); // simulate finalizer // Does not dispose managed resources during finalization objA.IsDisposed.Should().BeFalse(); objB.IsDisposed.Should().BeFalse(); }
public void Take_NotOwned() { var obj = new TestDisposable(); using (var box = new DisposableBox <TestDisposable>(obj, owned: false)) { box.Take().Should().BeSameAs(obj); obj.IsDisposed.Should().BeFalse(); box.Object.Should().BeNull(); box.IsOwned.Should().BeFalse(); // null can't be owned } obj.IsDisposed.Should().BeFalse(); }
public void Set_NullToOwned() { var obj = new TestDisposable(); using (var box = new DisposableBox <TestDisposable>()) { box.Set(obj); obj.IsDisposed.Should().BeFalse(); box.Object.Should().BeSameAs(obj); box.IsOwned.Should().BeTrue(); } obj.IsDisposed.Should().BeTrue(); }
public void Set_OwnedToDifferentNotOwned() { var objA = new TestDisposable(); var objB = new TestDisposable(); using (var box = new DisposableBox <TestDisposable>(objA)) { box.Set(objB, owned: false); objA.IsDisposed.Should().BeTrue(); objB.IsDisposed.Should().BeFalse(); box.Object.Should().BeSameAs(objB); box.IsOwned.Should().BeFalse(); } objB.IsDisposed.Should().BeFalse(); }
public static DisposalState CreateFinalizable() { var obj = new TestDisposable(); return(obj.DisposalState); }
public void IsDisposed_False() { var obj = new TestDisposable(); obj.IsDisposed.Should().BeFalse(); }
public void RequireNotDisposed_Ok() { var obj = new TestDisposable(); obj.RequireNotDisposed(); }