public void Test_ApplicationHost_HttpClientMultiple() { var builder = new AppHostBuilder(); // Configure the application host. var processHost = builder .AddHealthProbe("886") .AddHttpClient(new Dictionary <string, Uri> { { "test1", new Uri("http://localhost:886") }, { "test2", new Uri("http://test2.com") }, { "test3", new Uri("http://test3.com") } }) .AddHostedProcess <BackgroundTimerService>() .Build(); var httpClient = ((AppHost)processHost)._serviceProvider.GetService <IHttpClientFactory>(); Assert.NotNull(httpClient); var client = httpClient.CreateClient("test1"); client.Timeout = TimeSpan.FromSeconds(1); try { client.GetAsync("doesnotexist").GetAwaiter().GetResult(); } catch (Exception) { } }
public void Test_ApplicationHost_HttpClientSingle() { // Arrange var builder = new AppHostBuilder(); // Act - Configure the application host. var processHost = builder .AddHealthProbe("884") .AddHttpClient("test", "http://localhost:884") .ConfigureServices((config, logger, serviceBuilder) => serviceBuilder.AddHostedProcess(new SimpleService(new SampleDependency()))) .AddHostedProcess <BackgroundTimerService>() .Build(); var httpClient = ((AppHost)processHost)._serviceProvider.GetService <IHttpClientFactory>(); Assert.NotNull(httpClient); var client = httpClient.CreateClient("test"); client.Timeout = TimeSpan.FromSeconds(1); try { client.GetAsync("doesnotexist").GetAwaiter().GetResult(); } catch (Exception) { } }
public void Test_ApplicationHost_HttpClientTyped() { var builder = new AppHostBuilder(); // Configure the application host. var processHost = builder .AddHealthProbe("885") .AddHttpClientTyped <HttpClientDependencyTest>("test", "http://a.com:885") .AddHostedProcess <BackgroundTimerService>() .Build(); var httpClient = ((AppHost)processHost)._serviceProvider.GetService <HttpClientDependencyTest>(); httpClient.Client.Timeout = TimeSpan.FromSeconds(1); Assert.NotNull(httpClient); try { httpClient.RetryExample(); } catch (Exception) { } }