示例#1
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            _category.Name        = tbName.Text;
            _category.Description = tbDescription.Text;

            if (_categoriesService.Edit(_topic, _category))
            {
                Close();
            }
        }
        public async Task EditThrowsArgumentNullExceptionIfNameIsNotValid()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(dbContext);

            var repository = new EfDeletableEntityRepository <Category>(dbContext);
            var service    = new CategoriesService(repository);

            await Assert.ThrowsAsync <ArgumentNullException>(() => service.Edit("Wrong", "Edit"));
        }
        public async Task EditShouldReturnOne()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(dbContext);

            var repository = new EfDeletableEntityRepository <Category>(dbContext);
            var service    = new CategoriesService(repository);

            var actualResult = await service.Edit("Writing", "Edit");

            Assert.Equal(1, actualResult);
        }
        public IActionResult Edit(Guid id, Category_expense category)
        {
            try
            {
                // TODO: Add update logic here
                _categorieRepo.Edit(id, category);

                return(RedirectToAction(nameof(Index)).WithSuccess("Modifier", "vous avez modifié avec succès "));
            }
            catch (Exception e)
            {
                return(View().WithDanger("ERREUR", e.Message));
            }
        }
        public async Task EditShouldChangeCategoryName()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(dbContext);

            var repository = new EfDeletableEntityRepository <Category>(dbContext);
            var service    = new CategoriesService(repository);

            string expectedResult = "Edited";

            await service.Edit("Writing", expectedResult);

            string actualResult = repository.All()
                                  .Where(c => c.Id == 1)
                                  .Select(c => c.Name)
                                  .FirstOrDefault();

            Assert.Equal(expectedResult, actualResult);
        }