コード例 #1
0
ファイル: Time.cs プロジェクト: tiba666/WurmAssistant3
        public StubScope CreateStubbedScope()
        {
            lock (syncLocker)
            {
                if (CurrentScope != null)
                {
                    throw new InvalidOperationException("Another scope is already active, dispose of it first.");
                }
                else
                {
                    CurrentScope = new StubScope(this);
                }

                return(CurrentScope);
            }
        }
コード例 #2
0
ファイル: Time.cs プロジェクト: imtheman/WurmApi
        public StubScope CreateStubbedScope()
        {
            lock (syncLocker)
            {
                if (CurrentScope != null)
                {
                    throw new InvalidOperationException("Another scope is already active, dispose of it first.");
                }
                else
                {
                    CurrentScope = new StubScope(this);
                }

                return CurrentScope;
            }
        }
コード例 #3
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);
        }
コード例 #4
0
 public void CurrentRetreivesScope()
 {
     using (StubScope scope = new StubScope(ScopeBounds.Thread, ScopeNesting.Prohibited))
     {
         Assert.AreEqual(scope, StubScope.Current);
     }
 }
コード例 #5
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));
            }
        }
コード例 #6
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);
        }
コード例 #7
0
 public void ScopeAvailableInOtherMethods()
 {
     using (StubScope scope = new StubScope(ScopeBounds.Thread, ScopeNesting.Allowed))
     {
         AssertCurrentScopeIsNotNull();
     }
 }
コード例 #8
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);
     }
 }
コード例 #9
0
 public void UndefinedNestingValues()
 {
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         using (StubScope scope = new StubScope(ScopeBounds.Thread, (ScopeNesting)73))
         {
         }
     });
 }
コード例 #10
0
 public void UndefinedBoundsValues()
 {
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         using (StubScope scope = new StubScope((ScopeBounds)73, ScopeNesting.Prohibited))
         {
         }
     });
 }