Пример #1
0
 public ReadonlyApiClientTests(ITestOutputHelper output,
                               ApiLauncherFactory <TStartup> factory)
 {
     Output       = output;
     ApiClient    = TestApiClientFactory.CreateReadonlyClient <TClient, TStartup>(factory);
     InstanceName = ApiClient.GetInstanceName();
 }
 public WriteableApiClientTests(ITestOutputHelper output,
                                ApiLauncherFactory <TStartup> fixture,
                                string testUser = "******")
 {
     Output       = output;
     ApiClient    = TestApiClientFactory.CreateWriteableClient <TClient, TStartup>(fixture, testUser);
     HttpClient   = ApiClient.HttpClient;
     InstanceName = ApiClient.GetInstanceName();
 }
Пример #3
0
        public static TClient CreateWriteableClient <TClient, TStartup>(
            ApiLauncherFactory <TStartup> factory, string testUser = TestRepoFactory.DEFAULT_USER)
            where TClient : ApiClient
            where TStartup : class
        {
            var httpClient = HttpClientFactory.Create();

            var port        = factory.Port;
            var baseAddress = $"http://localhost:{port}";

            var baseAddressConfig = new List <KeyValuePair <string, string> >();
            var clientName        = typeof(TClient).Name;

            baseAddressConfig.Add(new KeyValuePair <string, string>($"Apis:{clientName}:BaseAddress", baseAddress));

            var apiConfiguration = new ConfigurationBuilder()
                                   .AddInMemoryCollection(baseAddressConfig)
                                   .Build();

            var instanceName    = Guid.NewGuid().ToString();
            var scopeProperties = new ScopeProperties {
                User = testUser
            };

            var apiClientHeaders = new List <KeyValuePair <string, StringValues> > {
                new KeyValuePair <string, StringValues>(
                    Interceptor.HDR_USE_INMEMORY, instanceName)
            };

            var dict = new Dictionary <string, object> {
                { Web.ApiClient.HEADER_KEY, apiClientHeaders }
            };

            scopeProperties.OtherProperties.Add(
                typeof(TClient).Name, dict);


            var apiClient = Activator.CreateInstance(typeof(TClient),
                                                     httpClient, apiConfiguration, scopeProperties
                                                     ) as TClient;


            bool ping = httpClient.Ping(TIMEOUT_SECONDS);

            if (ping == false)
            {
                ping = httpClient.Ping(TIMEOUT_SECONDS);
            }

            return(apiClient);
        }