public void Activate_AfterDisposal_ShouldThrow()
        {
            using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.NoNesting, noNestingIgnoresDefaultScope: true);
            scope.Dispose();

            Assert.ThrowsAny <InvalidOperationException>(() => scope.Activate());
        }
        public void Deactivate_FromDisposedState_ShouldThrow()
        {
            using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.ForceCreateNew);
            scope.Dispose();

            Assert.Throws <InvalidOperationException>(() => scope.Deactivate());
        }
        public void Activate_Regularly_ShouldRegisterAmbientScope()
        {
            using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.NoNesting, noNestingIgnoresDefaultScope: true);
            scope.Activate();

            Assert.Equal(scope, ManuallyActivatedScope.CurrentNondefault);
        }
        public void Dispose_FromStateNew_ShouldResultInStateDisposed()
        {
            using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.ForceCreateNew);

            scope.Dispose();

            Assert.Equal(AmbientScopeState.Disposed, scope.State);
        }
        public void Activate_Regularly_ShouldResultInStateActive()
        {
            using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.ForceCreateNew);

            scope.Activate();

            Assert.Equal(AmbientScopeState.Active, scope.State);
        }
        public void Deactivate_FromActivateState_ShouldResultInStateNew()
        {
            using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.ForceCreateNew);
            scope.Activate();

            scope.Deactivate();

            Assert.Equal(AmbientScopeState.New, scope.State);
        }
        public void GetEffectiveRootScope_WithNoNesting_ShouldReturnSelf()
        {
            using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.NoNesting, noNestingIgnoresDefaultScope: true);
            scope.Activate();

            var parent = scope.GetEffectiveRootScope();

            Assert.Equal(scope, parent);
        }
        public void EffectiveParentScope_WithNoNesting_ShouldReturnNull()
        {
            using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.NoNesting, noNestingIgnoresDefaultScope: true);
            scope.Activate();

            var parent = scope.EffectiveParentScope;

            Assert.Null(parent);
        }
        public void Deactivate_WithPotentialParentScope_ShouldResultInNonNullParents()
        {
            using var outerScope = new ManuallyActivatedScope(1, AmbientScopeOption.ForceCreateNew);
            using var innerScope = new ManuallyActivatedScope(1, AmbientScopeOption.JoinExisting);

            outerScope.Activate();
            innerScope.Activate();

            Assert.NotNull(innerScope.PhysicalParentScope);
            Assert.NotNull(innerScope.EffectiveParentScope);
        }
        public void GetEffectiveRootScope_WithJoinExistingAndNoNestingUnderlyingScope_ShouldReturnUnderlyingScope()
        {
            using var underlyingScope = new ManuallyActivatedScope(1, AmbientScopeOption.NoNesting, noNestingIgnoresDefaultScope: true);
            underlyingScope.Activate();

            using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.JoinExisting);
            scope.Activate();

            var parent = scope.GetEffectiveRootScope();

            Assert.Equal(underlyingScope, parent);
        }
 public void Construct_Regularly_ShouldResultInStateNew()
 {
     using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.ForceCreateNew);
     Assert.Equal(AmbientScopeState.New, scope.State);
 }
 public void Construct_Regularly_ShouldNotRegisterAmbientScope()
 {
     using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.NoNesting);
     Assert.Null(ManuallyActivatedScope.CurrentNondefault);
 }
 public void Activate_WithJoinExistingAndDefaultScope_ShouldSucceed()
 {
     using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.JoinExisting);
     scope.Activate();
 }
 public void Activate_WithForceCreateNewAndDefaultScope_ShouldSucceed()
 {
     using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.ForceCreateNew);
     scope.Activate();
 }
 public void Activate_WithNoNestingAndDefaultScope_ShouldThrow()
 {
     using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.NoNesting);
     Assert.ThrowsAny <InvalidOperationException>(() => scope.Activate());
 }
 public void Activate_WithNoNestingAndIgnoredDefaultScope_ShouldSucceed()
 {
     using var scope = new ManuallyActivatedScope(1, AmbientScopeOption.NoNesting, noNestingIgnoresDefaultScope: true);
     scope.Activate();
 }