public void T2_Equal_ReturnsTrueForSameName() { // Arrange, act City firstCity = new City("Seattle","WA","USA"); City secondCity = new City("Seattle","WA","USA"); // Assert Assert.Equal(firstCity, secondCity); }
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 static City Find(int id) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM cities WHERE id = @CityId;", conn); SqlParameter cityIdParameter = new SqlParameter(); cityIdParameter.ParameterName = "@CityId"; cityIdParameter.Value = id.ToString(); cmd.Parameters.Add(cityIdParameter); SqlDataReader rdr = cmd.ExecuteReader(); int foundCityId = 0; string foundCityName = null; string foundCityState = null; string foundCityCountry = null; while(rdr.Read()) { foundCityId = rdr.GetInt32(0); foundCityName = rdr.GetString(1); foundCityState = rdr.GetString(2); foundCityCountry= rdr.GetString(3); } City foundCity = new City(foundCityName,foundCityState,foundCityCountry,foundCityId); if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return foundCity; }
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 AddFlyingFromFlight(Flight newFlight, City FlyingToCity) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO flights_cities(flight_id,departing_city_id,returning_city_id) VALUES(@FlightId,@DepartCityId,@ReturningCityId);",conn); SqlParameter newFlightIdParameter = new SqlParameter(); newFlightIdParameter.ParameterName = "@FlightId"; newFlightIdParameter.Value=newFlight.GetId(); cmd.Parameters.Add(newFlightIdParameter); SqlParameter departCityIdParameter = new SqlParameter(); departCityIdParameter.ParameterName="@DepartCityId"; departCityIdParameter.Value=this.GetId(); cmd.Parameters.Add(departCityIdParameter); SqlParameter ReturningCityIdParameter = new SqlParameter(); ReturningCityIdParameter.ParameterName="@ReturningCityId"; ReturningCityIdParameter.Value=FlyingToCity.GetId(); cmd.Parameters.Add(ReturningCityIdParameter); cmd.ExecuteNonQuery(); if(conn != null) { conn.Close(); } }
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); }
public List<City> GetCities() { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT departing_city_id,returning_city_id FROM flights_cities WHERE flight_id=@FlightId",conn); SqlParameter flightIdParameter = new SqlParameter(); flightIdParameter.ParameterName= "@FlightId"; flightIdParameter.Value=this.GetId(); cmd.Parameters.Add(flightIdParameter); SqlDataReader rdr = cmd.ExecuteReader(); List<int> cityIds= new List<int>{}; while(rdr.Read()) { int departingCityId= rdr.GetInt32(0); int returningCityId= rdr.GetInt32(1); cityIds.Add(departingCityId); cityIds.Add(returningCityId); } if(rdr !=null) { rdr.Close(); } List<City> cities = new List<City> {}; foreach (int cityId in cityIds) { SqlCommand cityQuery = new SqlCommand("SELECT * FROM cities WHERE id = @CityId;", conn); SqlParameter cityIdParameter = new SqlParameter(); cityIdParameter.ParameterName = "@CityId"; cityIdParameter.Value = cityId; cityQuery.Parameters.Add(cityIdParameter); SqlDataReader queryReader = cityQuery.ExecuteReader(); while (queryReader.Read()) { int thisCityId = queryReader.GetInt32(0); string cityName = queryReader.GetString(1); string cityState = queryReader.GetString(2); string cityCountry = queryReader.GetString(3); City foundCity = new City(cityName, cityState,cityCountry,thisCityId); cities.Add(foundCity); } if (queryReader != null) { queryReader.Close(); } } if (conn != null) { conn.Close(); } return cities; }
public void AddCity(City departCity,City arrivalCity) { SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("INSERT INTO flights_cities (flight_id,departing_city_id,returning_city_id) VALUES (@FlightId, @DepartCityId,@ArrivalCityId);", conn); SqlParameter flightIdParameter = new SqlParameter(); flightIdParameter.ParameterName = "@FlightId"; flightIdParameter.Value = this.GetId(); cmd.Parameters.Add(flightIdParameter); SqlParameter departCityParameter = new SqlParameter(); departCityParameter.ParameterName = "@DepartCityId"; departCityParameter.Value = departCity.GetId(); cmd.Parameters.Add(departCityParameter); SqlParameter arrivalCityParameter = new SqlParameter(); arrivalCityParameter.ParameterName = "@ArrivalCityId"; arrivalCityParameter.Value = arrivalCity.GetId(); cmd.Parameters.Add(arrivalCityParameter); cmd.ExecuteNonQuery(); if (conn != null) { conn.Close(); } }
public static List<City> GetAll() { List<City> allCities = new List<City>{}; //Open connection SqlConnection conn = DB.Connection(); conn.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM cities;", conn); SqlDataReader rdr = cmd.ExecuteReader(); //SqlDataReader.Read() method returns boolean - true if more rows, false otherwise while(rdr.Read()) { //Specific methods to get types from DB int cityId = rdr.GetInt32(0); string cityName = rdr.GetString(1); string cityState = rdr.GetString(2); string cityCountry = rdr.GetString(3); City newCity = new City(cityName,cityState,cityCountry, cityId); allCities.Add(newCity); } //More explanation needed... if (rdr != null) { rdr.Close(); } if (conn != null) { conn.Close(); } return allCities; }
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 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); }