public async Task TestForResponseTypeGET(HttpStatusCode httpStatusCode) { //Arrange using (var client = new TestClientProvider().Client) { //Act var response = await client.GetAsync("/api/calc"); response.EnsureSuccessStatusCode(); //Assert response.StatusCode.Should().Be(httpStatusCode); } }
public async Task TestForResponseTypeMultiply(int n1, int n2, int result) { using (var client = new TestClientProvider().Client) //Initializes the client { //Arrange var Initial = DateTime.UtcNow; var request = await client.PostAsync($"/api/calc/mul/{n1}/{n2}", new StringContent( JsonConvert.SerializeObject(new Calculator().Multiply(n1, n2)), Encoding.UTF8, "application/json")); request.EnsureSuccessStatusCode(); //Act var response = request.Content.ReadAsStringAsync().Result; var dif = DateTime.Now - Initial; //Assert if (dif.TotalSeconds < 2) { request.StatusCode.Should().Be(HttpStatusCode.OK); //Asserting that the request returns a 200 OK Assert.Equal(result.ToString(), response); //Asserting that the calculation of the Calculator.Add() method is as expected } } }