public async Task UnsupportedContentTypeNotFound()
 {
     await GetApiInfoInvalidResponse(
         _ => new HttpResponseMessage(HttpStatusCode.NotFound)
     {
         Content = new StringContent("text", Encoding.UTF8, "text/plain")
     },
         ServiceErrors.NotFound, HttpServiceErrors.CreateErrorForStatusCode(HttpStatusCode.NotFound).Message);
 }
 public async Task InvalidJsonNotFound()
 {
     await GetApiInfoInvalidResponse(
         _ => new HttpResponseMessage(HttpStatusCode.NotFound)
     {
         Content = new StringContent("{", Encoding.UTF8, "application/json")
     },
         ServiceErrors.NotFound, HttpServiceErrors.CreateErrorForStatusCode(HttpStatusCode.NotFound).Message);
 }
    /// <summary>
    /// Called to create an error object from an unhandled HTTP response.
    /// </summary>
    protected virtual async Task <ServiceErrorDto> CreateErrorFromHttpResponseAsync(HttpResponseMessage response, CancellationToken cancellationToken)
    {
        var result = await ContentSerializer.ReadHttpContentAsync <ServiceErrorDto>(response.Content, cancellationToken).ConfigureAwait(false);

        if (result.IsFailure || string.IsNullOrWhiteSpace(result.Value.Code))
        {
            return(HttpServiceErrors.CreateErrorForStatusCode(response.StatusCode, response.ReasonPhrase));
        }

        return(result.Value);
    }
        public async Task NotFoundHtmlClientError()
        {
            var service = CreateTestService(request =>
            {
                var response     = new HttpResponseMessage(HttpStatusCode.NotFound);
                response.Content = new StringContent("<html><body><h1>Not Found!</h1></body></html>");
                response.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("text/html");
                return(response);
            });

            var result = await service.CreateWidgetAsync(new WidgetDto(name : "hi"));

            result.Error.Should().BeDto(HttpServiceErrors.CreateErrorForStatusCode(HttpStatusCode.NotFound));
        }
 public async Task MissingContentTypeNotFound()
 {
     await GetApiInfoInvalidResponse(
         _ => new HttpResponseMessage(HttpStatusCode.NotFound),
         ServiceErrors.NotFound, HttpServiceErrors.CreateErrorForStatusCode(HttpStatusCode.NotFound).Message);
 }