public async Task HttpClient_GetAsync_ResponseContentAreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("get response") }; fakeHttpMessageHandler.AddFakeResponse(new Uri("http://example.org/test"), fakeResponse); var httpClient = new HttpClient(fakeHttpMessageHandler); var response = await httpClient.GetAsync("http://example.org/test"); var stringResponse = await response.Content.ReadAsStringAsync(); Assert.AreEqual("get response", stringResponse); }
public async Task HttpClient_PostAsync_ResponseContentAreEqual() { var fakeHttpMessageHandler = new FakeHttpMessageHandler(); var fakeResponse = new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("post response") }; fakeHttpMessageHandler.AddFakeResponse(new Uri("http://example.org/test"), fakeResponse); var httpClient = new HttpClient(fakeHttpMessageHandler); var parameters = new Dictionary <string, string> { { "Name", "bob" } }; var content = new FormUrlEncodedContent(parameters.ToArray()); var response = await httpClient.PostAsync("http://example.org/test", content); var stringResponse = await response.Content.ReadAsStringAsync(); Assert.AreEqual("post response", stringResponse); }