Example #1
0
        public void Delete_AllFlights_AllButOneFlight()
        {
            City city1 = new City("Barcelona");

            city1.Save();
            City city2 = new City("Honolulu");

            city2.Save();
            Flight flight1 = new Flight("12:00 pm", city1.GetName(), city2.GetName(), "Delayed");

            flight1.Save();
            flight1.AddCities(city1, city2);

            City city3 = new City("Barcelona");

            city3.Save();
            City city4 = new City("Honolulu");

            city4.Save();
            Flight flight2 = new Flight("14:00 pm", city3.GetName(), city4.GetName(), "Delayed");

            flight2.Save();
            flight2.AddCities(city3, city4);

            flight1.Delete();

            List <Flight> returnedFlights = Flight.GetAll();
            List <Flight> expected        = new List <Flight> {
                flight2
            };

            Assert.Equal(returnedFlights, expected);
        }
Example #2
0
        public void GetFlightsByDeparture_GetFlightsByCity_ConnectedFlights()
        {
            City city1 = new City("Seattle");

            city1.Save();
            City city2 = new City("Chicago");

            city2.Save();
            City city3 = new City("Orange County");

            city3.Save();

            Flight flight1 = new Flight("12:00 pm", "Seattle", "Orange County", "Delayed");

            flight1.Save();
            flight1.AddCities(city1, city3);
            Flight flight2 = new Flight("2am", "Chicago", "Seattle", "On-time");

            flight2.Save();
            flight2.AddCities(city2, city1);

            List <Flight> expected = new List <Flight> {
                flight1
            };
            List <Flight> returnedFlights = city1.GetFlightsByDepartureOrArrival(false);

            Assert.Equal(expected, returnedFlights);
        }
Example #3
0
        public void Test_Find_FindsCityInDatabase()
        {
            //Arrange
            City testCity = new City("Chicago");

            testCity.Save();

            //Act
            City foundCity = City.Find(testCity.GetId());

            //Assert
            Assert.Equal(testCity, foundCity);
        }
        public HomeModule()
        {
            Get["/"] = _ => {
                List <City> allCities = City.GetAll();
                return(View["index.cshtml", allCities]);
            };

            Post["/"] = _ => {
                Flight newFlight = new Flight(Request.Form["departure"], Request.Form["departure-city"], Request.Form["arrival-city"], Request.Form["status"]);
                newFlight.Save();
                return(View["add_flight_success.cshtml", newFlight]);
            };

            Get["/cities"] = _ => {
                List <City> allCities = City.GetAll();
                return(View["cities.cshtml", allCities]);
            };

            Post["/cities"] = _ => {
                string userInput = Request.Form["name"];
                City   newCity   = new City(userInput);
                newCity.Save();
                List <City> allCities = City.GetAll();
                return(View["cities.cshtml", allCities]);
            };

            Get["/flights"] = _ => {
                List <Flight> allFlights = Flight.GetAll();
                return(View["flights.cshtml", allFlights]);
            };

            Post["/flights"] = _ => {
                string departure       = Request.Form["departure"];
                int    departureCityId = Request.Form["departure-city"];
                int    arrivalCityId   = Request.Form["arrival-city"];
                string status          = Request.Form["status"];

                City departureCity = City.Find(departureCityId);
                City arrivalCity   = City.Find(arrivalCityId);

                string departureCityString = departureCity.GetName();
                string arrivalCityString   = arrivalCity.GetName();

                Flight newFlight = new Flight(departure, departureCityString, arrivalCityString, status);
                newFlight.Save();
                newFlight.AddCities(departureCity, arrivalCity);

                List <Flight> allFlights = Flight.GetAll();
                return(View["flights.cshtml", allFlights]);
            };
        }
Example #5
0
        public void Test_Save_AssignsIdToCityObject()
        {
            //Arrange
            City testCity = new City("Miami");

            testCity.Save();

            //Act
            City savedCity = City.GetAll()[0];

            int result = savedCity.GetId();
            int testId = testCity.GetId();

            //Assert
            Assert.Equal(testId, result);
        }
Example #6
0
        public void Test_Save_SavesCityToDatabase()
        {
            //Arrange
            City testCity = new City("Miami");

            testCity.Save();

            //Act
            List <City> result   = City.GetAll();
            List <City> testList = new List <City> {
                testCity
            };

            //Assert
            Assert.Equal(testList, result);
        }
Example #7
0
        public void UpdateStatus_OneFlight_NewStatus()
        {
            City city1 = new City("Barcelona");

            city1.Save();
            City city2 = new City("Honolulu");

            city2.Save();
            Flight flight1 = new Flight("12:00 pm", city1.GetName(), city2.GetName(), "Delayed");

            flight1.Save();
            flight1.AddCities(city1, city2);

            flight1.UpdateStatus("On Time");

            string newStatus = flight1.GetStatus();

            Assert.Equal(newStatus, "On Time");
        }
Example #8
0
        public void UpdateDeparture_OneFlight_NewDeparture()
        {
            City city1 = new City("Barcelona");

            city1.Save();
            City city2 = new City("Honolulu");

            city2.Save();
            Flight flight1 = new Flight("12:00 pm", city1.GetName(), city2.GetName(), "Delayed");

            flight1.Save();
            flight1.AddCities(city1, city2);

            flight1.UpdateDeparture("12:00 am");

            string newDeparture = flight1.GetDeparture();

            Assert.Equal(newDeparture, "12:00 am");
        }
Example #9
0
        public void Test_AddCities_AddsCityToFlight()
        {
            //Arrange
            City departureCity = new City("Chicago");

            departureCity.Save();
            City arrivalCity = new City("Seattle");

            arrivalCity.Save();

            Flight testFlight = new Flight("12:00 pm", departureCity.GetName(), arrivalCity.GetName(), "Delayed");

            testFlight.Save();
            testFlight.AddCities(departureCity, arrivalCity);

            List <City> result   = testFlight.GetCities();
            List <City> testList = new List <City> {
                departureCity, arrivalCity
            };

            //Assert
            Assert.Equal(testList, result);
        }
Example #10
0
        public void UpdateArrivalCity_OneFlight_NewArrivalCity()
        {
            City city1 = new City("Barcelona");

            city1.Save();
            City city2 = new City("Honolulu");

            city2.Save();
            Flight flight1 = new Flight("12:00 pm", city1.GetName(), city2.GetName(), "Delayed");

            flight1.Save();
            flight1.AddCities(city1, city2);

            City city3 = new City("Austin");

            city3.Save();

            flight1.UpdateArrivalCity(city3);

            string newArrivalCity = flight1.GetArrivalCity();

            Assert.Equal(newArrivalCity, city3.GetName());
        }