public InternalContextCookie(DefaultTestContextTracker contextTracker, InternalContextLink previousTopLink) { this.contextTracker = contextTracker; this.previousTopLink = previousTopLink; threadId = Thread.CurrentThread.ManagedThreadId; }
/// <inheritdoc /> public IDisposable EnterContext(ITestContext context) { InternalContextLink previousTopLink = TopContextLinkForCurrentThread; TopContextLinkForCurrentThread = new InternalContextLink(previousTopLink, context); return(new InternalContextCookie(this, previousTopLink)); }
private ITestContext GetCurrentContextImpl() { InternalContextLink contextLink = TopContextLinkForCurrentThread; if (contextLink != null) { return(contextLink.Context); } return(GetThreadDefaultContextImpl(Thread.CurrentThread)); }
private void ExitContext(InternalContextLink previousTopLink, int threadId) { if (Thread.CurrentThread.ManagedThreadId != threadId) { throw new InvalidOperationException("The context cookie does not belong to this thread."); } InternalContextLink currentLink = TopContextLinkForCurrentThread; while (currentLink != null) { currentLink = currentLink.ParentLink; if (currentLink == previousTopLink) { TopContextLinkForCurrentThread = currentLink; return; } } throw new InvalidOperationException("The context has already been exited."); }
public InternalContextLink(InternalContextLink parentLink, ITestContext context) { this.parentLink = parentLink; this.context = context; }
private void ExitContext(InternalContextLink previousTopLink, int threadId) { if (Thread.CurrentThread.ManagedThreadId != threadId) throw new InvalidOperationException("The context cookie does not belong to this thread."); InternalContextLink currentLink = TopContextLinkForCurrentThread; while (currentLink != null) { currentLink = currentLink.ParentLink; if (currentLink == previousTopLink) { TopContextLinkForCurrentThread = currentLink; return; } } throw new InvalidOperationException("The context has already been exited."); }
/// <inheritdoc /> public IDisposable EnterContext(ITestContext context) { InternalContextLink previousTopLink = TopContextLinkForCurrentThread; TopContextLinkForCurrentThread = new InternalContextLink(previousTopLink, context); return new InternalContextCookie(this, previousTopLink); }