public void WhenScopeIsCreatedThenScopeDisposedLifetimeDisposesValue() { var disposable = new Disposable(); var scope = new Scoped <Disposable>(disposable); var lifetime = scope.CreateLifetime(); scope.Dispose(); scope.Dispose(); // validate double dispose is still single ref count disposable.IsDisposed.Should().BeFalse(); lifetime.Dispose(); disposable.IsDisposed.Should().BeTrue(); }
public void WhenScopeIsDisposedCreateScopeThrows() { var disposable = new Disposable(); var scope = new Scoped <Disposable>(disposable); scope.Dispose(); scope.Invoking(s => s.CreateLifetime()).Should().Throw <ObjectDisposedException>(); }
public void ExitAction_Is_Called_On_Dispose() { // Arrange var wasCalled = false; // Act using (var scope = new Scoped(exitAction: () => wasCalled = true)) { wasCalled.Should().BeFalse("exitAction should not be called until Dispose() is called."); scope.Dispose(); // Assert wasCalled.Should().BeTrue(); } }
public void BeginScope_GetInstance_DisposeScope() { //ARRANGE var container = new Container(builder => { builder.Register <IDisposable, Disposable>(c => c .With(Lifetime.PerScope) .WithFinalizer(x => x.Dispose())); }); //ACT Scoped scope = container.BeginScope(); var disposable = (Disposable)scope.GetInstance <IDisposable>(); bool isDisposedBefore = disposable.IsDisposed; scope.Dispose(); bool isDisposedAfter = disposable.IsDisposed; //ASSERT Assert.False(isDisposedBefore); container.Dispose(); Assert.True(isDisposedAfter); }
/// <inheritdoc /> public void Dispose() { _scope.Dispose(); }