示例#1
0
        public void UpdatePassengerAddressProperty_ShouldUpdatePassengerAddressProperty()
        {
            // Arrange
            var updatePassengerModel = new UpdatePassengerModel
            {
                Id      = 91,
                Address = "fake town"
            };

            // Act
            var result = _passengersService.UpdatePassenger(updatePassengerModel);

            // Assert
            Assert.AreEqual("fake town", result.Address);
        }
        public ActionResult <Person> UpdatePassenger([FromBody] UpdatePassengerModel model)
        {
            if (!model.Id.HasValue)
            {
                var errorMessage = $"{nameof(model.Id)} should be specified";
                _logger.LogError(errorMessage, HttpContext.Request.Path);

                return(BadRequest(new { ErrorMessage = errorMessage }));
            }

            var updatedPassenger = _passengersService.UpdatePassenger(model);

            if (updatedPassenger == null)
            {
                var errorMessage = $"Person not found with {nameof(updatedPassenger.Id)} {model.Id.Value}";
                _logger.LogError(errorMessage, HttpContext.Request.Path);

                return(BadRequest(new { ErrorMessage = errorMessage }));
            }

            return(Ok(updatedPassenger));
        }