示例#1
0
        public async Task CreateAsync_WithInvalidName_ShouldThrowArgumentNullException()
        {
            var subCategoryServiceModel = new SubCategoryServiceModel()
            {
                Name = null,
            };

            Assert.ThrowsAsync <ArgumentNullException>(async() => await service.CreateAsync(subCategoryServiceModel));
        }
示例#2
0
        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);
        }
示例#3
0
        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);
            });
        }
示例#4
0
        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);
        }