Example #1
0
        public async Task CheckSameNameExpression_Test()
        {
            using (var uow = GetRequiredService <IUnitOfWorkManager>().Begin())
            {
                var opt = Substitute.For <IOptions <GeneralTreeOptions> >();
                opt.Value.Returns(new GeneralTreeOptions
                {
                    CheckSameNameExpression = (regionThis, regionCheck) =>
                                              ((Region)regionThis).SomeForeignKey == ((Region)regionCheck).SomeForeignKey
                });

                var manager = new GeneralTreeManager <Region, Guid>(
                    GetRequiredService <IGeneralTreeCodeGenerator>(),
                    GetRequiredService <IGeneralTreeRepository <Region, Guid> >(),
                    opt,
                    GetRequiredService <IStringLocalizer <GeneralTreeResource> >()
                    );

                //Act
                await manager.CreateAsync(new Region
                {
                    Name           = "beijing",
                    SomeForeignKey = 1
                });

                await uow.SaveChangesAsync();

                //Act
                await manager.CreateAsync(new Region
                {
                    Name           = "beijing",
                    SomeForeignKey = 2
                });

                await uow.SaveChangesAsync();

                //Assert
                var beijing1 = (await _generalTreeRepository.GetListAsync()).Where(x => x.Name == "beijing" && x.SomeForeignKey == 1);
                beijing1.ShouldNotBeNull();

                var beijing2 = (await _generalTreeRepository.GetListAsync()).Where(x => x.Name == "beijing" && x.SomeForeignKey == 2);
                beijing2.ShouldNotBeNull();
            }
        }
Example #2
0
        public async Task FullName_Hyphen_Test()
        {
            using (var uow = GetRequiredService <IUnitOfWorkManager>().Begin())
            {
                var opt = Substitute.For <IOptions <GeneralTreeOptions> >();
                opt.Value.Returns(new GeneralTreeOptions
                {
                    Hyphen = "->"
                });

                var manager = new GeneralTreeManager <Region, Guid>(
                    GetRequiredService <IGeneralTreeCodeGenerator>(),
                    GetRequiredService <IGeneralTreeRepository <Region, Guid> >(),
                    opt,
                    GetRequiredService <IStringLocalizer <GeneralTreeResource> >()
                    );

                //Act
                var beijing = new Region
                {
                    Name = "beijing"
                };
                await manager.CreateAsync(beijing);

                await uow.SaveChangesAsync();

                var xicheng = new Region
                {
                    Name     = "xicheng",
                    ParentId = beijing.Id
                };
                await manager.CreateAsync(xicheng);

                await uow.SaveChangesAsync();

                //Assert
                var xc = await GetRegion("xicheng");

                xc.ShouldNotBeNull();
                xc.Name.ShouldBe("xicheng");
                xc.FullName.ShouldBe("beijing->xicheng");
            }
        }