protected HttpClient GetClient()
        {
            int    randomPort    = RandomNumberHelper.NextIntegerInRange(5120, 6144);
            string httpServerUrl = String.Format("http://*:{0}", randomPort);

            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseContentRoot(Directory.GetCurrentDirectory())
                       .UseStartup <Startup>()
                       .UseUrls(httpServerUrl)
                       .Build();

            host.Start();

            Thread.Sleep(3000);

            var client = new HttpClient {
                BaseAddress = new Uri(httpServerUrl)
            };

            client.DefaultRequestHeaders.Accept.Clear();
            // Client always expects JSON results
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            // TODO: Switch over to using the RestSharp client
            return(client);
        }
Пример #2
0
        protected RestClient GetClient()
        {
            int    randomPort    = RandomNumberHelper.NextIntegerInRange(5120, 8191);
            string httpServerUrl = String.Format("http://*:{0}", randomPort);
            string httpClientUrl = String.Format("http://localhost:{0}", randomPort);

            _host = new WebHostBuilder()
                    .UseKestrel()
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseStartup <Startup>()
                    .UseUrls(httpServerUrl)
                    .Build();

            _host.Start();

            Thread.Sleep(3000);

            return(new RestClient(httpClientUrl));
        }