public async Task When_responding_with_custom_media_type_formatter_it_should_return_content_formatted_with_formatter()
        {
            var responseContent = new MyXmlSerializableType
            {
                Name = "John Doe"
            };
            var request = new HttpRequestMessage();
            var xmlMediaTypeFormatter = new XmlMediaTypeFormatter();

            // Act
            _sut.RespondObject(responseContent, xmlMediaTypeFormatter);
            HttpResponseMessage actualResponse = await _httpClient.SendAsync(request, CancellationToken.None);

            // Assert
            await actualResponse.Should().HaveContentAsync("<RootElem xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\"><Name>John Doe</Name></RootElem>");
        }
Exemplo n.º 2
0
 /// <summary>
 /// Specifies the <see cref="HttpStatusCode.OK"/> and <paramref name="value"/> to respond with for a request.
 /// </summary>
 /// <param name="responds"></param>
 /// <param name="value">The response value.</param>
 /// <param name="formatter">The media type formatter</param>
 /// <param name="mediaType">The media type. Can be null, in which case the <paramref name="formatter"/> default content type will be used.</param>
 public static TResult RespondObject <T, TResult>(this IResponds <TResult> responds, Func <HttpRequestMessage, T> value, MediaTypeFormatter formatter, string mediaType)
     where TResult : IResponseResult
 {
     return(responds.RespondObject(HttpStatusCode.OK, value, formatter, mediaType));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Specifies the <see cref="HttpStatusCode.OK"/> and <paramref name="value"/> to respond with for a request.
 /// </summary>
 /// <param name="responds"></param>
 /// <param name="value">The response value.</param>
 /// <param name="formatter">The media type formatter</param>
 /// <param name="mediaType">The media type. Can be null, in which case the <paramref name="formatter"/> default content type will be used.</param>
 public static TResult RespondObject <T, TResult>(this IResponds <TResult> responds, T value, MediaTypeFormatter formatter, string mediaType)
     where TResult : IResponseResult
 {
     return(responds.RespondObject(_ => value, formatter, mediaType));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Specifies the <paramref name="statusCode"/> and <paramref name="value"/> to respond with for a request.
 /// </summary>
 /// <param name="responds"></param>
 /// <param name="statusCode">The status code response for given request.</param>
 /// <param name="value">The response value.</param>
 /// <param name="formatter">The media type formatter</param>
 public static TResult RespondObject <T, TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, Func <HttpRequestMessage, T> value, MediaTypeFormatter formatter)
     where TResult : IResponseResult
 {
     return(responds.RespondObject(statusCode, value, formatter, (MediaTypeHeaderValue)null));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Specifies the <paramref name="statusCode"/> and <paramref name="value"/> to respond with for a request.
 /// </summary>
 /// <param name="responds"></param>
 /// <param name="statusCode">The status code response for given request.</param>
 /// <param name="value">The response value.</param>
 /// <param name="formatter">The media type formatter</param>
 public static TResult RespondObject <T, TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, T value, MediaTypeFormatter formatter)
     where TResult : IResponseResult
 {
     return(responds.RespondObject(statusCode, _ => value, formatter));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Specifies the <paramref name="statusCode"/> and <paramref name="value"/> to respond with for a request.
 /// </summary>
 /// <param name="responds"></param>
 /// <param name="statusCode">The status code response for given request.</param>
 /// <param name="value">The response value.</param>
 /// <param name="formatter">The media type formatter</param>
 /// <param name="mediaType">The media type. Can be null, in which case the <paramref name="formatter"/> default content type will be used.</param>
 public static TResult RespondObject <T, TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, Func <HttpRequestMessage, T> value, MediaTypeFormatter formatter, string mediaType)
     where TResult : IResponseResult
 {
     return(responds.RespondObject(statusCode, value, formatter, mediaType is null ? null : MediaTypeHeaderValue.Parse(mediaType)));
 }