Ejemplo n.º 1
0
        internal Structure.Options TestOptions(
            Func <AppFunc, AppFunc> responseMiddleware = null,
            Action <Structure.Options> more            = null)
        {
            var testOptions = new Structure.Options
            {
                Factories =
                {
                    HttpClient = options => HttpClientSimulator(options, ConsulKvSimulator, responseMiddleware)
                },
                Events =
                {
                    KeyDiscovered      = (keypath,                  property) => DiscoveredKeys[keypath] = property,
                    KeyValuesesIgnored = (kvs) =>
                    {
                        foreach (var kv in kvs)
                        {
                            IgnoredKeys[kv.Key] = kv.Value;
                        }
                    },
                    KeyValuesAssigned = KeyValuesAssigned.Enqueue,
                    HttpError         = HttpErrors.Enqueue,
                    HttpSuccess       = (request,                  response, duration) =>
                    {
                        HttpSuccesses.Enqueue(Tuple.Create(request, response, duration));
                    }
                }
            };

            more?.Invoke(testOptions);
            return(testOptions);
        }
        static HttpClient Response(Structure.Options options, Func <IOwinContext, Task> response)
        {
            var appFunc = new AppBuilder()
                          .Use((env, next) => response(env))
                          .Build();

            return(new HttpClient(new OwinClientHandler(appFunc))
            {
                BaseAddress = options.ConsulUri
            });
        }
Ejemplo n.º 3
0
        static HttpClient HttpClientSimulator(
            Structure.Options options,
            ConsulKvSimulator kvSimulator,
            Func <AppFunc, AppFunc> interceptor)
        {
            Func <IOwinContext, Task> invoker = kvSimulator.Invoke;

            if (interceptor != null)
            {
                invoker = interceptor(invoker);
            }

            var appFunc = new AppBuilder()
                          .Use((env, next) => invoker(env))
                          .Build();

            return(new HttpClient(new OwinClientHandler(appFunc))
            {
                BaseAddress = options.ConsulUri
            });
        }