public async Task Remove_CatalogCategory_Successfully()
        {
            var catalog  = Catalog.Create(this.Fixture.Create <string>());
            var catalogs = new List <Catalog> {
                catalog
            };

            this._mockDbContext
            .Setup(x => x.Set <Catalog>())
            .ReturnsDbSet(catalogs);

            var categoryId      = IdentityFactory.Create <CategoryId>();
            var catalogCategory = catalog.AddCategory(categoryId, this.Fixture.Create <string>());

            var command = new RemoveCatalogCategoryCommand
            {
                CatalogId         = catalog.CatalogId,
                CatalogCategoryId = catalogCategory.CatalogCategoryId
            };

            IRequestHandler <RemoveCatalogCategoryCommand> handler
                = new CommandHandler(this.MockRepositoryFactory.Object, this._validator);

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

            this._mockDbContext.Verify(x => x.Update(catalog), Times.Once);
        }
        public void Catalog_NotFound_ShouldBeInvalid()
        {
            var command = new RemoveCatalogCategoryCommand
            {
                CatalogId         = (CatalogId)Guid.Empty,
                CatalogCategoryId = IdentityFactory.Create <CatalogCategoryId>()
            };

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

            result.ShouldHaveValidationErrorFor(x => x.CatalogId);
            result.ShouldNotHaveValidationErrorFor(x => x.CatalogCategoryId);
        }
        public void GuidEmpty_For_Ids_ShouldBeInvalid()
        {
            var command = new RemoveCatalogCategoryCommand
            {
                CatalogId         = (CatalogId)Guid.Empty,
                CatalogCategoryId = (CatalogCategoryId)Guid.Empty
            };

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

            result.ShouldHaveValidationErrorFor(x => x.CatalogId);
            result.ShouldHaveValidationErrorFor(x => x.CatalogCategoryId);
        }
        public async Task Invalid_Command_ShouldThrowException()
        {
            var command = new RemoveCatalogCategoryCommand
            {
                CatalogId         = (CatalogId)Guid.Empty,
                CatalogCategoryId = (CatalogCategoryId)Guid.Empty
            };

            IRequestHandler <RemoveCatalogCategoryCommand> handler = new CommandHandler(this.MockRepositoryFactory.Object, this._validator);

            await Should.ThrowAsync <ValidationException>(async() =>
                                                          await handler.Handle(command, this.CancellationToken));
        }
        public void Catalog_NotFound_ShouldBeInvalid()
        {
            var command = new RemoveCatalogCategoryCommand
            {
                CatalogId         = CatalogId.Empty,
                CatalogCategoryId = CatalogCategoryId.New
            };

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

            result.ShouldHaveValidationErrorFor(x => x.CatalogId);
            result.ShouldNotHaveValidationErrorFor(x => x.CatalogCategoryId);
        }
        public void CatalogCategory_NotFound_ShouldBeInvalid()
        {
            var catalog  = Catalog.Create(this.Fixture.Create <string>());
            var catalogs = new List <Catalog> {
                catalog
            };

            this._mockDbContext.Setup(x => x.Set <Catalog>())
            .ReturnsDbSet(catalogs);

            var command = new RemoveCatalogCategoryCommand
            {
                CatalogId         = catalog.CatalogId,
                CatalogCategoryId = (CatalogCategoryId)Guid.Empty
            };

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

            result.ShouldHaveValidationErrorFor(x => x.CatalogCategoryId);
            result.ShouldNotHaveValidationErrorFor(x => x.CatalogId);
        }