public void SDHP_PartialUpdate()
        {
            //Arrange
            var entity = ValidVehicleEntity;

            _vehicleInteriorColorQueries.Setup(x => x.GetId("Yellow")).Returns(19);
            _vehicleExteriorColorQueries.Setup(x => x.GetId("Red")).Returns(14);

            //Act
            _vehicleModelMapper.UpdateVehicleEntityFromModel(entity, ValidVehicleModelPartialUpdate, true);

            //Assert
            entity.ShouldNotBeNull();
            entity.FullVin.ShouldEqual("JM1CW2BLE0I106097");
            entity.PartialVin.ShouldEqual("JM1CW2BLE0");
            entity.YearId.ShouldEqual(14);
            entity.MakeId.ShouldEqual(16);
            entity.ModelId.ShouldEqual(216);
            entity.TrimId.ShouldEqual(1260);
            entity.EngineTypeId.ShouldEqual(25);
            entity.TransmissionId.ShouldEqual(4);
            entity.DriveTrainId.ShouldEqual(2);
            entity.BodyTypeId.ShouldEqual(13);
            entity.VehicleTypeId.ShouldEqual(5);
            entity.InteriorColorId.ShouldEqual(19);
            entity.ExteriorColorId.ShouldEqual(14);
        }
Ejemplo n.º 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));
        }