Exemple #1
0
        public async Task DeleteSubCategory_ThrowsExceptionIfTheIdIsNull()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context);
            var subCategoryService    = new SubCategoryService(subCategoryRepository);

            await Assert.ThrowsAsync <ArgumentNullException>(async() =>
            {
                await subCategoryService.DeleteSubCategory(null);
            });
        }
Exemple #2
0
        public async Task DeleteSubCategory_ReturnsTrue_WhenTheIdISCorect()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context);
            var subCategoryService    = new SubCategoryService(subCategoryRepository);
            var subCategoryTestSeeder = new SubCategoryTestSeeder();

            await subCategoryTestSeeder.SeedSubCategories(context);

            var shouldBeTrue = await subCategoryService.DeleteSubCategory("1");

            Assert.True(shouldBeTrue);
        }
Exemple #3
0
        public async Task DeleteSubCategory_WithNonExistingCategory_ShouldReturnFalse()
        {
            string onTrueErrorMessage = "The method returned true upon valid category input.";

            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var subCategoryService = new SubCategoryService(context);

            string invalidSubCategoryId = "FakeCategoryId";

            var methodResult = await subCategoryService.DeleteSubCategory(invalidSubCategoryId);

            Assert.False(methodResult, onTrueErrorMessage);
        }
Exemple #4
0
        public async Task DeleteSubCategory_WithExistingCategory_ShouldDeleteCategorySuccessfully()
        {
            string onFalseErrorMessage   = "The method returned false upon valid sub-category input.";
            string onNotNullErrorMessage = "The sub-category is not deleted from the database.";

            var context = ApplicationDbContextInMemoryFactory.InitializeContext();

            var subCategoryService = new SubCategoryService(context);

            await this.SeedAndGetSubCategoriesWithCategories(context);

            string validSubCategoryId = "A-SubCategoryId-forFirst";

            var methodResult = await subCategoryService.DeleteSubCategory(validSubCategoryId);

            Assert.True(methodResult, onFalseErrorMessage);

            var categoriesFromDb = await context
                                   .Categories
                                   .FirstOrDefaultAsync(c => c.Id == validSubCategoryId);

            AssertExtensions.NullWithMessage(categoriesFromDb, onNotNullErrorMessage);
        }
Exemple #5
0
 // Xóa
 public bool DeleteSubCategory(int pSubCategoryID)
 {
     return(service.DeleteSubCategory(pSubCategoryID));
 }