public async Task DeleteWorkCorrectlyWithNotCorectId()
        {
            var categories = new List <Category>();

            for (int i = 0; i < 5; i++)
            {
                var category = new Category()
                {
                    Name = "Test" + i.ToString(),
                };
                categories.Add(category);
            }

            await this.dbContext.Categories.AddRangeAsync(categories);

            await this.dbContext.SaveChangesAsync();

            var service = new CategoriesService(this.categoryRepository);
            var result  = service.GetAll <AnnouncementCategoriesView>();

            Assert.Equal(5, result.Count());
            var isDelete = service.Delete("11");

            Assert.False(isDelete);
        }
        public async Task <IActionResult> Delete(Guid id)
        {
            if (!await _service.Delete(id))
            {
                return(NotFound());
            }

            return(NoContent());
        }
        public void Throw_WhenIdParameterIsInvalid()
        {
            //Arrange
            var categories        = new Mock <IEfGenericRepository <Category> >();
            var categoriesService = new CategoriesService(categories.Object);

            //Act & Assert
            Assert.Throws <ArgumentNullException>(() => categoriesService.Delete(null));
        }
        public async Task DeleteReturnsOneIfEntityIsDeleted()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(dbContext);

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

            Assert.Equal(1, await service.Delete("Writing"));
        }
        public async Task DeleteThrowsArgumentNullExceptionIfNameIsNotValid()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(dbContext);

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

            await Assert.ThrowsAsync <ArgumentNullException>(() => service.Delete("Writings"));
        }
 private void BtnCategoriesDelete_Click(object sender, EventArgs e)
 {
     if (lbCategories.SelectedItem != null)
     {
         if (FlashcardsMessageBox.YesNo("Are you sure to delete category with all decks and cards?"))
         {
             _categoriesService.Delete(_topic, ((Category)lbCategories.SelectedItem).Id);
             RefreshCategories();
         }
     }
 }
示例#7
0
 public ActionResult <Category> Delete(int id)
 {
     try
     {
         string userId = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
         // NOTE DONT TRUST THE USER TO TELL YOU WHO THEY ARE!!!!
         return(Ok(_cs.Delete(id, userId)));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
示例#8
0
        public async Task <ActionResult> Delete(int id)
        {
            try
            {
                await service.Delete(id);

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public async Task DeleteShouldDecreaseTheTableWithOneEntity()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(dbContext);

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

            var count = repository.All().Count() - 1;
            await service.Delete("Writing");

            Assert.Equal(count, repository.All().Count());
        }
        public async Task DeleteShouldDeleteRightEntity()
        {
            var dbContext = ApplicationDbContextInMemoryFactory.InitializeContext();

            await this.SeedDataAsync(dbContext);

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

            await service.Delete("Writing");

            var categoriesNames = repository.All().Select(c => c.Name);

            Assert.DoesNotContain("Writing", categoriesNames);
        }
        public void InvokeRepositoryMethosDeleteOnce()
        {
            //Arrange
            var categories = new Mock <IEfGenericRepository <Category> >();
            var category   = DataHelper.GetCategory();

            categories.Setup(x => x.Delete(It.IsAny <Category>())).Verifiable();
            var categoriesService = new CategoriesService(categories.Object);

            //Act
            categoriesService.Delete(category);

            //Assert
            categories.Verify(x => x.Delete(It.IsAny <Category>()), Times.Once);
        }
示例#12
0
        public ActionResult RemoveCategory(int?id)
        {
            if (!id.HasValue)
            {
                return(this.HttpResult(HttpStatusCode.NoContent));
            }

            var delete = _categoriesService.Get(id.Value);

            if (delete != null)
            {
                _categoriesService.Delete(delete.Id);
                return(new HttpStatusCodeResult(HttpStatusCode.OK));
            }

            return(this.HttpResult(HttpStatusCode.NoContent));
        }
示例#13
0
        public ActionResult Category_Destroy([DataSourceRequest] DataSourceRequest request, Category category)
        {
            try
            {
                if (category != null && ModelState.IsValid)
                {
                    _categoriesService.Delete(category.CategoryID);
                }

                return(Json(new[] { category }.ToDataSourceResult(request, ModelState)));
            }
            catch (Exception)
            {
                return(Json(new DataSourceResult
                {
                    Errors = "A server error has occurred!"
                }));
            }
        }
示例#14
0
        public async Task DeleteCategoryAsync_CategoryIsDeleted()
        {
            // Arrange
            await db.AddRangeAsync(seedCategories);

            await db.SaveChangesAsync();

            var recId = 3;
            var expectedCategories = seedCategories.Where(c => c.CategoryId != recId).ToList();

            // Act
            await service.Delete(recId);

            // Assert
            var actualCategories = await db.Categories.ToListAsync();

            Assert.Equal(
                expectedCategories.OrderBy(c => c.CategoryId).Select(c => c.CategoryName),
                actualCategories.OrderBy(c => c.CategoryId).Select(c => c.CategoryName));
        }
        public IActionResult Delete(Guid id, IFormCollection collection)
        {
            var categorie = _categorieRepo.FindById(id);

            try
            {
                // TODO: Add delete logic here

                _categorieRepo.Delete(id);
                return(RedirectToAction(nameof(Index)).WithSuccess("Supprimer", "vous avez supprimé avec succès "));
            }
            catch (DbUpdateException ex)
            {
                //Log the exception to a file. We discussed logging to a file
                // using Nlog in Part 63 of ASP.NET Core tutorial
                logger.LogError($"Exception Occured : {ex}");
                // Pass the ErrorTitle and ErrorMessage that you want to show to
                // the user using ViewBag. The Error view retrieves this data
                // from the ViewBag and displays to the user.
                ViewBag.ErrorTitle   = $" Le catégorie \"{categorie.Name_Category}\" est en cours d'utilisation";
                ViewBag.ErrorMessage = $"Le catégorie de dépense {categorie.Name_Category} ne peut pas être supprimé car il y a des dépenses dans ce catégorie. Si vous souhaitez supprimer ce catégorie, veuillez supprimer les dépenses du catégorie, puis essayez de supprimer";
                return(View("Error"));
            }
        }