Ejemplo n.º 1
0
        public async Task Given_ValidCarRequest_UpdatesCar()
        {
            // Arrange.
            var carBeforeUpdate = _fixture.Create <Car>();
            var carAfterUpdate  = _fixture.Create <Car>();

            var request = _fixture.Create <UpdateCarRequest>();

            request.Id = carBeforeUpdate.Id;

            _carRepositoryCache.GetAllCars().Returns(new List <Car>()
            {
                carBeforeUpdate
            });
            await _carRepository.Update(Arg.Any <Car>());

            _requestMapper.Map(Arg.Any <UpdateCarRequest>()).Returns(carAfterUpdate);

            // Act.
            var response = await _sut.Update(request);

            // Assert.
            response.Should().Be(carAfterUpdate);
            _carRepositoryCache.Received(1).InvalidateCache();
            _carRepository.Received(1).Update(Arg.Is <Car>(carAfterUpdate));
        }
Ejemplo n.º 2
0
        public async Task Given_ValidCarRequest_Returns_Car()
        {
            // Arrange.
            var carId       = _fixture.Create <int>();
            var carToCreate = _fixture.Create <Car>();
            var request     = _fixture.Create <AddCarRequest>();

            _carRepository.Add(Arg.Any <Car>()).Returns(carId);
            _requestMapper.Map(Arg.Any <AddCarRequest>()).Returns(carToCreate);

            // Act.
            var response = await _sut.AddCar(request);

            // Assert.
            response.Id.Should().Be(carId);
            _carRepositoryCache.Received(1).InvalidateCache();
        }