protected IntegrationTestBase() { CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("en-US"); CultureInfo.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); var path = Environment.GetEnvironmentVariable("deltaKustoSingleExecPath"); _executablePath = string.IsNullOrWhiteSpace(path) ? null : path; if (_executablePath != null) { if (!File.Exists(_executablePath)) { throw new DeltaException( $"Executable file doesn't exist at '{_executablePath}' ; " + $"current directory is: {Directory.GetCurrentDirectory()}"); } } Tracer = new ConsoleTracer(false); HttpClientFactory = new SimpleHttpClientFactory(Tracer); }
public void CreateClient_UriRelative_Throws() { var configs = new Dictionary <string, ClientConfig>() { { "Bob", new ClientConfig { BaseAddress = "/test/", Policies = null, RequestHeaders = null } } }; var logger = new Mock <ILogger>(MockBehavior.Loose); var factory = new SimpleHttpClientFactory(configs, logger.Object); bool platformException = false; try { factory.CreateClient("Bob"); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) when(e is ArgumentException || e is UriFormatException) #pragma warning restore CA1031 // Do not catch general exception types { platformException = true; } // When running dotnet test on Windows and Linux, different exceptions are encountered Assert.IsTrue(platformException, "The platform specific exception was encountered"); }
public void Constructor_NullLogger_Throws() { var configs = new Dictionary <string, ClientConfig>(); Assert.ThrowsException <ArgumentNullException>( () => _ = new SimpleHttpClientFactory(configs, null)); }
public void CreateClient_UriAbsolute_InitializedHeaderValues_Succeeds() { var headers = new Dictionary <string, string> { { "header1", "test1" }, { "header2", "test2" } }; var configs = new Dictionary <string, ClientConfig> { { "Bob", new ClientConfig { BaseAddress = "http://test.com/", Policies = null, RequestHeaders = headers } } }; var logger = new Mock <ILogger>(MockBehavior.Loose); var factory = new SimpleHttpClientFactory(configs, logger.Object); HttpClient client = factory.CreateClient("Bob"); Assert.IsNotNull(client); Assert.AreEqual("http://test.com/", client.BaseAddress.ToString()); Assert.AreEqual(2, client.DefaultRequestHeaders.Count()); client.Dispose(); }
public void Constructor_NullClientConfigs_Throws() { var logger = new Mock <ILogger>(MockBehavior.Loose); Assert.ThrowsException <ArgumentNullException>( () => _ = new SimpleHttpClientFactory(null, logger.Object)); }
public void CreateClient_NameNotRegistered_Throws() { var logger = new Mock <ILogger>(MockBehavior.Loose); var configs = new Dictionary <string, ClientConfig>(); var factory = new SimpleHttpClientFactory(configs, logger.Object); Assert.ThrowsException <ArgumentException>( () => factory.CreateClient("Missing")); }
public void Constructor_EmptyClientConfigs_Succeeds() { var configs = new Dictionary <string, ClientConfig>(); var logger = new Mock <ILogger>(MockBehavior.Loose); var factory = new SimpleHttpClientFactory(configs, logger.Object); Assert.IsNotNull(factory); }
public void CreateClient_EmptyConfig_Throws() { var configs = new Dictionary <string, ClientConfig>() { { "Bob", new ClientConfig() } }; var logger = new Mock <ILogger>(MockBehavior.Loose); var factory = new SimpleHttpClientFactory(configs, logger.Object); Assert.ThrowsException <ArgumentNullException>( () => factory.CreateClient("Bob")); }
public void CreateClient_UriEmpty_Throws() { var configs = new Dictionary <string, ClientConfig>() { { "Bob", new ClientConfig { BaseAddress = string.Empty, Policies = null, RequestHeaders = null } } }; var logger = new Mock <ILogger>(MockBehavior.Loose); var factory = new SimpleHttpClientFactory(configs, logger.Object); Assert.ThrowsException <UriFormatException>( () => factory.CreateClient("Bob")); }
private static AdxDbTestHelper CreateSingleton() { var dbPrefix = Environment.GetEnvironmentVariable("deltaKustoDbPrefix"); var clusterUri = Environment.GetEnvironmentVariable("deltaKustoClusterUri"); var tenantId = Environment.GetEnvironmentVariable("deltaKustoTenantId"); var servicePrincipalId = Environment.GetEnvironmentVariable("deltaKustoSpId"); var servicePrincipalSecret = Environment.GetEnvironmentVariable("deltaKustoSpSecret"); if (string.IsNullOrWhiteSpace(tenantId)) { throw new ArgumentNullException(nameof(tenantId)); } if (string.IsNullOrWhiteSpace(servicePrincipalId)) { throw new ArgumentNullException(nameof(servicePrincipalId)); } if (string.IsNullOrWhiteSpace(servicePrincipalSecret)) { throw new ArgumentNullException(nameof(servicePrincipalSecret)); } if (string.IsNullOrWhiteSpace(clusterUri)) { throw new ArgumentNullException(nameof(clusterUri)); } if (string.IsNullOrWhiteSpace(dbPrefix)) { throw new ArgumentNullException(nameof(dbPrefix)); } var tracer = new ConsoleTracer(false); var httpClientFactory = new SimpleHttpClientFactory(tracer); var tokenParameterization = new TokenProviderParameterization { Login = new ServicePrincipalLoginParameterization { TenantId = tenantId, ClientId = servicePrincipalId, Secret = servicePrincipalSecret } }; var kustoGatewayFactory = new KustoManagementGatewayFactory(tokenParameterization, tracer); var helper = new AdxDbTestHelper( dbPrefix, db => kustoGatewayFactory.CreateGateway(new Uri(clusterUri), db)); return(helper); }
public ApiClient(ITracer tracer, SimpleHttpClientFactory httpClientFactory) { _tracer = tracer; _httpClientFactory = httpClientFactory; }