public async Task EditBrandAsync_ShouldEditBrandById() { var options = new DbContextOptionsBuilder <TechAndToolsDbContext>() .UseInMemoryDatabase(databaseName: "EditBrandAsync_ShouldEditBrandById") .Options; TechAndToolsDbContext context = new TechAndToolsDbContext(options); await SeedData(context); IBrandService brandService = new BrandService(context); Brand expectedData = context.Brands.First(); expectedData.Name = "New Name"; expectedData.LogoUrl = "New Logo"; expectedData.OfficialSite = "New Site"; BrandServiceModel serviceModel = expectedData.To <BrandServiceModel>(); BrandServiceModel actualData = await brandService.EditAsync(serviceModel); Assert.Equal(expectedData.Id, actualData.Id); Assert.Equal(expectedData.Name, actualData.Name); Assert.Equal(expectedData.LogoUrl, actualData.LogoUrl); Assert.Equal(expectedData.OfficialSite, actualData.OfficialSite); Assert.NotNull(actualData); Assert.NotNull(actualData.Products); }
public async Task <IActionResult> Edit(int id) { BrandServiceModel brandServiceModel = await this.brandService.GetBrandByIdAsync(id); BrandEditInputModel brandEditInputModel = brandServiceModel.To <BrandEditInputModel>(); return(this.View(brandEditInputModel)); }
public async Task <BrandServiceModel> CreateAsync(BrandServiceModel serviceModel) { Brand brand = serviceModel.To <Brand>(); await this.context.Brands.AddAsync(brand); await this.context.SaveChangesAsync(); return(serviceModel); }
public async Task GetBrandById_ShouldReturnBrandByBrandId() { var options = new DbContextOptionsBuilder <TechAndToolsDbContext>() .UseInMemoryDatabase(databaseName: "GetBrandById_ShouldReturnBrandByBrandId") .Options; TechAndToolsDbContext context = new TechAndToolsDbContext(options); await SeedData(context); IBrandService brandService = new BrandService(context); int brandId = 1; BrandServiceModel actualData = await brandService.GetBrandByIdAsync(brandId); Assert.NotNull(actualData); Assert.Equal(brandId, actualData.Id); }
public async Task <BrandServiceModel> EditAsync(BrandServiceModel serviceModel) { Brand brand = this.context.Brands.FirstOrDefault(x => x.Id == serviceModel.Id); if (brand == null) { throw new ArgumentNullException(nameof(brand)); } brand.Name = serviceModel.Name; brand.LogoUrl = serviceModel.LogoUrl; brand.OfficialSite = serviceModel.OfficialSite; this.context.Brands.Update(brand); await this.context.SaveChangesAsync(); return(brand.To <BrandServiceModel>()); }