Exemplo n.º 1
0
        public void IfDTOHasNoCategoriesAndOneExistsOnTheProductRemoveCategoryFromProduct()
        {
            var category = new CategoryBuilder().WithUrlSegment("test-category").Build().PersistTo(Session);
            var importProductsService = new ImportProductsServiceBuilder(Session).Build();
            var dataTransferObject = new ProductImportDTOBuilder().WithNoCategories().Build();
            var product = new ProductBuilder().WithCategories(category).Build();
            product.Categories.Where(c => c.UrlSegment == "test-category").Should().HaveCount(1);

            importProductsService.SetCategories(dataTransferObject, product);

            product.Categories.Where(c => c.UrlSegment == "test-category").Should().HaveCount(0);
        }
Exemplo n.º 2
0
        public void IfDTOHasNoCategoriesAndOneExistsOnTheProductRemoveProductFromCategory()
        {
            var category = new CategoryBuilder().WithUrlSegment("test-category").Build().PersistTo(Session);
            var importProductsService = new ImportProductsServiceBuilder(Session).Build();
            var dataTransferObject = new ProductImportDTOBuilder().WithNoCategories().Build();
            var product = new ProductBuilder().WithCategories(category).Build();
            category.Products.Add(product);

            importProductsService.SetCategories(dataTransferObject, product);

            category.Products.Should().NotContain(product);
        }
Exemplo n.º 3
0
        public void IfDTOHasNewCategoryWhichExistsInSystemItIsAddedToTheProduct()
        {
            new CategoryBuilder().WithUrlSegment("test-category").Build().PersistTo(Session);
            var importProductsService = new ImportProductsServiceBuilder(Session).Build();
            var dataTransferObject = new ProductImportDTOBuilder().WithCategories("test-category").Build();
            var product = new ProductBuilder().Build();
            product.Categories.Where(c => c.UrlSegment == "test-category").Should().HaveCount(0);

            importProductsService.SetCategories(dataTransferObject, product);

            product.Categories.Where(c => c.UrlSegment == "test-category").Should().HaveCount(1);
        }
        public void DeletingProductShouldDeleteCategoryMapping()
        {
            //build
            var category = new CategoryBuilder().Build();
            _documentService.AddDocument(category);
            var product = new ProductBuilder().Build();
            _documentService.AddDocument(product);

            //test
            _productService.AddCategory(product, category.Id);
            category.Products.Count.Should().Be(1);
            _documentService.DeleteDocument(product);
            category.Products.Count.Should().Be(0);
        }