コード例 #1
0
ファイル: ProductTests.cs プロジェクト: Allors/apps
        public void GivenGood_WhenProductCategoryParentsAreInserted_ThenProductCategoriesExpandedAreRecalculated()
        {
            var productCategory1 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1").Build();
            var productCategory2 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("2").Build();
            var productCategory11 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.1").WithParent(productCategory1).WithParent(productCategory2).Build();
            var productCategory12 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.2").WithParent(productCategory1).WithParent(productCategory2).Build();
            var productCategory111 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.1.1").WithParent(productCategory11).Build();
            var productCategory121 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.2.1").WithParent(productCategory12).Build();

            var vatRate21 = new VatRateBuilder(this.DatabaseSession).WithRate(21).Build();
            var good = new GoodBuilder(this.DatabaseSession)
                .WithName("Good")
                .WithSku("10101")
                .WithPrimaryProductCategory(productCategory111)
                .WithInventoryItemKind(new InventoryItemKinds(this.DatabaseSession).NonSerialized)
                .WithUnitOfMeasure(new UnitsOfMeasure(this.DatabaseSession).Piece)
                .WithVatRate(vatRate21)
                .Build();

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(4, good.ProductCategoriesExpanded.Count);
            Assert.Contains(productCategory111, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory11, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory1, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory2, good.ProductCategoriesExpanded);

            var productCategory3 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("3").Build();
            productCategory11.AddParent(productCategory3);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(5, good.ProductCategoriesExpanded.Count);
            Assert.Contains(productCategory111, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory11, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory1, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory2, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory3, good.ProductCategoriesExpanded);

            good.AddProductCategory(productCategory121);

            this.DatabaseSession.Derive(true);

            var productCategory13 = new ProductCategoryBuilder(this.DatabaseSession).WithDescription("1.3").WithParent(productCategory1).Build();
            productCategory121.AddParent(productCategory13);

            this.DatabaseSession.Derive(true);

            Assert.AreEqual(8, good.ProductCategoriesExpanded.Count);
            Assert.Contains(productCategory111, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory121, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory11, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory12, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory13, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory1, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory2, good.ProductCategoriesExpanded);
            Assert.Contains(productCategory3, good.ProductCategoriesExpanded);
        }