Ejemplo n.º 1
0
        public async Task BulkCreate_ExistTree_Test()
        {
            await UsingDbContextAsync(async context =>
            {
                //Arrange
                context.Region.Add(new Region
                {
                    Name     = "hebei",
                    FullName = "hebei",
                    Code     = "00001",
                    Level    = 1
                });
                await context.SaveChangesAsync();

                context.Region.Add(new Region
                {
                    Name     = "shijiazhuang",
                    FullName = "hebei-shijiazhuang",
                    Code     = "00001.00001",
                    Level    = 2,
                    ParentId = 1
                });
                await context.SaveChangesAsync();
            });

            var chengde = new Region
            {
                Name     = "chengde",
                ParentId = 1,
                Children = new List <Region>
                {
                    new Region
                    {
                        Name = "shuangqiaoqu"
                    },
                    new Region
                    {
                        Name = "shuangluanqu"
                    }
                }
            };

            await _generalRegionTreeManager.BulkCreateAsync(chengde);

            //Assert
            chengde = GetRegion("chengde");
            chengde.ShouldNotBeNull();
            chengde.Name.ShouldBe("chengde");
            chengde.FullName.ShouldBe("hebei-chengde");
            chengde.Code.ShouldBe(_generalTreeCodeGenerate.CreateCode(1, 2));
            chengde.Level.ShouldBe(2);
            chengde.ParentId.ShouldBe(1);

            var shuangqiaoqu = GetRegion("shuangqiaoqu");

            shuangqiaoqu.ShouldNotBeNull();
            shuangqiaoqu.Name.ShouldBe("shuangqiaoqu");
            shuangqiaoqu.FullName.ShouldBe("hebei-chengde-shuangqiaoqu");
            shuangqiaoqu.Code.ShouldBe(_generalTreeCodeGenerate.CreateCode(1, 2, 1));
            shuangqiaoqu.Level.ShouldBe(chengde.Level + 1);
            shuangqiaoqu.ParentId.ShouldBe(chengde.Id);

            var shuangluanqu = GetRegion("shuangluanqu");

            shuangluanqu.ShouldNotBeNull();
            shuangluanqu.Name.ShouldBe("shuangluanqu");
            shuangluanqu.FullName.ShouldBe("hebei-chengde-shuangluanqu");
            shuangluanqu.Code.ShouldBe(_generalTreeCodeGenerate.CreateCode(1, 2, 2));
            shuangluanqu.Level.ShouldBe(chengde.Level + 1);
            shuangluanqu.ParentId.ShouldBe(chengde.Id);
        }
Ejemplo n.º 2
0
        public async Task BulkCreate_Test()
        {
            //Act
            var beijing = new Region(Guid.NewGuid())
            {
                Name = "beijing"
            };

            var xicheng = new Region(Guid.NewGuid())
            {
                Name     = "xicheng",
                ParentId = beijing.Id
            };

            var xicheng_x = new Region(Guid.NewGuid())
            {
                Name     = "xicheng_x",
                ParentId = xicheng.Id
            };

            var xicheng_y = new Region(Guid.NewGuid())
            {
                Name     = "xicheng_y",
                ParentId = xicheng.Id
            };

            xicheng.Children = new List <Region>
            {
                xicheng_x,
                xicheng_y
            };

            beijing.Children = new List <Region>
            {
                xicheng,
                new Region(Guid.NewGuid())
                {
                    Name     = "dongcheng",
                    ParentId = beijing.Id
                }
            };

            await _generalTreeManager.BulkCreateAsync(beijing);

            //Assert
            var bj = await GetRegion("beijing");

            bj.ShouldNotBeNull();
            bj.Name.ShouldBe("beijing");
            bj.FullName.ShouldBe("beijing");
            bj.Code.ShouldBe(_generalTreeCodeGenerator.CreateCode(1));
            bj.Level.ShouldBe(1);
            bj.ParentId.ShouldBeNull();

            var xc = await GetRegion("xicheng");

            xc.ShouldNotBeNull();
            xc.Name.ShouldBe("xicheng");
            xc.FullName.ShouldBe("beijing-xicheng");
            xc.Code.ShouldBe(_generalTreeCodeGenerator.CreateCode(1, 1));
            xc.Level.ShouldBe(beijing.Level + 1);
            xc.ParentId.ShouldBe(beijing.Id);

            var xc_x = await GetRegion("xicheng_x");

            xc_x.ShouldNotBeNull();
            xc_x.Name.ShouldBe("xicheng_x");
            xc_x.FullName.ShouldBe("beijing-xicheng-xicheng_x");
            xc_x.Code.ShouldBe(_generalTreeCodeGenerator.CreateCode(1, 1, 1));
            xc_x.Level.ShouldBe(xc.Level + 1);
            xc_x.ParentId.ShouldBe(xc.Id);

            var dc = await GetRegion("dongcheng");

            dc.ShouldNotBeNull();
            dc.Name.ShouldBe("dongcheng");
            dc.FullName.ShouldBe("beijing-dongcheng");
            dc.Code.ShouldBe(_generalTreeCodeGenerator.CreateCode(1, 2));
            dc.Level.ShouldBe(beijing.Level + 1);
            dc.ParentId.ShouldBe(beijing.Id);
        }