public async Task FromStatusCode_NoContent_Works_Async() { var response = new HttpResponseMessage(HttpStatusCode.NotFound); var exception = await ImageRegistryException.FromResponseAsync(response, default).ConfigureAwait(false); Assert.Equal("An unexpected error occurred when sending a request to the remote server.", exception.Message); Assert.Empty(exception.Errors); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); }
public async Task FromStatusCode_JsonContent_Works_Async() { var response = new HttpResponseMessage(HttpStatusCode.BadRequest); response.Content = new StringContent("{\"errors\":[{\"code\":\"DIGEST_INVALID\",\"message\":\"provided digest did not match uploaded content\",\"detail\":\"digest parsing failed\"}]}", Encoding.UTF8, "application/json"); var exception = await ImageRegistryException.FromResponseAsync(response, default).ConfigureAwait(false); Assert.Equal("provided digest did not match uploaded content", exception.Message); Assert.Single(exception.Errors); Assert.Equal(HttpStatusCode.BadRequest, exception.StatusCode); }
public async Task FromStatusCode_TextContent_Works_Async() { var response = new HttpResponseMessage(HttpStatusCode.NotFound); response.Content = new StringContent("NOT FOUND"); var exception = await ImageRegistryException.FromResponseAsync(response, default).ConfigureAwait(false); Assert.Equal("NOT FOUND", exception.Message); Assert.Empty(exception.Errors); Assert.Equal(HttpStatusCode.NotFound, exception.StatusCode); }