public ActionResult Index(SearchFlightModel inputSearch) { if (ModelState.IsValid) { List <SearchFlightModel> result = new List <SearchFlightModel>(); SearchFlight source = new SearchFlight(); result = source.searchFlighsByOriginDestination(inputSearch); ViewBag.NoRecordFound = false; //check flight count if its zero then message is created & if its greater than zero, flight list will be display on view. if (result.Count <= 0) { ViewBag.NoRecordFound = true; ViewBag.Message = "No Flights Found for " + inputSearch.Origin + " --> " + inputSearch.Destination; } return(View(result)); } else { //Model state is not valid, for validation please check the model return(RedirectToAction("Index", "InvalidRequest")); } }
public void TestFlightsExpectedResults() { SearchFlightModel inputSearch = new SearchFlightModel() { Origin = "LHR", Destination = "BOS" }; List <SearchFlightModel> expectedResult = new List <SearchFlightModel>(); SearchFlight source = new SearchFlight(); expectedResult = source.searchFlighsByOriginDestination(inputSearch); searchFlightsController controller = new searchFlightsController(); var view = controller.Index(inputSearch) as ViewResult; List <SearchFlightModel> actualResult = (List <SearchFlightModel>)view.ViewData.Model; Assert.AreEqual(expectedResult.Count, actualResult.Count); if (expectedResult.Count > 0) { for (int i = 0; i >= expectedResult.Count; i++) { Assert.AreEqual(expectedResult[i].Origin, actualResult[i].Origin); Assert.AreEqual(expectedResult[i].DepartureTime, actualResult[i].DepartureTime); Assert.AreEqual(expectedResult[i].Destination, actualResult[i].DestinationTime); Assert.AreEqual(expectedResult[i].DestinationTime, actualResult[i].DestinationTime); Assert.AreEqual(expectedResult[i].Price, actualResult[i].Price); } } }