public async Task EditAsync_WithCorrectData_ShouldSuccessfullyEdit() { var testName = "TestName"; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var categoriesService = new CategoriesService(categoryRepository); var inputModel = new CreateCategoryInputModel() { Name = testName, }; await categoriesService.CreateAsync(inputModel); var category = categoryRepository.All().FirstOrDefault(c => c.Name == testName); // Act var expectedCategoryName = "Edited_TestName"; var editInputModel = new CategoryInfoViewModel() { Id = category.Id, Name = expectedCategoryName, }; await categoriesService.EditAsync(editInputModel); var actualCategoryName = category.Name; // Assert category = await categoryRepository.GetByIdWithDeletedAsync(category.Id); Assert.Equal(expectedCategoryName, actualCategoryName); }
public IActionResult Delete(string id) { var inputModel = new CategoryInfoViewModel() { Id = id, Name = this.categoriesService.GetNameById(id), }; return(this.View(inputModel)); }
public async Task EditAsync(CategoryInfoViewModel categoryInfoViewModel) { var categoryFromDb = await this.categoryRepository .GetByIdWithDeletedAsync(categoryInfoViewModel.Id); if (categoryFromDb == null) { throw new ArgumentNullException( string.Format(InvalidCategoryIdErrorMessage, categoryInfoViewModel.Id)); } categoryFromDb.Name = categoryInfoViewModel.Name; this.categoryRepository.Update(categoryFromDb); await this.categoryRepository.SaveChangesAsync(); }
public async Task EditAsync_WithIncorrectData_ShouldThrowArgumentNullException() { var incorrectId = Guid.NewGuid().ToString(); // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var categoryRepository = new EfDeletableEntityRepository <Category>(context); var categoriesService = new CategoriesService(categoryRepository); var editInputModel = new CategoryInfoViewModel() { Id = incorrectId, Name = "SomeTestName", }; // Act // Assert await Assert.ThrowsAsync <ArgumentNullException>(async() => { await categoriesService.EditAsync(editInputModel); }); }
public CategoryInfoView(CategoryInfoViewModel viewModel) { InitializeComponent(); DataContext = viewModel; }
public async Task <IActionResult> Delete(CategoryInfoViewModel input) { await this.categoriesService.DeleteByIdAsync(input.Id); return(this.Redirect("/Administration/Categories/All")); }
public async Task <IActionResult> Edit(CategoryInfoViewModel input) { await this.categoriesService.EditAsync(input); return(this.Redirect("/Administration/Categories/All")); }