public void BeginScope_WithParentScope_ParentScopeHasInnerScopeAsChild()
 {
     var container = new ServiceContainer();
     var scopeManager = new PerThreadScopeManager(container);
     using (var outerScope = scopeManager.BeginScope())
     {
         using (var scope = scopeManager.BeginScope())
         {
             Assert.Same(scope, outerScope.ChildScope);
         }
     }
 }
        public void EndScope_BeforeInnerScopeHasCompleted_ThrowsException()
        {
            var container    = new ServiceContainer();
            var scopeManager = new PerThreadScopeManager(container);

            using (var outerScope = scopeManager.BeginScope())
            {
                using (var innerScope = scopeManager.BeginScope())
                {
                    Assert.Throws <InvalidOperationException>(() => outerScope.Dispose());
                }
            }
        }
        public void BeginScope_WithParentScope_ParentScopeHasInnerScopeAsChild()
        {
            var container    = new ServiceContainer();
            var scopeManager = new PerThreadScopeManager(container);

            using (var outerScope = scopeManager.BeginScope())
            {
                using (var scope = scopeManager.BeginScope())
                {
                    Assert.Same(scope, outerScope.ChildScope);
                }
            }
        }
Example #4
0
        public void EndScope_BeforeInnerScopeHasCompleted_DoesNotThrowException()
        {
            var container    = new ServiceContainer();
            var scopeManager = new PerThreadScopeManager(container);

            using (var outerScope = scopeManager.BeginScope())
            {
                using (var innerScope = scopeManager.BeginScope())
                {
                    outerScope.Dispose();
                }
            }
        }
        public void BeginScope_NoParentScope_ParentScopeIsNull()
        {
            var container    = new ServiceContainer();
            var scopeManager = new PerThreadScopeManager(container);

            using (var scope = scopeManager.BeginScope())
            {
                Assert.Null(scope.ParentScope);
            }
        }
 public void Dispose_WithTrackedInstances_DisposesTrackedInstances()
 {
     var container = new ServiceContainer();
     var scopeManager = new PerThreadScopeManager(container);
     var disposable = new DisposableFoo();
     Scope scope = scopeManager.BeginScope();
     scope.TrackInstance(disposable);
     scope.Dispose();
     Assert.True(disposable.IsDisposed);
 }
        public void BeginScope_NoParentScope_ParentScopeIsNull()
        {
            var container = new ServiceContainer();
            var scopeManager = new PerThreadScopeManager(container);

            using (var scope = scopeManager.BeginScope())
            {
                Assert.Null(scope.ParentScope);
            }
        }
        public void Dispose_WithTrackedInstances_DisposesTrackedInstances()
        {
            var   container    = new ServiceContainer();
            var   scopeManager = new PerThreadScopeManager(container);
            var   disposable   = new DisposableFoo();
            Scope scope        = scopeManager.BeginScope();

            scope.TrackInstance(disposable);
            scope.Dispose();
            Assert.True(disposable.IsDisposed);
        }
        public void EndScope_BeforeInnerScopeHasCompleted_ThrowsException()
        {
            var container = new ServiceContainer();
            var scopeManager = new PerThreadScopeManager(container);

            using (var outerScope = scopeManager.BeginScope())
            {
                using (var innerScope = scopeManager.BeginScope())
                {
                    Assert.Throws<InvalidOperationException>(() => outerScope.Dispose());
                }
            }
        }