Beispiel #1
0
        public void ExecutionContextOnSetupThread(ExecutionContextFlow flow)
        {
            ResetExecutionContextFlowForTestThread();

            CallContext.LogicalSetData("test.data", "test.value");
            var server = new ServerBuilder()
                         .SetEndPoint(new IPEndPoint(IPAddress.Loopback, 8082))
                         .SetExecutionContextFlow(flow)
                         .SetRetrySocketBindingTime(System.TimeSpan.FromSeconds(4))
                         .Build();

            server.Start();
            server.Dispose();
            Assert.Equal(
                "test.value",
                CallContext.LogicalGetData("test.data") as string);
        }
Beispiel #2
0
        public void ExecutionContextFlowFromSetupThread(ExecutionContextFlow flow, string expectedLogicalContextValue)
        {
            ResetExecutionContextFlowForTestThread();

            CallContext.LogicalSetData("test.data", "test.value");

            var server = new ServerBuilder()
                         .SetEndPoint(new IPEndPoint(IPAddress.Loopback, 8082))
                         .SetExecutionContextFlow(flow)
                         .SetRetrySocketBindingTime(System.TimeSpan.FromSeconds(4))
                         .Build();

            server.Start();
            server.Dispose();


            var separateThreadValue = Task.Factory.StartNew(() => CallContext.LogicalGetData("test.data") as string);

            //Assert.True(ExecutionContext.IsFlowSuppressed());
            Assert.Equal(expectedLogicalContextValue, separateThreadValue.Result);
        }
Beispiel #3
0
        public void ExecutionContextFlowToOwinApp(ExecutionContextFlow flow, string expectedValue)
        {
            ResetExecutionContextFlowForTestThread();

            string applicationValue = null;

            CallContext.LogicalSetData("test.data", "test.value");

            var server = new ServerBuilder()
                         .SetEndPoint(new IPEndPoint(IPAddress.Loopback, 8082))
                         .SetExecutionContextFlow(flow)
                         .SetOwinApp(env => AppReadingLogicalCallContext(out applicationValue))
                         .SetRetrySocketBindingTime(System.TimeSpan.FromSeconds(4))
                         .Build();

            server.Start();
            using (var httpClient = new HttpClient())
            {
                var response = httpClient.GetAsync("http://localhost:8082").Result;
            }
            server.Dispose();

            Assert.Equal(expectedValue, applicationValue);
        }