public async Task Given_A_City_Update_Request_Validate_City_Mapped()
        {
            //Arrange
            var cityUpdate = new CityUpdateTransferModel()
            {
                TouristRating       = 1,
                DateEstablished     = new DateTime(2000, 1, 1),
                EstimatedPopulation = 500
            };

            var mappedCity = new City();
            var service    = new ServiceCore(_cityRepository.Object, _weatherService.Object, _countryService.Object, _mapper);

            _cityRepository.Setup(x => x.UpdateCityAsync(It.IsAny <int>(), It.IsAny <City>()))
            .Callback <int, City>((id, city) =>
            {
                mappedCity = city;
            }).ReturnsAsync(true);

            //Act
            var cities = await service.UpdateCityAsync(1, cityUpdate);

            //Assert
            Assert.AreEqual(cityUpdate.TouristRating, mappedCity.TouristRating);
            Assert.AreEqual(cityUpdate.EstimatedPopulation, mappedCity.EstimatedPopulation);
            Assert.AreEqual(cityUpdate.DateEstablished, mappedCity.DateEstablished);
        }
Example #2
0
        public async Task <ActionResult> UpdateCity(int id, [FromBody] CityUpdateTransferModel cityUpdate)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (!await _serviceCore.CityExistsAsync(id))
            {
                return(NotFound(id));
            }

            var response = await _serviceCore.UpdateCityAsync(id, cityUpdate);

            return(Ok());
        }
 public async Task <bool> UpdateCityAsync(int id, CityUpdateTransferModel cityUpdate)
 {
     return(await _cityRepository.UpdateCityAsync(id, _mapper.Map <CityUpdateTransferModel, City>(cityUpdate)));
 }