Пример #1
0
        public void SDHP_UpdateVehicle()
        {
            //Arrange
            var entity = new VehicleEntity();

            //Act
            var result = _vehicleCommands.UpdateVehicle(entity);

            //Assert
            result.ShouldBeTrue();
        }
Пример #2
0
        public IActionResult PartialUpdateVehicle([FromRoute] string vin, [FromBody] VehicleModel model)
        {
            //TODO: add guard pattern here for this check
            if (string.IsNullOrWhiteSpace(vin) || vin.Length != 17)
            {
                return(BadRequest(vin));
            }

            //TODO: replace with Guard
            if (model == null)
            {
                return(NoContent());
            }

            if (!_vehicleModelValidation.Validate(model))
            {
                return(BadRequest());
            }

            var entity = _vehicleQueries.GetVehicleByVin(model.Vin);

            _vehicleModelMapper.UpdateVehicleEntityFromModel(entity, model, true);

            var updated = _vehicleCommands.UpdateVehicle(entity);

            if (!updated)
            {
                return(BadRequest());
            }

            //TODO: replace this with an inteligent way of doing it - JS 29/05/218
            var apiUri = Request.GetBaseUri() + Request?.Path.Value;

            var links = new List <HateoasLink>
            {
                new HateoasLink("vehicle.update.full", $"{apiUri}", HttpVerbs.Put),
                new HateoasLink("vehicle.get", $"{apiUri}", HttpVerbs.Get),
            };

            var response = new HateoasResponseObject <VehicleModel>(model, links);

            return(Ok(response));
        }