public HomeModule() { Get["/"] = _ => { return View["index.cshtml"]; }; Get["/flights"] = _ => { List<Flight> allFlights = Flight.GetAll(); List<City> allCities = City.GetAll(); Dictionary<string,object> model = new Dictionary<string,object>{ {"allFlights", allFlights}, {"allCities", allCities}, {"message","welcome to our airline"} }; return View["flights.cshtml",model]; }; Post["/add_new_city"] = _ => { City newCity = new City( Request.Form["new-name"], Request.Form["new-state"], Request.Form["new-country"]); newCity.Save(); List<Flight> allFlights = Flight.GetAll(); List<City> allCities = City.GetAll(); Dictionary<string,object> model = new Dictionary<string,object>{ {"allFlights", allFlights}, {"allCities", allCities}, {"message","You just add " +Request.Form["new-name"]+" Cities"} }; return View["flights.cshtml",model]; }; Post["/add_new_flight"] = _ => { Flight newFlight = new Flight( Request.Form["flight-name"], Request.Form["flight-status"], Request.Form["flight-depart"], Request.Form["flight-return"], Request.Form["flight-complete"] ); newFlight.Save(); List<Flight> allFlights = Flight.GetAll(); List<City> allCities = City.GetAll(); Dictionary<string,object> model = new Dictionary<string,object>{ {"allFlights", allFlights}, {"allCities", allCities}, {"message","You just add " + Request.Form["flight-name"]+" Flights"} }; return View["flights.cshtml",model]; }; }
public void T3_Save_SavesCityToDatabase() { // Arrange City testCity = new City("Seattle","WA","USA"); testCity.Save(); // Act List<City> result = City.GetAll(); List<City> testList = new List<City>{testCity}; // Assert Assert.Equal(testList, result); }
public void T4_Save_AssignsIdToCagetoryObject() { //Arrange City testCity = new City("Seattle","WA","USA"); testCity.Save(); //Act City savedCity = City.GetAll()[0]; int result = savedCity.GetId(); int testId = testCity.GetId(); //Assert Assert.Equal(testId, result); }
public void Test_AddCity_AddsCityToFlight() { DateTime departing_time= new DateTime(2016,06,05); DateTime returning_time = new DateTime(2016, 1, 1); Flight testFlight = new Flight("E201","On time",departing_time,returning_time); testFlight.Save(); City departCity = new City("Seattle","WA","USA"); City arrivalCity = new City("New York","WA","USA"); departCity.Save(); arrivalCity.Save(); //Act testFlight.AddCity(departCity,arrivalCity); List<City> result = testFlight.GetCities(); List<City> testList = new List<City> {departCity,arrivalCity}; //Assert Assert.Equal(testList, result); }
public void Test_Delete_DeletesFlightAssociationsFromDatabase() { //Arrange DateTime departing_time= new DateTime(2016,06,05); DateTime returning_time = new DateTime(2016, 1, 1); Flight testFlight = new Flight("E201","On time",departing_time,returning_time); testFlight.Save(); City departCity = new City("Seattle","WA","USA"); City arrivalCity = new City("New York","WA","USA"); departCity.Save(); arrivalCity.Save(); //Act testFlight.AddCity(departCity,arrivalCity); testFlight.Delete(); List<Flight> resultCityFlights = departCity.GetFlightsbyDeparting(); List<Flight> testCityFlights = new List<Flight> {}; //Assert Assert.Equal(testCityFlights, resultCityFlights); }
public void T7_Update_UpdatesCityInDatabase() { //Arrange City testCity = new City("Seattle","WA","USA"); testCity.Save(); string newName = "New York"; string newState = "NY"; string newCountry = "USA"; //Act testCity.Update(newName,newState,newCountry); string result = testCity.GetCity(); //Assert Assert.Equal(newName, result); }
public void T5_Find_FindsCityInDatabase() { //Arrange City testCity = new City("Seattle","WA","USA"); testCity.Save(); //Act City foundCity = City.Find(testCity.GetId()); //Assert Assert.Equal(testCity, foundCity); }
public void Test_GetFlightsbyDeparting_ReturnAllCityFlights() { City departCity = new City("Seattle","WA","USA"); City arrivalCity = new City("New York","WA","USA"); departCity.Save(); arrivalCity.Save(); DateTime departing_time= new DateTime(2016,06,05); DateTime returning_time = new DateTime(2016, 1, 1); Flight testFlight = new Flight("E201","On time",departing_time,returning_time); testFlight.Save(); Flight testFlight2 = new Flight("E202","Late",departing_time,returning_time); testFlight2.Save(); departCity.AddFlyingFromFlight(testFlight,arrivalCity); List<Flight> savedFlights = departCity.GetFlightsbyDeparting(); List<Flight> testList= new List<Flight>{testFlight}; Assert.Equal(testList,savedFlights); }
public void Test_Delete_DeletesCityAssociationsFromDatabase() { //Arrange City departCity = new City("Seattle","WA","USA"); City arrivalCity = new City("New York","WA","USA"); departCity.Save(); arrivalCity.Save(); DateTime departing_time= new DateTime(2016,06,05); DateTime returning_time = new DateTime(2016, 1, 1); Flight testFlight = new Flight("E201","On time",departing_time,returning_time); testFlight.Save(); Flight testFlight2 = new Flight("E202","Late",departing_time,returning_time); testFlight2.Save(); departCity.AddFlyingFromFlight(testFlight,arrivalCity); departCity.Delete(); List<Flight> allflights= Flight.GetAll(); List<Flight> testList= new List<Flight>{testFlight2}; //Assert Assert.Equal(testList, allflights); }
public void Test_AddFlyingFromFlight_AddsFlightToCity() { //Arrange City departCity = new City("Seattle","WA","USA"); City arrivalCity = new City("New York","WA","USA"); departCity.Save(); arrivalCity.Save(); DateTime departing_time= new DateTime(2016,06,05); DateTime returning_time = new DateTime(2016, 1, 1); Flight testFlight = new Flight("E201","On time",departing_time,returning_time); testFlight.Save(); Flight testFlight2 = new Flight("E202","Late",departing_time,returning_time); testFlight2.Save(); //Act departCity.AddFlyingFromFlight(testFlight,arrivalCity); departCity.AddFlyingFromFlight(testFlight2,arrivalCity); List<Flight> result = departCity.GetFlightsbyDeparting(); List<Flight> testList = new List<Flight> {testFlight, testFlight2}; Assert.Equal(testList, result); }
public void T8_Delete_DeletesCityFromDatabase() { //Arrange City testCity1 = new City("Seattle","WA","USA"); City testCity2 = new City("New York","WA","USA"); testCity1.Save(); testCity2.Save(); //Act testCity1.Delete(); List<City> resultCategories = City.GetAll(); List<City> testCityList = new List<City> {testCity2}; //Assert Assert.Equal(testCityList, resultCategories); }