Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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();
              }
        }
Exemplo n.º 4
0
        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();
              }
        }