public void Test_HttpFakes_TestWithResponse() { // Arrange - setup client and fake response. var fakeHttpClient = new FakeHttpClient(FAKEAPIURL); fakeHttpClient.AddEndPoint("api/values", new HttpResponseMessage(HttpStatusCode.OK)); var client = fakeHttpClient.GetHttpClient(); // Act - make fake request. var response = client.GetAsync("api/values").GetAwaiter().GetResult(); // Assert - response was as expected. Assert.Equal(HttpStatusCode.OK, response.StatusCode); }
public void Test_HttpFakes_DoesNotExist() { // Arrange - setup client and fake response. var fakeHttpClient = new FakeHttpClient(FAKEAPIURL); fakeHttpClient.AddEndPoint("api/values", HttpStatusCode.OK); var client = fakeHttpClient.GetHttpClient(); // Act - make fake request. var response = client.GetAsync("anotherEndpoint").GetAwaiter().GetResult(); // Assert - response was as expected. Assert.Equal(HttpStatusCode.NotFound, response.StatusCode); }
public void Test_HttpFakes_VerifyResponseData() { // Arrange - setup client and fake response. var responseData = "test"; var fakeHttpClient = new FakeHttpClient(FAKEAPIURL); fakeHttpClient.AddEndPoint("api/values", HttpStatusCode.OK, responseData); var client = fakeHttpClient.GetHttpClient(); // Act - make fake request and get response body. var response = client.GetAsync("api/values").GetAwaiter().GetResult(); var content = JsonConvert.DeserializeObject <string>(response.Content.ReadAsStringAsync().GetAwaiter().GetResult()); // Assert - response was as expected. Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Equal(content, responseData); }