コード例 #1
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>, with an OK (200) status code
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="content">The content of the response</param>
 public static void Respond(this MockedRequest source, HttpContent content)
 {
     source.Respond(HttpStatusCode.OK, content);
 }
コード例 #2
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="message">The complete <see cref="T:HttpResponseMessage"/> to return</param>
 public static void Respond(this MockedRequest source, HttpResponseMessage message)
 {
     source.Respond(_ => TaskEx.FromResult(message));
 }
コード例 #3
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="statusCode">The <see cref="T:HttpStatusCode"/> of the response</param>
 public static void Respond(this MockedRequest source, HttpStatusCode statusCode)
 {
     source.Respond(new HttpResponseMessage(statusCode));
 }
コード例 #4
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>, with an OK (200) status code
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="content">The content of the response</param>
 public static MockedRequest Respond(this MockedRequest source, HttpContent content)
 {
     return(source.Respond(HttpStatusCode.OK, content));
 }
コード例 #5
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="handler">The delegate that will return a <see cref="T:HttpContent"/> determined at runtime</param>
 public static void Respond(this MockedRequest source, Func <HttpRequestMessage, HttpContent> handler)
 {
     source.Respond(HttpStatusCode.OK, handler);
 }
コード例 #6
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="handler">The delegate that will return a <see cref="T:HttpResponseMessage"/> determined at runtime</param>
 public static void Respond(this MockedRequest source, Func <HttpRequestMessage, HttpResponseMessage> handler)
 {
     source.Respond(req => TaskEx.FromResult(handler(req)));
 }
コード例 #7
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/> to defer to another <see cref="T:HttpMessageListener"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="handler">The <see cref="T:HttpMessageHandlert"/> that will handle requests</param>
 public static void Respond(this MockedRequest source, HttpMessageHandler handler)
 {
     source.Respond(new HttpClient(handler));
 }
コード例 #8
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="statusCode">The <see cref="T:HttpStatusCode"/> of the response</param>
 /// <param name="handler">The delegate that will return a <see cref="T:HttpContent"/> determined at runtime</param>
 public static MockedRequest Respond(this MockedRequest source, HttpStatusCode statusCode, Func <HttpRequestMessage, HttpContent> handler)
 {
     return(source.Respond(statusCode, Enumerable.Empty <KeyValuePair <string, string> >(), handler));
 }
コード例 #9
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/> to defer to another <see cref="T:HttpClient"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="httpClient">The <see cref="T:HttpClient"/> that will handle requests</param>
 public static MockedRequest Respond(this MockedRequest source, HttpClient httpClient)
 {
     return(source.Respond(req => httpClient.SendAsync(CloneRequest(req))));
 }
コード例 #10
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>, with an OK (200) status code
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="headers">A list of HTTP header name/value pairs to add to the response.</param>
 /// <param name="content">The content of the response</param>
 /// <param name="mediaType">The media type of the response</param>
 public static MockedRequest Respond(this MockedRequest source, IEnumerable <KeyValuePair <string, string> > headers, string mediaType, Stream content)
 {
     return(source.Respond(HttpStatusCode.OK, headers, mediaType, content));
 }
コード例 #11
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="headers">A list of HTTP header name/value pairs to add to the response.</param>
 /// <param name="handler">The delegate that will return a <see cref="T:HttpContent"/> determined at runtime</param>
 public static MockedRequest Respond(this MockedRequest source, IEnumerable <KeyValuePair <string, string> > headers, Func <HttpRequestMessage, HttpContent> handler)
 {
     return(source.Respond(HttpStatusCode.OK, headers, handler));
 }
コード例 #12
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="statusCode">The <see cref="T:HttpStatusCode"/> of the response</param>
 /// <param name="content">The content of the response</param>
 /// <param name="mediaType">The media type of the response</param>
 public static MockedRequest Respond(this MockedRequest source, HttpStatusCode statusCode, string mediaType, Stream content)
 {
     return(source.Respond(statusCode, Enumerable.Empty <KeyValuePair <string, string> >(), mediaType, content));
 }
コード例 #13
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>, with an OK (200) status code
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="content">The content of the response</param>
 /// <param name="mediaType">The media type of the response</param>
 public static MockedRequest Respond(this MockedRequest source, string mediaType, string content)
 {
     return(source.Respond(HttpStatusCode.OK, mediaType, content));
 }
コード例 #14
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="statusCode">The <see cref="T:HttpStatusCode"/> of the response</param>
 /// <param name="headers">A list of HTTP header name/value pairs to add to the response.</param>
 /// <param name="mediaType">The media type of the response</param>
 /// <param name="content">The content of the response</param>
 public static MockedRequest Respond(this MockedRequest source, HttpStatusCode statusCode, IEnumerable <KeyValuePair <string, string> > headers, string mediaType, string content)
 {
     return(source.Respond(statusCode, headers, _ => new StringContent(content, Encoding.UTF8, mediaType)));
 }
コード例 #15
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="statusCode">The <see cref="T:HttpStatusCode"/> of the response</param>
 /// <param name="content">The content of the response</param>
 /// <param name="mediaType">The media type of the response</param>
 public static void Respond(this MockedRequest source, HttpStatusCode statusCode, string mediaType, string content)
 {
     source.Respond(statusCode, new StringContent(content, Encoding.UTF8, mediaType));
 }
コード例 #16
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/> to defer to another <see cref="T:HttpMessageListener"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="handler">The <see cref="T:HttpMessageHandlert"/> that will handle requests</param>
 public static MockedRequest Respond(this MockedRequest source, HttpMessageHandler handler)
 {
     return(source.Respond(new HttpClient(handler)));
 }
コード例 #17
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>, with an OK (200) status code
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="content">The content of the response</param>
 /// <param name="mediaType">The media type of the response</param>
 public static void Respond(this MockedRequest source, string mediaType, Stream content)
 {
     source.Respond(HttpStatusCode.OK, mediaType, content);
 }
コード例 #18
0
 /// <summary>
 /// Creates a new instance of MockHttpMessageHandler
 /// </summary>
 public MockHttpMessageHandler()
 {
     AutoFlush = true;
     fallback  = new MockedRequest();
     fallback.Respond(fallbackResponse = CreateDefaultFallbackMessage());
 }
コード例 #19
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/> to defer to another <see cref="T:HttpClient"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="httpClient">The <see cref="T:HttpClient"/> that will handle requests</param>
 public static void Respond(this MockedRequest source, HttpClient httpClient)
 {
     source.Respond(req => httpClient.SendAsync(req));
 }
コード例 #20
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="mediaType">The media type of the response</param>
 /// <param name="handler">A delegate that will return a content stream at runtime</param>
 public static void Respond(this MockedRequest source, string mediaType, Func <HttpRequestMessage, Stream> handler)
 {
     source.Respond(HttpStatusCode.OK, mediaType, handler);
 }
コード例 #21
0
 /// <summary>
 /// Creates a new instance of MockHttpMessageHandler
 /// </summary>
 public MockHttpMessageHandler()
 {
     AutoFlush = true;
     fallback = new MockedRequest();
     fallback.Respond(fallbackResponse = CreateDefaultFallbackMessage());
 }
コード例 #22
0
 /// <summary>
 /// Sets the response of the current <see cref="T:MockedRequest"/>
 /// </summary>
 /// <param name="source">The source mocked request</param>
 /// <param name="statusCode">The <see cref="T:HttpStatusCode"/> of the response</param>
 public static MockedRequest Respond(this MockedRequest source, HttpStatusCode statusCode)
 {
     return(source.Respond(req => new HttpResponseMessage(statusCode)));
 }