Example #1
0
        public async Task <Domain.Car> InsertAsync(CarUpdateModel car)
        {
            var result = await this.Context.AddAsync(this.Mapper.Map <Car>(car));

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Domain.Car>(result.Entity));
        }
Example #2
0
        public async Task <Car> CreateCar(CarUpdateModel carUpdateModel)
        {
            var existingCar = await CarDataAccess.GetCar(carUpdateModel);

            if (existingCar != null)
            {
                throw new ArgumentException("Car with such carId already exists");
            }

            return(await CarDataAccess.CreateCar(carUpdateModel));
        }
Example #3
0
        public async Task <Domain.Car> UpdateAsync(CarUpdateModel car)
        {
            var existing = await this.Get(car);

            var result = this.Mapper.Map(car, existing);

            this.Context.Update(result);

            await this.Context.SaveChangesAsync();

            return(this.Mapper.Map <Domain.Car>(result));
        }
        public async Task <Car> CreateCar(CarUpdateModel carUpdateModel)
        {
            if (carUpdateModel == null)
            {
                throw new ArgumentNullException(nameof(carUpdateModel));
            }

            var entityEntry = await Context.Cars.AddAsync(Mapper.Map <Entities.Car>(carUpdateModel));

            await Context.SaveChangesAsync();

            return(Mapper.Map <Car>(entityEntry.Entity));
        }
        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));
        }
Example #7
0
        public async Task CreateAsync_CarValidationSucceed_CreatesStreet()
        {
            // Arrange
            var car      = new CarUpdateModel();
            var expected = new Car();

            var carDAL = new Mock <ICarDAL>();

            carDAL.Setup(x => x.InsertAsync(car)).ReturnsAsync(expected);

            var carService = new CarService(carDAL.Object);

            // Act
            var result = await carService.CreateAsync(car);

            // Assert
            result.Should().Be(expected);
        }
        public IActionResult UpdateCar([FromRoute] Guid id, [FromBody] CarUpdateModel model)
        {
            var found = Store.FirstOrDefault(c => c.Id == id);

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

            try
            {
                found.Make         = model.Make;
                found.Model        = model.Model;
                found.Power        = model.Power;
                found.Transmission = model.Transmission;

                Logger.LogInformation($" Car with ID {found.Id} has been updated");
                return(Ok());
            }catch (Exception exception)
            {
                Logger.LogError(exception, "Error while updating a car");
                return(StatusCode(500));
            }
        }
Example #9
0
 public async Task <Car> UpdateAsync(CarUpdateModel Car)
 {
     return(await this.CarDal.UpdateAsync(Car));
 }
Example #10
0
 public async Task <Car> CreateAsync(CarUpdateModel Car)
 {
     return(await this.CarDal.InsertAsync(Car));
 }
Example #11
0
 public Task <Car> CreateAsync(CarUpdateModel car)
 {
     return(CarDataAccess.InsertAsync(car));
 }
Example #12
0
 public Task <Car> UpdateAsync(CarUpdateModel car)
 {
     return(CarDataAccess.UpdateAsync(car));
 }