Exemplo n.º 1
0
        public IActionResult Update(int id, [FromBody] VehiculeUpdateViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var vehicule = repository.Get(id);

            if (vehicule == null)
            {
                return(NotFound());
            }

            var updatedVehicule = new Vehicule
            {
                Id    = id,
                Make  = model.Make,
                Model = model.Model,
                Color = model.Color,
                Type  = model.Type,
                VIN   = model.VIN
            };

            repository.Update(updatedVehicule);
            return(NoContent());
        }
Exemplo n.º 2
0
        public void Update_ExistingIdPassed_ReturnsNoContentResult()
        {
            // Arrange
            int existingId = 2;
            var testVehiculeUpdateViewModel = new VehiculeUpdateViewModel()
            {
                Color = ColorEnum.Blue,
                Make  = "makeNewVehicule",
                Model = "modelNewVehicule",
                Type  = VehicleTypeEnum.Car,
                VIN   = "VINNewVehicule"
            };
            // Act
            var noContentResponse = _controller.Update(existingId, testVehiculeUpdateViewModel);

            // Assert
            Assert.IsInstanceOfType(noContentResponse, typeof(NoContentResult));
        }
Exemplo n.º 3
0
        public void Update_NotExistingIdPassed_ReturnsNotFoundResponse()
        {
            // Arrange
            var testVehiculeUpdateViewModel = new VehiculeUpdateViewModel()
            {
                Color = ColorEnum.Blue,
                Make  = "makeNewVehicule",
                Model = "modelNewVehicule",
                Type  = VehicleTypeEnum.Car,
                VIN   = "VINNewVehicule"
            };
            // Act
            var notFoundResponse = _controller.Update(500, testVehiculeUpdateViewModel);

            // Assert

            Assert.IsInstanceOfType(notFoundResponse, typeof(Microsoft.AspNetCore.Mvc.NotFoundResult));
        }