public void InternalServerErrorException() { var httpMessage = new HttpRequestMessage(HttpMethod.Get, "localhost"); var restResponse = GetRestResponse(HttpStatusCode.InternalServerError, "errorInternal", httpMessage); var errorResult = RestStatusError.RestStatusToErrorResult(restResponse); Assert.Equal(ErrorResultType.InternalServerError, errorResult.ErrorResultType); }
public void HttpStatusCodeStatusServerNotFound() { var httpMessage = new HttpRequestMessage(HttpMethod.Get, "localhost"); var restResponse = GetRestResponse(0, "errorInternal", httpMessage); var errorResult = RestStatusError.RestStatusToErrorResult(restResponse); Assert.Equal(ErrorResultType.ServerNotFound, errorResult.ErrorResultType); }
public void HttpStatusCodeStatus(HttpStatusCode httpStatusCode, ErrorResultType errorResultType) { var httpMessage = new HttpRequestMessage(HttpMethod.Get, "localhost"); var restResponse = GetRestResponse(httpStatusCode, httpStatusCode.ToString(), httpMessage); var errorResult = RestStatusError.RestStatusToErrorResult(restResponse); Assert.Equal(errorResultType, errorResult.ErrorResultType); }
/// <summary> /// Преобразовать ответ сервера в результирующий ответ /// </summary> public static IResultError ToRestResultError(this HttpResponseMessage @this) => @this.IsSuccessStatusCode ? new ResultError() : RestStatusError.RestStatusToErrorResult(@this).ToResult();
/// <summary> /// Преобразовать ответ сервера в результирующий ответ с коллекцией /// </summary> public static async Task <IResultCollection <TValue> > ToRestResultCollectionAsync <TValue>(this HttpResponseMessage @this) where TValue : notnull => @this.IsSuccessStatusCode ? await @this.Content.ReadAsStringAsync().ToTransferCollectionJsonAsync <TValue>() : RestStatusError.RestStatusToErrorResult(@this).ToResultCollection <TValue>();
/// <summary> /// Преобразовать ответ сервера в результирующий ответ со значением строки /// </summary> public static async Task <IResultValue <string> > ToRestResultAsync(this HttpResponseMessage @this) => @this.IsSuccessStatusCode ? (await @this.Content.ReadAsStringAsync()).Trim('"').ToResultValue() : RestStatusError.RestStatusToErrorResult(@this).ToResultValue <string>();