public void GetAsync_DeserializesResponse() { var expected = new Poco { P1 = "value1" }; _innerHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .Returns(Task.FromResult(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(expected)) })); var actual = _testObject.GetAsync <Poco>("path/id", CancellationToken.None).Result; Assert.AreEqual(expected.P1, actual.P1); }
public void PutAsync_PostsCorrectContent() { string actualBody = null; var expectedBody = new Poco { P1 = "request" }; _innerHandler.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .Returns(Task.FromResult(new HttpResponseMessage { Content = new StringContent(string.Empty) })) .Callback <HttpRequestMessage, CancellationToken>((request, _) => actualBody = request.Content.ReadAsStringAsync().Result); _testObject.PutAsync <string>("path/id", expectedBody, CancellationToken.None).Wait(); Assert.NotNull(actualBody); Assert.AreEqual(JsonConvert.SerializeObject(expectedBody, _serializerSettings), actualBody); }
public void GetAsync_DeserializesResponse() { var expected = new Poco {P1 = "value1"}; _innerHandler.Protected() .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>()) .Returns(Task.FromResult(new HttpResponseMessage { Content = new StringContent(JsonConvert.SerializeObject(expected)) })); var actual = _testObject.GetAsync<Poco>("path/id", CancellationToken.None).Result; Assert.AreEqual(expected.P1, actual.P1); }
public void PutAsync_PostsCorrectContent() { string actualBody = null; var expectedBody = new Poco {P1 = "request"}; _innerHandler.Protected() .Setup<Task<HttpResponseMessage>>("SendAsync", ItExpr.IsAny<HttpRequestMessage>(), ItExpr.IsAny<CancellationToken>()) .Returns(Task.FromResult(new HttpResponseMessage { Content = new StringContent(string.Empty) })) .Callback<HttpRequestMessage, CancellationToken>((request, _) => actualBody = request.Content.ReadAsStringAsync().Result); _testObject.PutAsync<string>("path/id", expectedBody, CancellationToken.None).Wait(); Assert.NotNull(actualBody); Assert.AreEqual(JsonConvert.SerializeObject(expectedBody, _serializerSettings), actualBody); }