public void Execute() { DAOFactory daoFactory = DAOFactory.GetFactory(DAOFactory.Type.Postgres); PostgresCruiserDAO layoverDao = (PostgresCruiserDAO)daoFactory.GetCruiserDAO(); LayoverMapper layoverMapper = MapperFactory.CreateLayoverMapper(); Layover layover = (Layover)layoverMapper.CreateEntity(_layoverDTO); _layoverDTO = layoverMapper.CreateDTO(layoverDao.AddLayover(layover)); }
public void AddLayoverTest() { var id = _cruiserDao.AddCruiser(_cruiser); _addedCruiserList.Add(id); _layover = new Layover(id, "2019-12-2", "2019-12-6", 250, 1, 2); var layover = _cruiserDao.AddLayover(_layover); Assert.NotNull(layover); }
public void GetLayoversForResTest() { var id = _cruiserDao.AddCruiser(_cruiser); _addedCruiserList.Add(id); _layover = new Layover(id, "2019/12/2", "2019/12/3", 250, 1, 2); var layover = _cruiserDao.AddLayover(_layover); List <Layover> layoverList = _cruiserDao.GetLayoversForRes(1, 2); Assert.IsTrue(layoverList.Count > 0); }
public void DeleteLayover() { var id = _cruiserDao.AddCruiser(_cruiser); _addedCruiserList.Add(id); _layover = new Layover(id, "2019-12-2", "2019-12-6", 250, 1, 2); var layover = _cruiserDao.AddLayover(_layover); var deletedLayover = _cruiserDao.DeleteLayover(layover.Id); Assert.AreEqual(layover.Id, deletedLayover); }
public void Setup() { _cruiser = new Cruiser("The great seeker of wonder", true, 220, 200, "A big one", "A tender line", "I suppose a picture is in order"); _cruiserMapper = MapperFactory.CreateCruiserMapper(); _cruiserDTOList = new List <CruiserDTO>(); _cruiserList = new List <Cruiser>(); _layover = new Layover(0, "02/12/2019", "05/01/2020", 250, 1, 2); _layoverMapper = MapperFactory.CreateLayoverMapper(); _layoverDTOList = new List <LayoverDTO>(); _layoverList = new List <Layover>(); }
/// <summary> /// Metodo para agregar un layover a un crucero. /// </summary> /// <param name="layover">Id del crucero al que se le agregara la escala</param> /// <returns>Lista de layovers (escalas) de un crucero</returns> /// <exception cref="DatabaseException"> /// Lanzada si ocurre un fallo al ejecutar la funcion en la base de /// datos /// </exception> /// <exception cref="CruiserNotFoundException">Lanzada si el id del crucero en el layover no corresponde con ningun crucero guardado</exception> public static Layover AddLayover(Layover layover) { var cruiserTable = PgConnection.Instance.ExecuteFunction("GetShip(@ship_id)", layover.CruiserId); if (cruiserTable.Rows.Count == 0) { throw new CruiserNotFoundException("Crucero no encontrado"); } var table = PgConnection.Instance.ExecuteFunction( "addcruise(@cruiserId,@departureDate,@arrivalDate,@price,@LocDeparture,@locArrival)", layover.CruiserId, layover.DepartureDate, layover.ArrivalDate, layover.Price, layover.LocDeparture, layover.LocArrival); var id = Convert.ToInt32(table.Rows[0][0]); layover.Id = id; return(layover); }
/// <summary> /// Metodo para obtener todos los layovers (escalas) de un crucero. /// </summary> /// <param name="cruiserId">Id del crucero del cual se desea obtener los escalas</param> /// <returns>Lista de layovers (escalas) de un crucero</returns> /// <exception cref="DatabaseException"> /// Lanzada si ocurre un fallo al ejecutar la funcion en la base de /// datos /// </exception> public static List <Layover> GetLayovers(int cruiserId) { List <Layover> layovers = new List <Layover>(); var table = PgConnection.Instance.ExecuteFunction("getCruisers(@cruiserId)", cruiserId); for (int i = 0; i < table.Rows.Count; i++) { var id = Convert.ToInt32(table.Rows[i][0]); var departureDate = Convert.ToString(table.Rows[i][2]); var arrivalDate = Convert.ToString(table.Rows[i][3]); var price = Convert.ToDecimal(table.Rows[i][4]); var locDeparture = Convert.ToInt32(table.Rows[i][5]); var locArrival = Convert.ToInt32(table.Rows[i][6]); Layover layover = new Layover(id, cruiserId, departureDate, arrivalDate, price, locDeparture, locArrival); layovers.Add(layover); } return(layovers); }
/// <summary> /// Metodo para validar todos los campos de un layover /// </summary> /// <param name="layover">Objeto que contiene toda la informacion del layover a validar</param> public static void Validate(Layover layover) { if (string.IsNullOrEmpty(layover.ArrivalDate)) { throw new InvalidAttributeException("Arrival Date is required"); } if (string.IsNullOrEmpty(layover.DepartureDate)) { throw new InvalidAttributeException("Departure Date is required"); } if (layover.LocDeparture == 0) { throw new InvalidAttributeException("Departure location id is required"); } if (layover.LocArrival == 0) { throw new InvalidAttributeException("Arrival Location id is required"); } }
/// <summary> /// Metodo para obtener todos los layovers (escalas) de un crucero. /// </summary> /// <param name="departure">Id del la locacion de salida del crucero</param> /// <param name="arrival">Id de la locacion de llegada del crucero</param> /// <returns>Lista de layovers (escalas) de un crucero</returns> /// <exception cref="DatabaseException"> /// Lanzada si ocurre un fallo al ejecutar la funcion en la base de /// datos /// </exception> /// <exception cref="LayoverNotFoundException">Si no se encontraron rutas para las locaciones ingresadass</exception> public static List <Layover> GetLayoversForRes(int departure, int arrival) { List <Layover> layovers = new List <Layover>(); var table = PgConnection.Instance.ExecuteFunction("getCruiseByLocation(@departure,@arrival)", departure, arrival); if (table.Rows.Count == 0) { throw new LayoverNotFoundException("No se encontraron rutas disponibles para esas ciudades"); } for (int i = 0; i < table.Rows.Count; i++) { var id = Convert.ToInt32(table.Rows[i][0]); var shipid = Convert.ToInt32(table.Rows[i][1]); var departureDate = Convert.ToString(table.Rows[i][2]); var arrivalDate = Convert.ToString(table.Rows[i][3]); var price = Convert.ToDecimal(table.Rows[i][4]); var locDeparture = Convert.ToInt32(table.Rows[i][5]); var locArrival = Convert.ToInt32(table.Rows[i][6]); Layover layover = new Layover(id, shipid, departureDate, arrivalDate, price, locDeparture, locArrival); layovers.Add(layover); } return(layovers); }
public void NullLocArrivalTest() { var layover = new Layover(1, "2019-01-01", "2019-01-02", 2000, 1, 0); Assert.Throws <InvalidAttributeException>(() => layover.Validate()); }
public void EmptyArrivalDateTest() { var layover = new Layover(1, "2019-01-01", "", 2000, 0, 2); Assert.Throws <InvalidAttributeException>(() => layover.Validate()); }
public void InvalidLocationArrivalTest() { var _layover = new Layover(0, "05/01/2020", "05/01/2020", 250, 1, 0); Assert.Throws <InvalidAttributeException>(() => LayoverValidator.Validate(_layover)); }
public void EmptyDepartureTest() { var _layover = new Layover(0, "05/01/2020", null, 250, 1, 2); Assert.Throws <InvalidAttributeException>(() => LayoverValidator.Validate(_layover)); }
public void AddLayoverTest_Returns_CruiserNotFoundException() { _layover = new Layover(0, "2019-12-2", "2019-12-6", 250, 1, 2); Assert.Throws <CruiserNotFoundException>(() => _cruiserDao.AddLayover(_layover)); }
public void CreateLayoverEntityTest() { _layover = _layoverMapper.CreateEntity(_layoverDTO); Assert.AreEqual(_layoverDTO.DepartureDate, _layover.DepartureDate); }