Example #1
0
        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);
        }
Example #2
0
        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");
        }
Example #3
0
        public void Constructor_NullLogger_Throws()
        {
            var configs = new Dictionary <string, ClientConfig>();

            Assert.ThrowsException <ArgumentNullException>(
                () => _ = new SimpleHttpClientFactory(configs, null));
        }
Example #4
0
        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();
        }
Example #5
0
        public void Constructor_NullClientConfigs_Throws()
        {
            var logger = new Mock <ILogger>(MockBehavior.Loose);

            Assert.ThrowsException <ArgumentNullException>(
                () => _ = new SimpleHttpClientFactory(null, logger.Object));
        }
Example #6
0
        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"));
        }
Example #7
0
        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);
        }
Example #8
0
        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"));
        }
Example #9
0
        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"));
        }
Example #10
0
        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);
        }
Example #11
0
 public ApiClient(ITracer tracer, SimpleHttpClientFactory httpClientFactory)
 {
     _tracer            = tracer;
     _httpClientFactory = httpClientFactory;
 }