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); }
public async Task GetNameByIdAsync_ReturnsTheNameOrThrowsException() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subCategoryTestSeeder = new SubCategoryTestSeeder(); await subCategoryTestSeeder.SeedSubCategories(context); var actualName = await subCategoryService.GetNameByIdAsync("1"); Assert.Equal("SubCategory1", actualName); await Assert.ThrowsAsync <ArgumentNullException>(async() => { await subCategoryService.GetNameByIdAsync("invalid"); }); }
public async Task CreateAsync_ReturnsFalse_IfNameIsNotUnique() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subCategoryTestSeeder = new SubCategoryTestSeeder(); await subCategoryTestSeeder.SeedSubCategories(context); var subCategoryCreateInputModel = new SubCategoryCreateInputModel() { Name = "SubCategory1", CategoryId = "categoryId1", }; var shouldReturnfalse = await subCategoryService.CreateAsync(subCategoryCreateInputModel); Assert.False(shouldReturnfalse); }
public async Task EditSubCategory_ReturnsTrue_IfNameIsUnique() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subCategoryTestSeeder = new SubCategoryTestSeeder(); await subCategoryTestSeeder.SeedSubCategories(context); var subCategoryEditInputModel = new SubCategoryEditInputModel() { Id = "1", Name = "Unique", }; var shouldBetrue = await subCategoryService.EditSubCategory(subCategoryEditInputModel); Assert.True(shouldBetrue); }
public async Task EditSubCategory_ThrowsExceotion_IfMOdelIsIncorect() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subCategoryTestSeeder = new SubCategoryTestSeeder(); await subCategoryTestSeeder.SeedSubCategories(context); var subCategoryEditInputModel = new SubCategoryEditInputModel() { Id = "Incorrect", Name = "SubCategory2", }; await Assert.ThrowsAsync <ArgumentNullException>(async() => { await subCategoryService.EditSubCategory(subCategoryEditInputModel); }); }