Exemplo 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();
        }