public async Task CreateSupplierAsyncShouldCreateSupplierSuccessfully() { var options = new DbContextOptionsBuilder <MyCalisthenicAppDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var dbContext = new MyCalisthenicAppDbContext(options); var mockMapper = new MapperConfiguration(cfg => { cfg.AddProfile(new MyCalisthenicAppProfile()); }); var mapper = mockMapper.CreateMapper(); var suppliersService = new SuppliersService(dbContext, mapper); var supplierModel = new SupplierAdminCreateViewModel { Name = SupplierName, PriceToHome = SupplierPriceToHome, PriceToOffice = SupplierPriceToOffice, }; await suppliersService.CreateSupplierAsync(supplierModel); var actual = await dbContext.Suppliers.FirstOrDefaultAsync(); Assert.Equal(supplierModel.Name, actual.Name); }
public async Task <IActionResult> Create(SupplierAdminCreateViewModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } await this.suppliersService.CreateSupplierAsync(inputModel); return(this.RedirectToAction("All")); }
public async Task CreateSupplierAsync(SupplierAdminCreateViewModel inputModel) { var supplier = new Supplier { Name = inputModel.Name, PriceToHome = inputModel.PriceToHome, PriceToOffice = inputModel.PriceToOffice, LogoUrl = inputModel.LogoUrl, }; await this.dbContext.Suppliers.AddAsync(supplier); await this.dbContext.SaveChangesAsync(); }