Пример #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();
                }
            }
        }
Пример #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();
                }
            }
        }
Пример #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);
            }
        }
Пример #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();
            }
        }
Пример #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);
                }
            }
        }