コード例 #1
0
        public void GetHttpContext_CustomServerCallContext_Error()
        {
            var serverCallContext = new TestServerCallContext(DateTime.MinValue, CancellationToken.None);

            var ex = Assert.Throws <InvalidOperationException>(() => serverCallContext.GetHttpContext()) !;

            Assert.AreEqual("Could not get HttpContext from ServerCallContext. HttpContext can only be accessed when gRPC services are hosted by ASP.NET Core.", ex.Message);
        }
コード例 #2
0
        public void GetHttpContext_CustomServerCallContextWithContextInUserState_Success()
        {
            var httpContext = new DefaultHttpContext();

            var serverCallContext = new TestServerCallContext(DateTime.MinValue, CancellationToken.None);

            serverCallContext.UserState[ServerCallContextExtensions.HttpContextKey] = httpContext;

            Assert.AreEqual(httpContext, serverCallContext.GetHttpContext());
        }