Esempio n. 1
0
        public async Task <CarDTO> PutAsync(CarCreateDTO carCreateDto)
        {
            Logger.LogTrace($"{nameof(PutAsync)} call");

            var result = await CreateCarService.CreateCar(Mapper.Map <CarUpdateModel>(carCreateDto));

            return(Mapper.Map <CarDTO>(result));
        }
        public async Task CreateCar_CarNotExists_CreatesCar()
        {
            var carUpdateModel         = new CarUpdateModel();
            var addedCar               = new Car();
            var carDataAccessContainer = new Mock <ICarDataAccess>();

            carDataAccessContainer.Setup(t => t.GetCar(carUpdateModel)).ReturnsAsync((Car)null);
            carDataAccessContainer.Setup(t => t.CreateCar(carUpdateModel)).ReturnsAsync(addedCar);

            var carCreateService = new CreateCarService(carDataAccessContainer.Object);
            var result           = await carCreateService.CreateCar(carUpdateModel);

            Assert.AreNotEqual(null, result);
        }
        public void CreateCar_CarExists_ThrowsException()
        {
            var carUpdateModel = new CarUpdateModel();
            var existingCar    = new Car();

            var carDataAccessContainer = new Mock <ICarDataAccess>();

            carDataAccessContainer.Setup(t => t.CreateCar(carUpdateModel)).ReturnsAsync(existingCar);
            carDataAccessContainer.Setup(t => t.GetCar(carUpdateModel)).ReturnsAsync(existingCar);

            var carCreateService = new CreateCarService(carDataAccessContainer.Object);

            Assert.ThrowsAsync <ArgumentException>(async() =>
                                                   await carCreateService.CreateCar(carUpdateModel));
        }