public ActionResult <HotelDTO> Create([FromBody] HotelDTO hotelDTO) { try { HotelMapper hotelMapper = MapperFactory.createHotelMapper(); Entity entity = hotelMapper.CreateEntity(hotelDTO); AddHotelCommand command = CommandFactory.createAddHotelCommand((Hotel)entity); command.Execute(); int idFromData = command.GetResult(); _logger?.LogInformation($"Obtenido el id = {idFromData} el Hotel exitosamente al agregar"); GetHotelByIdCommand commandId = CommandFactory.GetHotelByIdCommand(idFromData); commandId.Execute(); var result = commandId.GetResult(); _logger?.LogInformation($"Obtenido el hotel exitosamente por Id = {idFromData}"); DTO lDTO = hotelMapper.CreateDTO(result); return(CreatedAtAction("Get", "hotels", lDTO)); } catch (RequiredAttributeException e) { _logger?.LogWarning($"Atributo requerido no recibido al agregar Hotel: {e.Message}"); return(new BadRequestObjectResult(new ErrorMessage(e.Message))); } catch (InvalidAttributeException e) { _logger?.LogWarning($"Valor del atributo es invalido al agregar Hotel: {e.Message}"); return(new BadRequestObjectResult(new ErrorMessage(e.Message))); } }
public void Update_ValidHotel_UpdatedDataReturned() { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotelentity); AddHotel.Execute(); var insertedHotelId = AddHotel.GetResult(); _insertedHotels.Add(insertedHotelId); _hotel.Name = "Upated Name"; _hotel.PricePerRoom = 999; _hotel.Phone = "+58 4241364429"; _hotel.Website = "http://updatedhotel.com"; _hotel.AmountOfRooms = 99; _hotel.AddressSpecification = "New Address specification"; var result = _hotelsController.Update(insertedHotelId, _hotel); var casted = (OkObjectResult)result.Result; var updatedHotel = (HotelDTO)casted.Value; Assert.AreEqual(_hotel.Name, updatedHotel.Name); Assert.AreEqual(_hotel.PricePerRoom, updatedHotel.PricePerRoom); Assert.AreEqual(_hotel.Phone, updatedHotel.Phone); Assert.AreEqual(_hotel.Website, updatedHotel.Website); Assert.AreEqual(_hotel.AmountOfRooms, updatedHotel.AmountOfRooms); Assert.AreEqual(_hotel.AddressSpecification, updatedHotel.AddressSpecification); }
public void UpdateHotel_ExistingHotel_DataIsUpdated() { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotel); AddHotel.Execute(); var insertedHotelId = AddHotel.GetResult(); _insertedHotels.Add(insertedHotelId); _hotel.Name = "Upated Name"; _hotel.PricePerRoom = 999; _hotel.Phone = "+58 4241364429"; _hotel.Website = "http://updatedhotel.com"; _hotel.AmountOfRooms = 99; _hotel.AddressSpecification = "New Address specification"; UpdateHotelCommand UpdateHotel = CommandFactory.UpdateHotelCommand(insertedHotelId, _hotel); UpdateHotel.Execute(); var updatedHotel = UpdateHotel.GetResult(); Assert.AreEqual(_hotel.Name, updatedHotel.Name); Assert.AreEqual(_hotel.PricePerRoom, updatedHotel.PricePerRoom); Assert.AreEqual(_hotel.Phone, updatedHotel.Phone); Assert.AreEqual(_hotel.Website, updatedHotel.Website); Assert.AreEqual(_hotel.AmountOfRooms, updatedHotel.AmountOfRooms); Assert.AreEqual(_hotel.AddressSpecification, updatedHotel.AddressSpecification); }
public void AddHotel_HotelWithInvalidLocation_ExceptionThrown() { Assert.Throws <InvalidAttributeException>(() => { _hotel.Location.Id = 99999; AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotel); AddHotel.Execute(); }); }
public void GetHotelImageTest() { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotelentity); AddHotel.Execute(); var insertedHotelId = AddHotel.GetResult(); _insertedHotels.Add(insertedHotelId); var base64ImageCode = _hotelsController.GetHotelImage(insertedHotelId); Assert.IsNotNull(base64ImageCode); }
public void GetById_ValidHotelId_OkResultReturned() { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotelentity); AddHotel.Execute(); var savedHotelId = AddHotel.GetResult(); _insertedHotels.Add(savedHotelId); var result = _hotelsController.GetById(savedHotelId); Assert.IsInstanceOf <OkObjectResult>(result.Result); }
public void Get_ValidLocationId_HotelsInLocationReturned() { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotelentity); AddHotel.Execute(); var savedHotelId = AddHotel.GetResult(); _insertedHotels.Add(savedHotelId); var result = _hotelsController.Get(HotelTestSetup.LOCATION_ID); Assert.AreEqual(1, result.Value.Count()); }
public void Update_HotelWithoutName_BadRequestReturned() { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotelentity); AddHotel.Execute(); var insertedHotelId = AddHotel.GetResult(); _insertedHotels.Add(insertedHotelId); _hotel.Name = null; var result = _hotelsController.Update(insertedHotelId, _hotel); Assert.IsInstanceOf <BadRequestObjectResult>(result.Result); }
public void AddHotel_ValidHotel_NoExceptionThrown() { Assert.DoesNotThrow(() => { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotel); AddHotel.Execute(); var addedHotelId = AddHotel.GetResult(); GetHotelByIdCommand GetHotelById = CommandFactory.GetHotelByIdCommand(addedHotelId); GetHotelById.Execute(); _insertedHotels.Add(addedHotelId); }); }
public void Delete_ValidHotelId_OkResultReturned() { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotelentity); AddHotel.Execute(); var savedHotelId = AddHotel.GetResult(); var deleteResult = _hotelsController.Delete(savedHotelId); Assert.IsInstanceOf <OkResult>(deleteResult); GetHotelByIdCommand GetHotelById = CommandFactory.GetHotelByIdCommand(savedHotelId); Assert.Throws <HotelNotFoundException>(() => GetHotelById.Execute()); }
public void GetHotelById_ValidHotelId_CorrectDataReturned() { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotel); AddHotel.Execute(); var hotelId = AddHotel.GetResult(); _insertedHotels.Add(hotelId); GetHotelByIdCommand GetHotelById = CommandFactory.GetHotelByIdCommand(hotelId); GetHotelById.Execute(); var getHotel = GetHotelById.GetResult(); Assert.AreEqual(hotelId, getHotel.Id); }
public void Update_ValidHotel_OkResultReturned() { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotelentity); AddHotel.Execute(); var insertedHotelId = AddHotel.GetResult(); _insertedHotels.Add(insertedHotelId); _hotel.Name = "Upated Name"; _hotel.PricePerRoom = 999; _hotel.Phone = "+58 4241364429"; _hotel.Website = "http://updatedhotel.com"; _hotel.AmountOfRooms = 99; _hotel.AddressSpecification = "New Address specification"; var result = _hotelsController.Update(insertedHotelId, _hotel); Assert.IsInstanceOf <OkObjectResult>(result.Result); }
public void DeleteHotel_ValidHotelId_HotelNotFound() { Assert.Throws <HotelNotFoundException>(() => { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotel); AddHotel.Execute(); var addedHotelId = AddHotel.GetResult(); GetHotelByIdCommand GetHotelById = CommandFactory.GetHotelByIdCommand(addedHotelId); GetHotelById.Execute(); DeleteHotelCommand DeleteHotel = CommandFactory.DeleteHotelCommand(addedHotelId); DeleteHotel.Execute(); GetHotelById = CommandFactory.GetHotelByIdCommand(addedHotelId); GetHotelById.Execute(); }); }
public void GetHotelsTest() { int i = 0; while (i < 3) { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotel); AddHotel.Execute(); var hotelId = AddHotel.GetResult(); _insertedHotels.Add(hotelId); i++; } GetHotelsCommand GetHotels = CommandFactory.GetHotelsCommand(); GetHotels.Execute(); var hotelsList = GetHotels.GetResult(); Assert.True(hotelsList.Count >= 3); }
public void GetHotelsByCity_HotelsInCity_CorrectDataReturned() { int i = 0; while (i < 3) { AddHotelCommand AddHotel = CommandFactory.createAddHotelCommand(_hotel); AddHotel.Execute(); var hotelId = AddHotel.GetResult(); _insertedHotels.Add(hotelId); i++; } GetHotelsByCityCommand GetHotelsByCity = CommandFactory.GetHotelsByCityCommand(HotelTestSetup.LOCATION_ID); GetHotelsByCity.Execute(); var found = GetHotelsByCity.GetResult(); Assert.AreEqual(3, found.Count); }