Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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();
        }
Example #4
0
 public IHttpActionResult UpdateCar(UpdateCarRequestDto carRequestDto)
 {
     _carService.UpdateCar(_carsMapper.ToProduct(carRequestDto));
     return(new StatusCodeResult(HttpStatusCode.NoContent, this));
 }