Ejemplo n.º 1
0
 public void ScopeAvailableInOtherMethods()
 {
     using (StubScope scope = new StubScope(ScopeBounds.Thread, ScopeNesting.Allowed))
     {
         AssertCurrentScopeIsNotNull();
     }
 }
Ejemplo n.º 2
0
 public void CurrentRetreivesScope()
 {
     using (StubScope scope = new StubScope(ScopeBounds.Thread, ScopeNesting.Prohibited))
     {
         Assert.AreEqual(scope, StubScope.Current);
     }
 }
Ejemplo 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);
         }
 }
Ejemplo n.º 4
0
 public void UndefinedNestingValues()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         using (StubScope scope = new StubScope(ScopeBounds.Thread, (ScopeNesting)73))
         {
         }
     });
 }
Ejemplo n.º 5
0
 public void UndefinedBoundsValues()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         using (StubScope scope = new StubScope((ScopeBounds)73, ScopeNesting.Prohibited))
         {
         }
     });
 }
Ejemplo 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));
                }
        }
Ejemplo 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);
        }
Ejemplo 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);
        }