Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        public void WhenScopeIsDisposedCreateScopeThrows()
        {
            var disposable = new Disposable();
            var scope      = new Scoped <Disposable>(disposable);

            scope.Dispose();

            scope.Invoking(s => s.CreateLifetime()).Should().Throw <ObjectDisposedException>();
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
 /// <inheritdoc />
 public void Dispose()
 {
     _scope.Dispose();
 }