public async Task When_responding_with_json_object_it_should_return_response() { var jsonContent = new { name = "John Doe" }; var request = new HttpRequestMessage(); // Act _sut.RespondJson(jsonContent); HttpResponseMessage actualResponse = await _httpClient.SendAsync(request, CancellationToken.None); // Assert await actualResponse.Should() .HaveStatusCode(HttpStatusCode.OK) .And.HaveJsonContent(jsonContent); }
/// <summary> /// Specifies the <see cref="HttpStatusCode.OK"/> and <paramref name="content"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="content">The response content.</param> /// <param name="mediaType">The media type. Can be null, in which case the default JSON content type will be used.</param> public static TResult RespondJson <T, TResult>(this IResponds <TResult> responds, Func <HttpRequestMessage, T> content, MediaTypeHeaderValue mediaType) where TResult : IResponseResult { return(responds.RespondJson(HttpStatusCode.OK, content, mediaType)); }
/// <summary> /// Specifies the <see cref="HttpStatusCode.OK"/> and <paramref name="content"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="content">The response content.</param> /// <param name="mediaType">The media type. Can be null, in which case the default JSON content type will be used.</param> /// <param name="serializerSettings">The serializer settings.</param> public static TResult RespondJson <T, TResult>(this IResponds <TResult> responds, T content, MediaTypeHeaderValue mediaType, JsonSerializerSettings serializerSettings) where TResult : IResponseResult { return(responds.RespondJson(_ => content, mediaType, serializerSettings)); }
/// <summary> /// Specifies the <see cref="HttpStatusCode.OK"/> and <paramref name="content"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="content">The response content.</param> /// <param name="mediaType">The media type. Can be null, in which case the default JSON content type will be used.</param> public static TResult RespondJson <T, TResult>(this IResponds <TResult> responds, T content, MediaTypeHeaderValue mediaType) where TResult : IResponseResult { return(responds.RespondJson(_ => content, mediaType)); }
/// <summary> /// Specifies the <paramref name="statusCode"/> and <paramref name="content"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> /// <param name="content">The response content.</param> public static TResult RespondJson <T, TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, Func <HttpRequestMessage, T> content) where TResult : IResponseResult { return(responds.RespondJson(statusCode, content, (MediaTypeHeaderValue)null)); }
/// <summary> /// Specifies the <paramref name="statusCode"/> and <paramref name="content"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> /// <param name="content">The response content.</param> public static TResult RespondJson <T, TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, T content) where TResult : IResponseResult { return(responds.RespondJson(statusCode, _ => content)); }
/// <summary> /// Specifies the <paramref name="statusCode"/> and <paramref name="content"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="statusCode">The status code response for given request.</param> /// <param name="content">The response content.</param> /// <param name="mediaType">The media type. Can be null, in which case the default JSON content type will be used.</param> public static TResult RespondJson <T, TResult>(this IResponds <TResult> responds, HttpStatusCode statusCode, Func <HttpRequestMessage, T> content, string mediaType) where TResult : IResponseResult { return(responds.RespondJson(statusCode, content, mediaType is null ? null : new MediaTypeHeaderValue(mediaType))); }
/// <summary> /// Specifies the <see cref="HttpStatusCode.OK"/> and <paramref name="content"/> to respond with for a request. /// </summary> /// <param name="responds"></param> /// <param name="content">The response content.</param> public static TResult RespondJson <T, TResult>(this IResponds <TResult> responds, T content) where TResult : IResponseResult { return(responds.RespondJson(_ => content)); }