public async Task Create_CatalogCategory_With_Fail_Of_Validation_ShouldThrowException()
        {
            var command = new CreateCatalogCategoryCommand
            {
                CatalogId   = (CatalogId)Guid.Empty,
                CategoryId  = (CategoryId)Guid.Empty,
                DisplayName = string.Empty
            };

            await Should.ThrowAsync <ValidationException>(async() =>
                                                          await this._requestHandler.Handle(command, this.CancellationToken));
        }
        public async Task Create_CatalogCategory_Successfully()
        {
            var command = new CreateCatalogCategoryCommand
            {
                CatalogId   = this._catalog.CatalogId,
                CategoryId  = this._category.CategoryId,
                DisplayName = this.Fixture.Create <string>()
            };

            await this._requestHandler.Handle(command, this.CancellationToken);

            this._mockDbContext.Verify(x => x.Update(this._catalog), Times.Once);
        }
        public void Command_With_NotFound_Category_ShouldBeInvalid()
        {
            var command = new CreateCatalogCategoryCommand
            {
                CatalogId   = this._catalog.CatalogId,
                CategoryId  = IdentityFactory.Create <CategoryId>(),
                DisplayName = this.Fixture.Create <string>()
            };

            var result = this._validator.TestValidate(command);

            result.ShouldHaveValidationErrorFor(x => x.CategoryId);
            result.ShouldNotHaveValidationErrorFor(x => x.CatalogId);
            result.ShouldNotHaveValidationErrorFor(x => x.DisplayName);
        }
        public void Command_With_Empty_Values_ShouldBeInvalid()
        {
            var command = new CreateCatalogCategoryCommand
            {
                CatalogId   = (CatalogId)Guid.Empty,
                CategoryId  = (CategoryId)Guid.Empty,
                DisplayName = string.Empty
            };

            var result = this._validator.TestValidate(command);

            result.ShouldHaveValidationErrorFor(x => x.CatalogId);
            result.ShouldHaveValidationErrorFor(x => x.CategoryId);
            result.ShouldHaveValidationErrorFor(x => x.DisplayName);
        }
示例#5
0
        public void Command_With_NotFound_Catalog_ShouldBeInvalid()
        {
            var command = new CreateCatalogCategoryCommand
            {
                CatalogId   = CatalogId.New,
                CategoryId  = this._category.Id,
                DisplayName = this._category.DisplayName
            };

            var result = this._validator.TestValidate(command);

            result.ShouldHaveValidationErrorFor(x => x.CatalogId);
            result.ShouldNotHaveValidationErrorFor(x => x.CategoryId);
            result.ShouldNotHaveValidationErrorFor(x => x.DisplayName);
        }
示例#6
0
        public void Command_With_Invalid_ParentCatalogCategoryId_ShouldBeInvalid()
        {
            var command = new CreateCatalogCategoryCommand
            {
                CatalogId               = this._catalog.Id,
                CategoryId              = this._category.Id,
                DisplayName             = this.Fixture.Create <string>(),
                ParentCatalogCategoryId = CatalogCategoryId.New
            };

            var result = this._validator.TestValidate(command);

            result.ShouldNotHaveValidationErrorFor(x => x.CategoryId);
            result.ShouldNotHaveValidationErrorFor(x => x.CatalogId);
            result.ShouldNotHaveValidationErrorFor(x => x.DisplayName);
            result.ShouldHaveValidationErrorFor(x => x.ParentCatalogCategoryId);
        }
        public async Task Create_CatalogCategory_As_Child_Successfully()
        {
            var catalogCategory = this._catalog.AddCategory(this._category.CategoryId, this._category.DisplayName);
            var childCategory   = Category.Create(this.Fixture.Create <string>());

            this._mockDbContext
            .Setup(x => x.Set <Category>())
            .ReturnsDbSet(new List <Category> {
                this._category, childCategory
            });

            var command = new CreateCatalogCategoryCommand
            {
                CatalogId               = this._catalog.CatalogId,
                CategoryId              = childCategory.CategoryId,
                DisplayName             = childCategory.DisplayName,
                ParentCatalogCategoryId = catalogCategory.CatalogCategoryId
            };

            await this._requestHandler.Handle(command, this.CancellationToken);

            this._mockDbContext.Verify(x => x.Update(this._catalog), Times.Once);
        }