public void GetLocationByIdCommand_LocationNotFoundException_Test()
 {
     Assert.Throws <LocationNotFoundException>(() =>
     {
         GetLocationByIdCommand commandId = CommandFactory.GetLocationByIdCommand(999999);
         commandId.Execute();
     });
 }
        public void GetLocationByIdCommandTest()
        {
            GetLocationByIdCommand commandId = CommandFactory.GetLocationByIdCommand(77);

            commandId.Execute();
            location = commandId.GetResult();
            Assert.NotNull(location);
        }
        /// <summary>
        ///     Valida que los campos de un <see cref="Hotel" /> sean correctos, lanzando excepciones
        ///     segun los errores detectados.
        /// </summary>
        /// <exception cref="RequiredAttributeException">Algun atributo requerido estaba como null</exception>
        /// <exception cref="InvalidAttributeException">Algun atributo tenia un valor invalido</exception>
        public static void Validate(Hotel hotel)
        {
            if (hotel == null)
            {
                throw new RequiredAttributeException(
                          "El hotel no fue especificado y es requerido");
            }
            if (hotel.Name == null)
            {
                throw new RequiredAttributeException(
                          "El nombre del hotel no fue especificado y es requerido");
            }
            if (hotel.AddressSpecification == null)
            {
                throw new RequiredAttributeException(
                          "La direccion especifica del hotel es necesaria");
            }
            if (hotel.Location == null)
            {
                throw new RequiredAttributeException("La ubicacion del hotel es necesaria");
            }
            if (hotel.AmountOfRooms <= 0)
            {
                throw new InvalidAttributeException(
                          "La cantidad de habitaciones debe ser mayor a 1");
            }
            if (hotel.RoomCapacity <= 0)
            {
                throw new InvalidAttributeException(
                          "La capacidad de personas por habitacion debe ser mayor a 1");
            }
            if (hotel.Stars < 1 || hotel.Stars > 5)
            {
                throw new InvalidAttributeException(
                          "La cantidad de estrellas debe estar entre 1 y 5");
            }
            if (hotel.PricePerRoom < 0)
            {
                throw new InvalidAttributeException(
                          "El precio por habitacion no puede ser negativo");
            }

            try
            {
                GetLocationByIdCommand commandId = CommandFactory.GetLocationByIdCommand(hotel.Location.Id);
                commandId.Execute();
            }
            catch (LocationNotFoundException)
            {
                throw new InvalidAttributeException(
                          $"El location (id: {hotel.Location.Id}) no es valido");
            }
        }
        public HotelBuilder LocatedAt(int locationid)
        {
            try
            {
                GetLocationByIdCommand commandId = CommandFactory.GetLocationByIdCommand(locationid);
                commandId.Execute();
                _hotel.Location = commandId.GetResult();
            }catch (LocationNotFoundException)
            {
                _hotel.Location = null;
            }

            return(this);
        }
        public void DtoShouldSerializableTest()
        {
            GetLocationByIdCommand command = CommandFactory.GetLocationByIdCommand(_hotel.Location.Id);
            Location location = command.GetResult();
            HotelDTO HotelDTO = new HotelDTO(_hotel.Name, _hotel.AmountOfRooms,
                                             _hotel.RoomCapacity, _hotel.IsActive, _hotel.AddressSpecification,
                                             _hotel.PricePerRoom, _hotel.Website, _hotel.Phone, _hotel.Picture,
                                             _hotel.Stars, location);

            HotelDTO.AvailableRooms = 1000;
            var respuesta = HotelDTO.ShouldSerializeAvailableRooms();

            Assert.AreEqual(respuesta, true);
        }
示例#6
0
        public ActionResult <IEnumerable <LocationDTO> > GetCitiesByCountry([FromRoute] int countryId)
        {
            try
            {
                GetLocationByIdCommand commandId = CommandFactory.GetLocationByIdCommand(countryId);
                commandId.Execute();

                LocationMapper            locationMapper    = MapperFactory.createLocationMapper();
                GetCitiesByCountryCommand commandIByCountry = CommandFactory.GetCitiesByCountryCommand(countryId);
                commandIByCountry.Execute();
                var result = commandIByCountry.GetResult();
                _logger?.LogInformation($"Obtenida las ciudades por pais id {countryId} exitosamente");
                return(locationMapper.CreateDTOList(result));
            }
            catch (LocationNotFoundException ex)
            {
                _logger?.LogWarning($"Location con id {countryId} no encontrada");
                return(NotFound($"Location with id {countryId} not found"));
            }
        }
示例#7
0
        public HotelDTO(int id, string name, int amountOfRooms, int roomCapacity,
                        bool isActive, string addressSpecs, decimal pricePerRoom, string website, string phone,
                        string picture, int stars, int locationId)
        {
            this.Id                   = id;
            this.Name                 = name;
            this.AmountOfRooms        = amountOfRooms;
            this.RoomCapacity         = roomCapacity;
            this.IsActive             = isActive;
            this.AddressSpecification = addressSpecs;
            this.PricePerRoom         = pricePerRoom;
            this.Website              = website;
            this.Phone                = phone;
            this.Picture              = picture;
            this.Stars                = stars;

            GetLocationByIdCommand commandId = CommandFactory.GetLocationByIdCommand(locationId);

            commandId.Execute();
            this.Location = commandId.GetResult();
        }