Beispiel #1
0
        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);
        }
Beispiel #2
0
        public IActionResult Delete(string id)
        {
            var inputModel = new CategoryInfoViewModel()
            {
                Id   = id,
                Name = this.categoriesService.GetNameById(id),
            };

            return(this.View(inputModel));
        }
Beispiel #3
0
        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();
        }
Beispiel #4
0
        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;
 }
Beispiel #6
0
        public async Task <IActionResult> Delete(CategoryInfoViewModel input)
        {
            await this.categoriesService.DeleteByIdAsync(input.Id);

            return(this.Redirect("/Administration/Categories/All"));
        }
Beispiel #7
0
        public async Task <IActionResult> Edit(CategoryInfoViewModel input)
        {
            await this.categoriesService.EditAsync(input);

            return(this.Redirect("/Administration/Categories/All"));
        }