Exemplo n.º 1
0
        public void Task_GetCurrentScope_NestedScope_Should_NotSame()
        {
            using (var scopeOuter = new AmbientScope())
            {
                var ambientScopeOuter = AmbientScope.Current;
                ambientScopeOuter.ShouldNotNull();
                ambientScopeOuter.ShouldSame(scopeOuter);
                using (var scope = new AmbientScope())
                {
                    var ambientScope = AmbientScope.Current;

                    ambientScope.ShouldNotNull();
                    ambientScope.ShouldSame(scope);
                    ambientScopeOuter.ShouldNotSame(scope);

                    Task.Run(() =>
                    {
                        var ambientScope2 = AmbientScope.Current;
                        ambientScope2.ShouldNotNull();
                        ambientScope2.ShouldSame(scope);
                        ambientScope2.ShouldSame(ambientScope);
                        ambientScopeOuter.ShouldNotSame(ambientScope2);
                    }).Wait();
                }
            }
        }
Exemplo n.º 2
0
        public void Thread_GetCurrentScope_NestedScope_Should_NotSame()
        {
            using (var scopeOuter = new AmbientScope())
            {
                var ambientScopeOuter = AmbientScope.Current;
                ambientScopeOuter.ShouldNotNull();
                ambientScopeOuter.ShouldSame(scopeOuter);
                using (var scope = new AmbientScope())
                {
                    var ambientScope = AmbientScope.Current;

                    ambientScope.ShouldNotNull();
                    ambientScope.ShouldSame(scope);
                    ambientScopeOuter.ShouldNotSame(scope);

                    var thread = new Thread(() =>
                    {
                        var ambientScope2 = AmbientScope.Current;
                        ambientScope2.ShouldNotNull();
                        ambientScope2.ShouldSame(scope);
                        ambientScope2.ShouldSame(ambientScope);
                        ambientScopeOuter.ShouldNotSame(ambientScope2);
                    });
                    thread.Start();
                    thread.Join();
                }
            }
        }
Exemplo n.º 3
0
        public void GetCurrentScope_InSameScope_Should_Same()
        {
            using (var scope = new AmbientScope())
            {
                var ambientScope = AmbientScope.Current;

                ambientScope.ShouldNotNull();
                ambientScope.ShouldSame(scope);

                var ambientScope2 = AmbientScope.Current;
                ambientScope2.ShouldNotNull();
                ambientScope2.ShouldSame(scope);
                ambientScope2.ShouldSame(ambientScope);
            }
        }
Exemplo n.º 4
0
        public void Task_GetCurrentScope_SameScope_Should_Same()
        {
            using (var scope = new AmbientScope())
            {
                var ambientScope = AmbientScope.Current;

                ambientScope.ShouldNotNull();
                ambientScope.ShouldSame(scope);

                Task.Run(() =>
                {
                    var ambientScope2 = AmbientScope.Current;
                    ambientScope2.ShouldNotNull();
                    ambientScope2.ShouldSame(scope);
                    ambientScope2.ShouldSame(ambientScope);
                }).Wait();
            }
        }
Exemplo n.º 5
0
        public void GetCurrentScope_NestedScope_Should_NotSame()
        {
            using (var scopeOuter = new AmbientScope())
            {
                var ambientScopeOuter = AmbientScope.Current;
                ambientScopeOuter.ShouldNotNull();
                ambientScopeOuter.ShouldSame(scopeOuter);

                using (var scope = new AmbientScope())
                {
                    var ambientScope = AmbientScope.Current;

                    ambientScope.ShouldNotNull();
                    ambientScope.ShouldSame(scope);

                    var ambientScope2 = AmbientScope.Current;
                    ambientScope2.ShouldNotNull();
                    ambientScope2.ShouldSame(scope);
                    ambientScope2.ShouldSame(ambientScope);

                    ambientScopeOuter.ShouldNotSame(scope);
                }
            }
        }