public static HttpMessageHandlerStub Responds(
            this GetClause dsl,
            HttpResponseMessage response)
        {
            HttpMessageHandlerStub stub = dsl.Stub;

            stub.Configure(new HttpRequestHandler(dsl.CanHandle, response));
            return(stub);
        }
        public static HttpMessageHandlerStub Responds(
            this GetClause dsl,
            Func <HttpRequestMessage, Task <HttpResponseMessage> > handle)
        {
            HttpMessageHandlerStub stub = dsl.Stub;

            stub.Configure(new HttpRequestHandler(dsl.CanHandle, handle));
            return(stub);
        }
        public static HttpMessageHandlerStub RespondsJson(
            this GetClause dsl,
            object value)
        {
            HttpMessageHandlerStub stub     = dsl.Stub;
            HttpResponseMessage    response = CreateJsonResponse(value);

            stub.Configure(new HttpRequestHandler(dsl.CanHandle, response));
            return(stub);
        }
        public static GetClause WithAuthorization(
            this GetClause dsl,
            Func <AuthenticationHeaderValue, bool> predicate)
        {
            return(new GetClause(dsl.Stub, CanHandle));

            bool CanHandle(HttpRequestExcerpt request)
            => dsl.CanHandle.Invoke(request) &&
            predicate.Invoke(request.Headers.Authorization);
        }
        public static HttpMessageHandlerStub RespondsStream(
            this GetClause dsl,
            MediaTypeHeaderValue contentType,
            Stream content)
        {
            HttpMessageHandlerStub stub     = dsl.Stub;
            HttpResponseMessage    response = CreateStreamResponse(contentType, content);

            stub.Configure(new HttpRequestHandler(dsl.CanHandle, response));
            return(stub);
        }
        public static GetClause WithAuthorization(
            this GetClause dsl,
            string scheme,
            string parameter)
        {
            return(new GetClause(dsl.Stub, CanHandle));

            bool CanHandle(HttpRequestExcerpt request)
            => dsl.CanHandle.Invoke(request) &&
            request.Headers.Authorization != null &&
            request.Headers.Authorization.Scheme == scheme &&
            request.Headers.Authorization.Parameter == parameter;
        }
        public static HttpMessageHandlerStub RespondsJsonStream(
            this GetClause dsl,
            Stream content)
        {
            HttpMessageHandlerStub stub = dsl.Stub;
            var contentType             = new MediaTypeHeaderValue("application/json")
            {
                CharSet = "utf-8"
            };
            HttpResponseMessage response = CreateStreamResponse(contentType, content);

            stub.Configure(new HttpRequestHandler(dsl.CanHandle, response));
            return(stub);
        }