public async Task Greet_Name_Greeting(string name, string expected) { // Arrange var httpResponseMessage = new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent(expected) }; var httpRequestMessage = new HttpRequestMessage(); _httpMessageHandler.WhenForAnyArgs(x => x.Send(httpRequestMessage)).DoNotCallBase(); _httpMessageHandler.Send(httpRequestMessage).ReturnsForAnyArgs(httpResponseMessage); // Act IActionResult result = await _helloController.Greet(name).ConfigureAwait(false); // Assert Assert.IsType <OkObjectResult>(result); var okResult = (OkObjectResult)result; var actual = okResult.Value as string; Assert.Equal(expected, actual); }