public async Task UpdateCar_Invoke() { var car = new Car { Id = Guid.NewGuid(), Description = "test", Model = "test" }; var dto = new UpdateCarRequestDto { Id = car.Id.ToString(), Description = "edited_desc", Model = "edited" }; var cars = new List <Car> { car }.AsQueryable(); var mockCarSet = FakeDbSetFactory <Car> .Get(cars); _fakeDb.Setup(m => m.GetSet <Car>()).Returns(mockCarSet.Object); _sut = new CarService(_fakeDb.Object); await _sut.UpdateCar(dto); _fakeDb.Verify(v => v.GetSet <Car>()); _fakeDb.Verify(v => v.SaveDbAsync()); car.Model.Should().Be(dto.Model); car.Description.Should().Be(dto.Description); }
public Product ToProduct(UpdateCarRequestDto carRequestDto) { Product product = _productsMapper.ToProduct(carRequestDto.Product); foreach (UpdateSpecificationRequestDto updateSpecificationRequestDto in carRequestDto.Specifications) { product.Specifications.Add(_specificationMapper.ToSpecification(updateSpecificationRequestDto)); } return(product); }
public async Task UpdateCar(UpdateCarRequestDto request) { var carSet = _dataService.GetSet <Car>(); var car = await carSet.FirstOrDefaultAsync(x => x.Id.ToString() == request.Id); if (car == null) { throw new InvalidCarIdException($"Cannot find car for id: {request.Id}"); } car.Description = request.Description; car.Model = request.Model; car.Year = request.Year; carSet.Update(car); await _dataService.SaveDbAsync(); }
public IHttpActionResult UpdateCar(UpdateCarRequestDto carRequestDto) { _carService.UpdateCar(_carsMapper.ToProduct(carRequestDto)); return(new StatusCodeResult(HttpStatusCode.NoContent, this)); }