Esempio n. 1
0
 public void ScopeAvailableInOtherMethods()
 {
     using (StubScope scope = new StubScope(ScopeBounds.Thread, ScopeNesting.Allowed))
     {
         AssertCurrentScopeIsNotNull();
     }
 }
Esempio n. 2
0
 public void CurrentRetreivesScope()
 {
     using (StubScope scope = new StubScope(ScopeBounds.Thread, ScopeNesting.Prohibited))
     {
         Assert.AreEqual(scope, StubScope.Current);
     }
 }
Esempio n. 3
0
 public void CurrentRetreivesNestedScope()
 {
     using (StubScope scope = new StubScope(ScopeBounds.Thread, ScopeNesting.Allowed))
         using (StubScope scope2 = new StubScope(ScopeBounds.Thread, ScopeNesting.Allowed))
         {
             Assert.AreEqual(scope2, StubScope.Current);
         }
 }
Esempio n. 4
0
 public void UndefinedNestingValues()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         using (StubScope scope = new StubScope(ScopeBounds.Thread, (ScopeNesting)73))
         {
         }
     });
 }
Esempio n. 5
0
 public void UndefinedBoundsValues()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         using (StubScope scope = new StubScope((ScopeBounds)73, ScopeNesting.Prohibited))
         {
         }
     });
 }
Esempio n. 6
0
        public void Dispose_ViaDisposedNestedScope_DoesNotChangeCurrent()
        {
            using (var parent = new StubScope(ScopeBounds.Thread, ScopeNesting.Allowed))
                using (var child = new StubScope(ScopeBounds.Thread, ScopeNesting.Allowed))
                {
                    child.Dispose();
                    Assert.IsTrue(object.ReferenceEquals(parent, StubScope.Current));

                    child.Dispose();
                    Assert.IsTrue(object.ReferenceEquals(parent, StubScope.Current));
                }
        }
Esempio n. 7
0
        public void ThreadBoundScopeNotAvailableOnAnotherThread()
        {
            bool isAvailable = true;

            Action assertCurrentScopeIsNull = delegate()
            {
                isAvailable = StubScope.Current != null;
            };

            using (StubScope scope = new StubScope(ScopeBounds.Thread, ScopeNesting.Prohibited))
            {
                IAsyncResult result = assertCurrentScopeIsNull.BeginInvoke(null, null);

                result.AsyncWaitHandle.WaitOne();
                assertCurrentScopeIsNull.EndInvoke(result);
            }

            Assert.IsFalse(isAvailable);
        }
Esempio n. 8
0
        public void AppDomainBoundScopeIsAvailableOnAnotherThread_WhenNestingAllowed()
        {
            bool isAvailable = false;

            Action assertCurrentScopeIsNull = delegate()
            {
                isAvailable = StubScope.Current != null;
            };

            using (StubScope scope = new StubScope(ScopeBounds.AppDomain, ScopeNesting.Allowed))
            {
                IAsyncResult result = assertCurrentScopeIsNull.BeginInvoke(null, null);

                result.AsyncWaitHandle.WaitOne();
                assertCurrentScopeIsNull.EndInvoke(result);
            }

            Assert.IsTrue(isAvailable);
        }