Exemple #1
0
        public static OpenHttpServer CreateAndRun()
        {
            var currentPort = DefaultPort;

            while (true)
            {
                OpenHttpServer server = null;
                try
                {
                    server = new OpenHttpServer();

                    var baseAddress = new Uri($"http://localhost:{currentPort}");
                    // ReSharper disable once AccessToDisposedClosure
                    var webHost = WebHost.Start(baseAddress.ToString(), ctx => server.Handler(ctx));

                    server.Host        = webHost;
                    server.BaseAddress = baseAddress;

                    return(server);
                }
                catch (IOException ex)
                {
                    server?.Dispose();

                    if (!(ex.InnerException is AddressInUseException))
                    {
                        throw;
                    }
                }

                currentPort++;
            }
        }
 public OpenHttpServerTests()
 {
     _httpServer = OpenHttpServer.CreateAndRun();
     _client     = _httpServer.CreateClient();
 }