internal static HttpMessageHandler GetPrimaryHttpMessageHandler(this HttpHandlerBuilder httpHandlerBuilder, ILogHandler logHandler) { var innerHandler = httpHandlerBuilder.Build(); return(_primaryHandlerFactory?.Invoke(innerHandler, logHandler) ?? innerHandler); }
private static async Task <FakeLogger> ExecuteFakeRequest(HttpMessageParts?verbosity = null) { var logger = new FakeLogger(); var httpClientHandler = new HttpClientHandler(); httpClientHandler.UseCookies = true; httpClientHandler.CookieContainer.Add(new Cookie(CookieName, CookieValue, "", new Uri(_testUri).Host)); var builder = new HttpHandlerBuilder(new FakeHttpTraceHandler(httpClientHandler, logger)); builder.AddHandler(new FakeHandler()) .AddHandler(new SillyHandler()) .AddHandler(new FakeHandler()); if (verbosity != null) { builder.SetHttpTracerVerbosity(verbosity.Value); } var client = new HttpClient(builder.Build()); await client.GetAsync(_testUri); return(logger); }
private static async Task <FakeLogger> ExecuteFakeRequest(HttpMessageParts?verbosity = null, JsonFormatting jsonFormatting = JsonFormatting.None, string responseContent = FakeHttpTraceHandler.FakeResponseContent) { var logger = new FakeLogger(); var httpClientHandler = new HttpClientHandler(); httpClientHandler.UseCookies = true; httpClientHandler.CookieContainer.Add(new Cookie(CookieName, CookieValue, "", new Uri(TestUri).Host)); HttpContent fakeContent = new StringContent("{\"Foo\": \"Bar\"}", Encoding.Default, "application/json"); var builder = new HttpHandlerBuilder(new FakeHttpTraceHandler(httpClientHandler, logger) { ResponseContent = responseContent, JsonFormatting = jsonFormatting }); builder.AddHandler(new FakeHandler()) .AddHandler(new SillyHandler()) .AddHandler(new FakeHandler()); if (verbosity != null) { builder.SetHttpTracerVerbosity(verbosity.Value); } var client = new HttpClient(builder.Build()); await client.PostAsync(TestUri, fakeContent); return(logger); }
public static void MapExpressController(this IEndpointRouteBuilder routes) { var assembly = Assembly.GetCallingAssembly(); var baseType = typeof(ControllerBase); var types = assembly.GetTypes(); foreach (var type in types) { if (type.IsAssignableTo(baseType)) { HttpHandlerBuilder.Build(type, routes); } } }
public async Task ShouldLogWithBuilder() { var logger = new TestLogger(); var builder = new HttpHandlerBuilder(new FakeHttpTraceHandler(logger)); builder.AddHandler(new MyHandler3()) .AddHandler(new MyHandler1()) .AddHandler(new MyHandler3()); var client = new HttpClient(builder.Build()); var result = await client.GetAsync("https://uinames.com/api?ext&amount=25"); Assert.AreEqual(2, logger.LogHistory.Count); }
public void MakeSureHierarchyIsBuiltWithCorrectType() { var builder = new HttpHandlerBuilder(); builder.AddHandler(new MyHandler3()) .AddHandler(new MyHandler1()) .AddHandler(new MyHandler3()); var first = builder.Build(); var second = ((DelegatingHandler)first).InnerHandler; var third = ((DelegatingHandler)second).InnerHandler; var fourth = ((DelegatingHandler)third).InnerHandler; Assert.IsInstanceOfType(first, typeof(MyHandler3)); Assert.IsInstanceOfType(second, typeof(MyHandler1)); Assert.IsInstanceOfType(third, typeof(MyHandler3)); Assert.IsInstanceOfType(fourth, typeof(HttpTracerHandler)); }
public void MakeSureHierarchyIsBuilt() { var builder = new HttpHandlerBuilder(); builder.AddHandler(new MyHandler3()) .AddHandler(new MyHandler1()) .AddHandler(new MyHandler3()); var httpHandler = builder.Build(); var first = ((DelegatingHandler)httpHandler).InnerHandler; var second = ((DelegatingHandler)first).InnerHandler; var third = ((DelegatingHandler)second).InnerHandler; var fourth = ((DelegatingHandler)third).InnerHandler; Assert.IsNotNull(first); Assert.IsNotNull(second); Assert.IsNotNull(third); Assert.IsNotNull(fourth); }
private static async Task <FakeLogger> ExecuteFakeRequest(HttpMessageParts?verbosity = null) { var logger = new FakeLogger(); var builder = new HttpHandlerBuilder(new FakeHttpTraceHandler(logger)); builder.AddHandler(new FakeHandler()) .AddHandler(new SillyHandler()) .AddHandler(new FakeHandler()); if (verbosity != null) { builder.SetHttpTracerVerbosity(verbosity.Value); } var client = new HttpClient(builder.Build()); await client.GetAsync(_testUri); return(logger); }
public static void MapDynamicHttpHandler <THttpHandler>(this IEndpointRouteBuilder builder) { HttpHandlerBuilder.Build <THttpHandler>(builder); }