public static HttpResponseMessage CreateResponse <TResponse>(this HttpRequestMessage request, IResponseStatus <TResponse> responseStatus) where TResponse : IResponse { if (responseStatus is OkResponseStatus <TResponse> ) { var response = ((OkResponseStatus <TResponse>)responseStatus).Response; return(request.CreateResponse(HttpStatusCode.OK, response)); } Verify.Argument.IsTrue(responseStatus is ErrorResponseStatus <TResponse>, "responseStatus"); var errorResponseStatus = ((ErrorResponseStatus <TResponse>)responseStatus); var responseError = errorResponseStatus.Error; if (responseError.ErrorCode == CommonResponseErrorCode.InternalServerError) { var internalServerErrroResponse = new InternalServerErrorResponse { ErrorMessage = responseError.ErrorMessage }; return(request.CreateResponse(HttpStatusCode.InternalServerError, internalServerErrroResponse)); } var badRequestResponse = ConvertResponseErrorToBadRequestErrorResponse(responseError); return(request.CreateResponse(HttpStatusCode.BadRequest, badRequestResponse)); }
/// <summary> /// A success response is: /// * is not null /// * has its Success property to true /// * has its Error property to Null /// </summary> /// <param name="response"></param> public static void HasSucceeded(IResponseStatus response) { Assert.NotNull(response); Assert.True(response.Success); Assert.Null(response.Error); }