Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Petr Komissarov committed Mar 26, 2024
1 parent 58c2181 commit bf757d4
Showing 1 changed file with 62 additions and 60 deletions.
122 changes: 62 additions & 60 deletions TmsRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,72 +91,74 @@ private static IHostBuilder CreateHostBuilder(string[] args)
outputTemplate:
"{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.Console(LogEventLevel.Information))
.ConfigureServices((_, services) =>
.ConfigureServices((hostContext, services) =>
{
_ = (HostBuilderContext)services.AddHttpClient(nameof(HttpClientNames.Default), client =>
{
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;
client.DefaultRequestVersion = HttpVersion.Version11;
})
.SetHandlerLifetime(TimeSpan.FromMinutes(20))
.AddPolicyHandler(GetRetryPolicy());

_ = (HostBuilderContext)services
.AddSingleton(GetAdapterConfiguration(args))
.AddSingleton(provider =>
services.AddHttpClient(nameof(HttpClientNames.Default), client =>
{
var adapterConfig = provider.GetRequiredService<AdapterConfig>();

return ConfigurationManager.Configure(
adapterConfig.ToInternalConfig(),
Path.GetDirectoryName(adapterConfig.TestAssemblyPath) ?? string.Empty
);
client.DefaultVersionPolicy = HttpVersionPolicy.RequestVersionOrHigher;
client.DefaultRequestVersion = HttpVersion.Version11;
})
.AddSingleton(provider =>
{
var tmsSettings = provider.GetRequiredService<TmsSettings>();
.SetHandlerLifetime(TimeSpan.FromMinutes(20))
.AddPolicyHandler(GetRetryPolicy());

return new TestIT.ApiClient.Client.Configuration
services
.AddSingleton(GetAdapterConfiguration(args))
.AddSingleton(provider =>
{
BasePath = tmsSettings.Url ?? string.Empty,
ApiKeyPrefix = new Dictionary<string, string> { { "Authorization", "PrivateToken" } },
ApiKey = new Dictionary<string, string> { { "Authorization", tmsSettings?.PrivateToken ?? string.Empty } }
};
})
.AddTransient(provider => new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (_, _, _, _) => provider.GetRequiredService<TmsSettings>().CertValidation
})
.AddTransient<IAttachmentsApiAsync, AttachmentsApi>(provider => new AttachmentsApi(
provider.GetRequiredService<IHttpClientFactory>().CreateClient(nameof(HttpClientNames.Default)),
provider.GetRequiredService<TestIT.ApiClient.Client.Configuration>(),
provider.GetRequiredService<HttpClientHandler>()
))
.AddTransient<ITestRunsApiAsync, TestRunsApi>(provider => new TestRunsApi(
provider.GetRequiredService<IHttpClientFactory>().CreateClient(nameof(HttpClientNames.Default)),
provider.GetRequiredService<TestIT.ApiClient.Client.Configuration>(),
provider.GetRequiredService<HttpClientHandler>()
))
.AddTransient<IAutoTestsApiAsync, AutoTestsApi>(provider => new AutoTestsApi(
provider.GetRequiredService<IHttpClientFactory>().CreateClient(nameof(HttpClientNames.Default)),
provider.GetRequiredService<TestIT.ApiClient.Client.Configuration>(),
provider.GetRequiredService<HttpClientHandler>()
))
.AddTransient<App>()
.AddTransient<ITmsClient, TmsClient>()
.AddTransient<Replacer>()
.AddTransient<Reflector>()
.AddTransient<LogParser>()
.AddTransient<FilterService>()
.AddTransient<ProcessorService>()
.AddTransient(provider => new AutoResetEvent(false))
.AddTransient<DiscoveryEventHandler>()
.AddTransient<RunEventHandler>()
.AddTransient<IVsTestConsoleWrapper, VsTestConsoleWrapper>(provider => new VsTestConsoleWrapper(
provider.GetRequiredService<AdapterConfig>().RunnerPath ?? string.Empty,
new ConsoleParameters { LogFilePath = Path.Combine(Directory.GetCurrentDirectory(), @"log.txt") }
))
.AddSingleton<Runner>();
var adapterConfig = provider.GetRequiredService<AdapterConfig>();

return ConfigurationManager.Configure(
adapterConfig.ToInternalConfig(),
Path.GetDirectoryName(adapterConfig.TestAssemblyPath) ?? string.Empty
);
})
.AddSingleton(provider =>
{
var tmsSettings = provider.GetRequiredService<TmsSettings>();

return new TestIT.ApiClient.Client.Configuration
{
BasePath = tmsSettings.Url ?? string.Empty,
ApiKeyPrefix = new Dictionary<string, string> { { "Authorization", "PrivateToken" } },
ApiKey = new Dictionary<string, string> { { "Authorization", tmsSettings?.PrivateToken ?? string.Empty } }
};
})
.AddTransient(provider => new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (_, _, _, _) => provider.GetRequiredService<TmsSettings>().CertValidation
})
.AddTransient<IAttachmentsApiAsync, AttachmentsApi>(provider => new AttachmentsApi(
provider.GetRequiredService<IHttpClientFactory>().CreateClient(nameof(HttpClientNames.Default)),
provider.GetRequiredService<TestIT.ApiClient.Client.Configuration>(),
provider.GetRequiredService<HttpClientHandler>()
))
.AddTransient<ITestRunsApiAsync, TestRunsApi>(provider => new TestRunsApi(
provider.GetRequiredService<IHttpClientFactory>().CreateClient(nameof(HttpClientNames.Default)),
provider.GetRequiredService<TestIT.ApiClient.Client.Configuration>(),
provider.GetRequiredService<HttpClientHandler>()
))
.AddTransient<IAutoTestsApiAsync, AutoTestsApi>(provider => new AutoTestsApi(
provider.GetRequiredService<IHttpClientFactory>().CreateClient(nameof(HttpClientNames.Default)),
provider.GetRequiredService<TestIT.ApiClient.Client.Configuration>(),
provider.GetRequiredService<HttpClientHandler>()
))
.AddTransient<App>()
.AddTransient<ITmsClient, TmsClient>()
.AddTransient<Replacer>()
.AddTransient<Reflector>()
.AddTransient<LogParser>()
.AddTransient<FilterService>()
.AddTransient<ProcessorService>()
.AddTransient(provider => new AutoResetEvent(false))
.AddTransient<DiscoveryEventHandler>()
.AddTransient<RunEventHandler>()
.AddTransient<IVsTestConsoleWrapper, VsTestConsoleWrapper>(provider => new VsTestConsoleWrapper(
provider.GetRequiredService<AdapterConfig>().RunnerPath ?? string.Empty,
new ConsoleParameters { LogFilePath = Path.Combine(Directory.GetCurrentDirectory(), @"log.txt") }
))
.AddSingleton<Runner>();
}
});
}

Expand Down

0 comments on commit bf757d4

Please sign in to comment.