public async Task <MainCategoryServiceModel> EditAsync(MainCategoryServiceModel mainCategoryServiceModel) { MainCategory mainCategoryFromDb = this.context.MainCategories .Find(mainCategoryServiceModel.Id); mainCategoryFromDb.Name = mainCategoryServiceModel.Name; this.context.MainCategories.Update(mainCategoryFromDb); await this.context.SaveChangesAsync(); return(mainCategoryFromDb.To <MainCategoryServiceModel>()); }
public async void EditAsyncShouldEditMainCategoryFromDatabaseById() { var options = new DbContextOptionsBuilder <TechAndToolsDbContext>() .UseInMemoryDatabase(databaseName: "EditAsyncShouldEditMainCategoryFromDatabaseById") .Options; var context = new TechAndToolsDbContext(options); await SeedData(context); IMainCategoryService mainCategoryService = new MainCategoryService(context); MainCategory mainCategoryFromDb = context.MainCategories.First(); mainCategoryFromDb.Name = "New Name"; MainCategoryServiceModel expectedResult = mainCategoryFromDb.To <MainCategoryServiceModel>(); await mainCategoryService.EditAsync(expectedResult); var actualResult = context.MainCategories.First(); Assert.Equal(expectedResult.Name, actualResult.Name); }