Based on everything I read, the following testing method should pass. I am trying to understand why he is failing. The first statement in the private asynchronous method passes as expected. However, as soon as the task returns and waits. The value that was set in the CallContext is now null on recovery.
[TestMethod] public void LogicalCallContextBlockingTest() { PerformSimpleAsyncWork().Wait(); var result = CallContext.LogicalGetData("test"); Assert.AreEqual(result, "expected"); } private async Task PerformSimpleAsyncWork() { await Task.Run(() => { System.Threading.Thread.Sleep(100); CallContext.LogicalSetData("test", "expected"); var result = CallContext.LogicalGetData("test"); Assert.AreEqual(result, "expected"); }); }
source share