public async Task AddCarViaController() { var context = await VehicleDatabaseGenerator.Initialize(); ICarRepository carRepository = new CarRepository(context); ICarService carService = new CarService(carRepository, context); var controller = new CarsController(carService); CreateCarDto createCarDto = new CreateCarDto() { Make = "Audi", Model = "A8", Engine = "8cyl", Doors = 4, Wheels = 4, BodyType = CarBodyType.Sedan }; var response = await controller.AddAsync(createCarDto); Assert.IsType<OkResult>(response); Assert.True(await context .Cars .AnyAsync(car => car.Make == "Audi" && car.Model == "A8" && car.Engine == "8cyl" && car.Doors == 4 && car.Wheels == 4 && car.BodyType == CarBodyType.Sedan && car.VehicleType == VehicleType.Car)); await context.DisposeAsync(); }
private async Task CreateCar(string name, string description) { var car = new CreateCarDto { Name = name, Description = description }; await _carRepository.Add(car); }
public async Task AddCarToInMemoryDatabaseAsync() { var context = await VehicleDatabaseGenerator.Initialize(); ICarRepository carRepository = new CarRepository(context); ICarService carService = new CarService(carRepository, context); CreateCarDto createCarDto = new CreateCarDto() { Make = "Audi", Model = "A8", Engine = "8cyl", Doors = 4, Wheels = 4, BodyType = CarBodyType.Sedan }; await carService.CreateAsync(createCarDto); await context.SaveChangesAsync(); Assert.True(await context .Cars .AnyAsync(car => car.Make == "Audi" && car.Model == "A8" && car.Engine == "8cyl" && car.Doors == 4 && car.Wheels == 4 && car.BodyType == CarBodyType.Sedan && car.VehicleType == VehicleType.Car)); await context.DisposeAsync(); }
public async Task Add(CreateCarDto carDto) { var count = await _carContext.Cars.CountDocumentsAsync(Builders <Car> .Filter.Empty) + 1; var car = new Car(); car.FromDto(carDto, (int)count); await _carContext.Cars.InsertOneAsync(car); }
public async Task Add(CreateCarDto carDto) { await Task.Delay(1); var count = _cars.Count + 1; var car = new Car(); car.FromDto(carDto, (int)count); _cars.Add(car); }
public async Task CreateCar(CreateCarDto createCarDto) { try { var driver = DriverDB[createCarDto.DriverId]; } catch { throw new KeyNotFoundException("Водителя с таким id не существует"); } await CarDB.CreateCar(createCarDto); }
public async Task <ActionResult> AddAsync([FromBody] CreateCarDto createCarDto) { try { await _carService.CreateAsync(createCarDto); return(Ok()); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public void Create(CreateCarDto dto) { var Car = new CarDbEntity() { Brand = dto.Brand, Model = dto.Model, Color = dto.Color, CustomerId = dto.CustomerId, }; _DB.Cars.Add(Car); _DB.SaveChanges(); }
public async Task CreateAsync(CreateCarDto createCarDto) { var createCarCommand = new CreateCarCommand(createCarDto.Make, createCarDto.Model, createCarDto.Engine, createCarDto.Doors, createCarDto.Wheels, createCarDto.BodyType); Car car = _factory.Create(createCarCommand); await _carRepository.AddAsync(car); await _context.SaveChangesAsync(); }
//[AbpAuthorize(PermissionNames.Pages_Cars_Create)] public async Task CreateCar(CreateCarDto input) { var car = new Car { Name = input.Name, Description = input.Description, Inventory = input.Inventory, Price = input.Price, Total = input.Total, CompanyId = input.CompanyId, CarImage = "http://localhost:21021/cars/image/default.jpg" }; await _carRepository.InsertAsync(car); await CurrentUnitOfWork.SaveChangesAsync(); }
public async Task <CarDto> CreateCar(CreateCarDto createCarDto) { var car = new CarEntity() { Id = GetNewId(), Color = createCarDto.Color, Model = createCarDto.Model, DriverId = createCarDto.DriverId }; CarsTable.Rows.Add(car); Console.Out.WriteLine(CarsTable.Rows.Count); await UpdateDatabase(); return(ClientifyCar(car)); }
public async Task <ActionResult> CreateCar([FromBody] CreateCarDto createCarDto) { var car = _mapper.Map <Car>(createCarDto); await _carRepository.AddAsync(car); await _carRepository.Context.SaveChangesAsync(); var carColor = new CarColor(car.Key, createCarDto.ColorId); await _carColorRepository.AddAsync(carColor); var carBrand = new CarBrand(car.Key, createCarDto.CarBrandId); await _carBrandRepository.AddAsync(carBrand); await _carColorRepository.Context.SaveChangesAsync(); return(Ok()); }
public async void Create_CreateSomeCar_NotExistException() { //Arrange var controller = new CarsController(_carRepository); var exceptedName = "car1"; var exceptedDescription = "desc1"; var carDto = new CreateCarDto { Name = exceptedName, Description = exceptedDescription }; //Act await controller.Create(carDto); //Assert var allCars = await _carRepository.Get(); allCars.Count().Should().Be(1); allCars.First().Id.Should().Be(1); allCars.First().Name.Should().Be(exceptedName); allCars.First().Description.Should().Be(exceptedDescription); }
// POST: CarController/Create public IActionResult Create([FromBody] CreateCarDto dTO) { _CarService.Create(dTO); return(Ok(GetRespons())); }
public Task <bool> CreateCarAsync(CreateCarDto CarDto) { throw new System.NotImplementedException(); }
public async Task Create([FromBody] CreateCarDto carDto) { await _carRepository.Add(carDto); }