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));
            }
        }
Exemplo n.º 2
0
        public void PostResFlyExTest()
        {
            FlightResDTO flightDTO = new FlightResDTO("", "2019-7-6 23:00", 0, 1, -1);
            var          result    = controller.Post(flightDTO);

            Assert.IsInstanceOf <BadRequestObjectResult>(result.Result);
        }
Exemplo n.º 3
0
        public void PostResTest()
        {
            FlightResDTO flightDTO = new FlightResDTO("", "2019-7-6 23:00", 10, 1, 1);


            var result = controller.Post(flightDTO);

            Assert.IsInstanceOf <ActionResult <IEnumerable <string> > >(result);
        }
        //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 SetUp()
        {
            //Instancia del mapper
            ResFlightMapper = MapperFactory.CreateReservationFlightMapper();

            //Instancia el DTO
            flightDTO = new FlightResDTO("", "2019-7-6 23:00", 1, 1, 1);

            //Instancia el objeto reserva de vuelo
            entity = new FlightRes("", "2019-7-6 23:00", 1, 1, 1);

            //Instancia una lista de DTO
            dtos = new List <FlightResDTO>();
            dtos.Add(flightDTO);

            //Instancia una lsita de entidades
            entities = new List <FlightRes>();
            entities.Add(entity);
        }
        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 una entidad a un dto y la compara con otro dto
        public void CreateDTOTest()
        {
            FlightResDTO flightDTOcopy = ResFlightMapper.CreateDTO(entity);

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

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

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

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


            Assert.AreEqual(a, b);
        }