Ejemplo n.º 1
0
        public ActionResult <IEnumerable <string> > Post(FlightResDTO flightDTO)
        {
            try{
                //Crea la entidad por medio del mapper devuelvo del factory
                ReservationFlightMapper ResFlightMapper = MapperFactory.CreateReservationFlightMapper();
                Entity entity = ResFlightMapper.CreateEntity(flightDTO);

                //Instancia el comando por medio del factory pasandole la entidad al constructor
                AddReservationFlightCommand command = CommandFactory.CreateAddReservationFlightCommand((FlightRes)entity);

                //Ejecuta y obtiene el resultado del comando
                command.Execute();
                int _id = command.GetResult();


                return(StatusCode(200, "Se agrego satisfactoriamente id: " + _id));
            }
            catch (ValidationErrorException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
        //Añadir reserva de vuelo con vuelo inválido
        public void AddReservationFlightFlyExCommandTest()
        {
            FlightResDTO flightDTO = new FlightResDTO("", "2019-7-6 23:00", 1, 1, -1);

            //Crea la entidad por medio del mapper devuelvo del factory
            ReservationFlightMapper ResFlightMapper = MapperFactory.CreateReservationFlightMapper();
            Entity entity = ResFlightMapper.CreateEntity(flightDTO);

            //Instancia el comando por medio del factory pasandole la entidad al constructor
            AddReservationFlightCommand command = CommandFactory.CreateAddReservationFlightCommand((FlightRes)entity);

            Assert.Throws <ValidationErrorException>(delegate { command.Execute(); });
        }
        public void AddReservationFlightCommandTest()
        {
            FlightResDTO flightDTO = new FlightResDTO("", "2019-7-6 23:00", 1, 1, 1);

            //Crea la entidad por medio del mapper devuelvo del factory
            ReservationFlightMapper ResFlightMapper = MapperFactory.CreateReservationFlightMapper();
            Entity entity = ResFlightMapper.CreateEntity(flightDTO);

            //Instancia el comando por medio del factory pasandole la entidad al constructor
            AddReservationFlightCommand command = CommandFactory.CreateAddReservationFlightCommand((FlightRes)entity);

            //Ejecuta y obtiene el resultado del comando
            command.Execute();

            Assert.AreNotEqual(null, command.GetResult());
        }
        public void DeleteReservationCommandTest()
        {
            FlightResDTO flightDTO = new FlightResDTO("", "2019-7-6 23:00", 1, 1, 1);

            //Crea la entidad por medio del mapper devuelvo del factory
            ReservationFlightMapper ResFlightMapper = MapperFactory.CreateReservationFlightMapper();
            Entity entity = ResFlightMapper.CreateEntity(flightDTO);

            //Instancia el comando por medio del factory pasandole la entidad al constructor
            AddReservationFlightCommand command = CommandFactory.CreateAddReservationFlightCommand((FlightRes)entity);

            //Ejecuta y obtiene el resultado del comando
            command.Execute();
            int id_res = command.GetResult();

            //Obtiene comando para borrar
            DeleteReservationCommand command2 = CommandFactory.CreateDeleteReservationCommand(id_res);

            command2.Execute();
        }
        //Convierte un dto a una entidad y la compara con otra entidad
        public void CreateEntityTest()
        {
            FlightRes entitycopy = ResFlightMapper.CreateEntity(flightDTO);

            List <String> a = new List <String>();

            a.Add(entity._seatNum.ToString());
            a.Add(entity._timestamp.ToString());
            a.Add(entity._numPas.ToString());
            a.Add(entity._id_user.ToString());
            a.Add(entity._id_fli.ToString());

            List <String> b = new List <String>();

            b.Add(entitycopy._seatNum.ToString());
            b.Add(entitycopy._timestamp.ToString());
            b.Add(entitycopy._numPas.ToString());
            b.Add(entitycopy._id_user.ToString());
            b.Add(entitycopy._id_fli.ToString());


            Assert.AreEqual(a, b);
        }