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); }
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()); }