public async Task CreateAsync_WithInvalidName_ShouldThrowArgumentNullException() { var subCategoryServiceModel = new SubCategoryServiceModel() { Name = null, }; Assert.ThrowsAsync <ArgumentNullException>(async() => await service.CreateAsync(subCategoryServiceModel)); }
public async Task CreateCategoryAsync_ReturnsTrueAndCreates_IfNameIsUnique() { MapperInitializer.InitializeMapper(); var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subCategoryCreateInputModel = new SubCategoryCreateInputModel() { Name = "SubCategory1", CategoryId = "categoryId1", }; var shouldReturnTrue = await subCategoryService.CreateAsync(subCategoryCreateInputModel); Assert.True(shouldReturnTrue); }
public async Task CreateAsync_ThrowsException_IfNameIsNullOrWhiteSpace() { var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var subCategoryRepository = new EfDeletableEntityRepository <SubCategory>(context); var subCategoryService = new SubCategoryService(subCategoryRepository); var subcategoryCreateInputModel = new SubCategoryCreateInputModel() { Name = null, CategoryId = null, }; await Assert.ThrowsAsync <ArgumentNullException>(async() => { await subCategoryService.CreateAsync(subcategoryCreateInputModel); }); }
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); }