public void Should_throw_exception_when_disposed() { var sut = new MyDisposableObject(); sut.Dispose(); Assert.Throws <ObjectDisposedException>(() => sut.Ensure()); }
public void GivenExistingKey_ThrowsArgumentException() { var existingKey = _sut.Keys.ElementAt(0); var newValue = new MyDisposableObject(); Action action = () => _sut.Add(existingKey, newValue, true); action.Should().Throw <ArgumentException>(); }
public void Should_dispose_once() { var sut = new MyDisposableObject(); sut.Dispose(); sut.Dispose(); Assert.True(sut.IsDisposed); Assert.Equal(1, sut.DisposeCallCount); }
public void DisposingParentDisposesChild() { UnityContainer parent = new UnityContainer(); IUnityContainer child = parent.CreateChildContainer(); MyDisposableObject spy = new MyDisposableObject(); child.RegisterInstance(spy); parent.Dispose(); Assert.IsTrue(spy.WasDisposed); }
public void WhenItemIsRemovedThatIsMarkedForDisposal_AlsoRemovesThatMark() { var disposableValue = new MyDisposableObject(); _sut.Add("D1", disposableValue, true); _sut.Disposables.Should().BeEquivalentTo(expectation: new[] { disposableValue }); _sut.Remove("D1"); _sut.Disposables.Should().BeEmpty(); _sut.Add("D1", disposableValue, false); _sut.Disposables.Should().BeEquivalentTo(Enumerable.Empty <IDisposable>()); _sut.Remove("D1"); _sut.Disposables.Should().BeEquivalentTo(Enumerable.Empty <IDisposable>()); }
public void GivenNewDisposableItem_AddsItemToDictionary() { var newKey = "newKey"; var newValue = new MyDisposableObject(); _sut.Add(newKey, newValue, true); var expectedItems = new[] { new KeyValuePair <string, object>("A", 1), new KeyValuePair <string, object>("B", 2), new KeyValuePair <string, object>(newKey, newValue) }; var actualItems = (ICollection <KeyValuePair <string, object> >)_sut; actualItems.Should().BeEquivalentTo(expectedItems); }
public void CanDisposeChildWithoutDisposingParent() { MyDisposableObject parentSpy = new MyDisposableObject(); MyDisposableObject childSpy = new MyDisposableObject(); UnityContainer parent = new UnityContainer(); parent.RegisterInstance(parentSpy); IUnityContainer child = parent.CreateChildContainer() .RegisterInstance(childSpy); child.Dispose(); Assert.IsFalse(parentSpy.WasDisposed); Assert.IsTrue(childSpy.WasDisposed); childSpy.WasDisposed = false; parent.Dispose(); Assert.IsTrue(parentSpy.WasDisposed); Assert.IsFalse(childSpy.WasDisposed); }
public void Run() { //var obj = new MyDisposableObject(); //try //{ // throw new Exception("exception in using"); //} //finally //{ // obj.Dispose(); //} using (var obj = new MyDisposableObject()) { throw new Exception("exception in using"); Console.WriteLine("in using block"); } Console.WriteLine("out using block"); }
public void Should_not_throw_exception_when_not_disposed() { var sut = new MyDisposableObject(); sut.Ensure(); }