Exemplo n.º 1
0
        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];

              };
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void Test_Save_SavesToDatabase()
        {
            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();
              List<Flight> result = Flight.GetAll();
              List<Flight> testList = new List<Flight>{testFlight};

              Assert.Equal(testList, result);
        }
Exemplo n.º 5
0
        public void Test_Save_AssignsIdToObject()
        {
            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 savedFlight = Flight.GetAll()[0];
              int result=savedFlight.GetId();
              int testId=testFlight.GetId();

              Assert.Equal(testId,result);
        }
Exemplo n.º 6
0
        public void Test_GetComplete_FromDatabase()
        {
            //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,true);
              testFlight.Save();
              List<Flight> result = Flight.GetAll();

              //Assert
              Assert.Equal(true, result[0].GetComplete());
        }
Exemplo n.º 7
0
        public void Test_Find_FindsFlightInDatabase()
        {
            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 foundFlight = Flight.Find(testFlight.GetId());

              Assert.Equal(testFlight, foundFlight);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }