Exemplo n.º 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);
        }
Exemplo n.º 2
0
        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]);
            };
        }
Exemplo n.º 3
0
 public override bool Equals(System.Object otherCity)
 {
     if (!(otherCity is City))
     {
         return(false);
     }
     else
     {
         City newCity      = (City)otherCity;
         bool idEquality   = this.GetId() == newCity.GetId();
         bool nameEquality = this.GetName() == newCity.GetName();
         return(idEquality && nameEquality);
     }
 }
Exemplo n.º 4
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");
        }
Exemplo n.º 5
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");
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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());
        }
Exemplo n.º 8
0
        public void UpdateArrivalCity(City newCity)
        {
            City OldArrivalCity   = City.FindByName(this.GetArrivalCity());
            int  OldArrivalCityId = OldArrivalCity.GetId();

            SqlConnection conn = DB.Connection();

            conn.Open();

            SqlCommand cmd = new SqlCommand("UPDATE flights SET arrival_city = @ArrivalCity OUTPUT INSERTED.arrival_city WHERE id=@FlightId; UPDATE flights_cities SET city_id = @NewArrivalCityId WHERE flight_id = @FlightId AND city_id = @OldArrivalCityId;", conn);

            SqlParameter arrivalCityParameter = new SqlParameter("@ArrivalCity", newCity.GetName());
            SqlParameter flightIdParameter    = new SqlParameter("@FlightId", this.GetId());
            SqlParameter oldArrivalCity       = new SqlParameter("@OldArrivalCityId", OldArrivalCityId);
            SqlParameter newArrivalCity       = new SqlParameter("@NewArrivalCityId", newCity.GetId());

            cmd.Parameters.Add(arrivalCityParameter);
            cmd.Parameters.Add(flightIdParameter);
            cmd.Parameters.Add(oldArrivalCity);
            cmd.Parameters.Add(newArrivalCity);

            SqlDataReader rdr = cmd.ExecuteReader();

            while (rdr.Read())
            {
                this._arrivalCity = rdr.GetString(0);
            }
            if (rdr != null)
            {
                rdr.Close();
            }
            if (conn != null)
            {
                conn.Close();
            }
        }