public async Task Response_Read_Json_Failure_Transformed() { TestBody expectedBody = new TestBody { StringProperty = "This is a failure response", IntProperty = 456 }; TestBody responseBody = new TestBody { StringProperty = "This is a test", IntProperty = 123 }; using (HttpClient client = JsonTestClients.RespondWith(HttpStatusCode.BadRequest, responseBody)) { TestBody actualBody = await client .GetAsync(DefaultRequest) .ReadContentAsAsync(new JsonFormatter(), onFailureResponse: () => new TestBody { StringProperty = expectedBody.StringProperty, IntProperty = expectedBody.IntProperty } ); Assert.NotNull(actualBody); Assert.NotSame(expectedBody, actualBody); Assert.Equal(expectedBody.StringProperty, actualBody.StringProperty); Assert.Equal(expectedBody.IntProperty, actualBody.IntProperty); } }
public async Task Response_Read_Json_TreatAsSuccess() { TestBody expectedBody = new TestBody { StringProperty = "This is a test", IntProperty = 123 }; using (HttpClient client = JsonTestClients.RespondWith(HttpStatusCode.BadRequest, expectedBody)) { TestBody actualBody = await client .GetAsync(DefaultRequest) .ReadContentAsAsync <TestBody>(new JsonFormatter(), HttpStatusCode.OK, HttpStatusCode.BadRequest); Assert.NotNull(actualBody); Assert.NotSame(expectedBody, actualBody); Assert.Equal(expectedBody.StringProperty, actualBody.StringProperty); Assert.Equal(expectedBody.IntProperty, actualBody.IntProperty); } }