public async void TestSearchOneWay() { // Initialize test objects. var logger = ILoggerMockFactory.Build <HomeController>(); var factory = IHttpClientFactoryMockFactory.Build(GetEmptyAirportsPayload()); var testContext = new HomeController(logger, factory); // Invoke the GetAirports method var airports = await testContext.GetAirports(); Assert.True(airports.Count == 0); }
public async void TestIndexHandlesHttpClientException() { // Initialize test objects. var logger = ILoggerMockFactory.Build <HomeController>(); var factory = IHttpClientFactoryMockFactory.Build(new HttpRequestException()); var testContext = new HomeController(logger, factory); // Run the index method and cast result var actionResult = await testContext.Index() as ViewResult; // Test that the Controller redirects user to the HttpErrorPage Assert.NotNull(actionResult); Assert.Equal("HttpErrorPage", actionResult.ViewName); }
public async void TestGetAirports() { // Initialize test objects. var logger = ILoggerMockFactory.Build <HomeController>(); var factory = IHttpClientFactoryMockFactory.Build(GetSuccessfulAirportsPayload()); var testContext = new HomeController(logger, factory); // Invoke the GetAirports method var airports = await testContext.GetAirports(); // Check for instance equality using operator overload var equal = TestAirport == airports[0]; Assert.True(equal); }
public async void TestIndexHandlesEmptyResult() { // Initialize test objects. var logger = ILoggerMockFactory.Build <HomeController>(); var factory = IHttpClientFactoryMockFactory.Build(GetEmptyAirportsPayload()); var testContext = new HomeController(logger, factory); // Run the index method and cast result var actionResult = await testContext.Index() as ViewResult; // Get the viewModel and cast it var viewModel = actionResult.ViewData.Model as HomeSearchViewModel; // Test successful casting Assert.NotNull(actionResult); Assert.NotNull(viewModel); // Test that it successfully imported the empty payload Assert.True(viewModel.Airports.Count == 0); }