Ejemplo n.º 1
0
        private void WhenICallTheMiddlewareMultipleTimes(int times, Ocelot.DownstreamRouteFinder.DownstreamRouteHolder downstreamRoute)
        {
            var httpContexts = new List <HttpContext>();

            for (int i = 0; i < times; i++)
            {
                var httpContext = new DefaultHttpContext();
                httpContext.Response.Body = new FakeStream();
                httpContext.Items.UpsertDownstreamRoute(downstreamRoute.Route.DownstreamRoute[0]);
                httpContext.Items.UpsertTemplatePlaceholderNameAndValues(downstreamRoute.TemplatePlaceholderNameAndValues);
                httpContext.Items.UpsertDownstreamRoute(downstreamRoute);
                var clientId = "ocelotclient1";
                var request  = new HttpRequestMessage(new HttpMethod("GET"), _url);
                httpContext.Items.UpsertDownstreamRequest(new DownstreamRequest(request));
                httpContext.Request.Headers.TryAdd("ClientId", clientId);
                httpContexts.Add(httpContext);
            }

            foreach (var httpContext in httpContexts)
            {
                _middleware.Invoke(httpContext).GetAwaiter().GetResult();
                var ds = httpContext.Items.DownstreamResponse();
                _downstreamResponse = ds;
            }
        }
        private void WhenICallTheMiddlewareMultipleTime(int times)
        {
            var clientId = "ocelotclient1";

            for (int i = 0; i < times; i++)
            {
                var request = new HttpRequestMessage(new HttpMethod("GET"), _url);
                request.Headers.Add("ClientId", clientId);
                _downstreamContext.DownstreamRequest = new DownstreamRequest(request);

                _middleware.Invoke(_downstreamContext).GetAwaiter().GetResult();
                _responseStatusCode = (int)_downstreamContext.HttpContext.Response.StatusCode;
            }
        }