public void AsyncLocalScopeManager_Activate_ReturnsAsyncLocalScope()
        {
            var span = NSubstitute.Substitute.For <ISpan>();

            AsyncLocalScopeManager scopeManager = new AsyncLocalScopeManager();
            var scope = scopeManager.Activate(span, true);

            Assert.IsInstanceOfType(scope, typeof(AsyncLocalScope));
        }
        public void DefaultActivate()
        {
            ISpan span = Substitute.For <ISpan>();

            using (IScope scope = _source.Activate(span, finishSpanOnDispose: false))
            {
                Assert.NotNull(scope);
                IScope otherScope = _source.Active;
                Assert.Same(otherScope, scope);
            }

            // Make sure the span is not finished.
            span.DidNotReceive().Finish();

            // And now it's gone:
            IScope missingScope = _source.Active;

            Assert.Null(missingScope);
        }
        public void AsyncLocalScopeManager_Active_ReturnsInput()
        {
            var span = NSubstitute.Substitute.For <ISpan>();

            AsyncLocalScopeManager scopeManager = new AsyncLocalScopeManager();

            scopeManager.Activate(span, true);

            var active = scopeManager.Active.Span;

            Assert.AreSame(span, active);
        }
Esempio n. 4
0
        public void ImplicitSpanStack()
        {
            ISpan backgroundSpan = Substitute.For <ISpan>();
            ISpan foregroundSpan = Substitute.For <ISpan>();

            using (IScope backgroundActive = _scopeManager.Activate(backgroundSpan, finishSpanOnDispose: true))
            {
                Assert.NotNull(backgroundActive);

                // Activate a new Scope on top of the background one.
                using (IScope foregroundActive = _scopeManager.Activate(foregroundSpan, finishSpanOnDispose: true))
                {
                    IScope shouldBeForeground = _scopeManager.Active;
                    Assert.Same(foregroundActive, shouldBeForeground);
                }

                // And now the backgroundActive should be reinstated.
                IScope shouldBeBackground = _scopeManager.Active;
                Assert.Same(backgroundActive, shouldBeBackground);
            }

            // The background and foreground spans should be finished.
            backgroundSpan.Received(1).Finish();
            foregroundSpan.Received(1).Finish();

            // And now nothing is active.
            IScope missingSpan = _scopeManager.Active;

            Assert.Null(missingSpan);
        }