コード例 #1
0
        public async Task Response_Read_Xml_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 = XmlTestClients.RespondWith(HttpStatusCode.BadRequest, responseBody))
            {
                TestBody actualBody = await client
                                      .GetAsync(DefaultRequest)
                                      .ReadContentAsAsync(new XmlFormatter(),
                                                          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);
            }
        }
コード例 #2
0
        public async Task Response_Read_Xml_TreatAsSuccess()
        {
            TestBody expectedBody = new TestBody
            {
                StringProperty = "This is a test",
                IntProperty    = 123
            };

            using (HttpClient client = XmlTestClients.RespondWith(HttpStatusCode.BadRequest, expectedBody))
            {
                TestBody actualBody = await client
                                      .GetAsync(DefaultRequest)
                                      .ReadContentAsAsync <TestBody>(new XmlFormatter(), HttpStatusCode.OK, HttpStatusCode.BadRequest);

                Assert.NotNull(actualBody);
                Assert.NotSame(expectedBody, actualBody);
                Assert.Equal(expectedBody.StringProperty, actualBody.StringProperty);
                Assert.Equal(expectedBody.IntProperty, actualBody.IntProperty);
            }
        }