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