Ejemplo n.º 1
0
        public void SyncEntityToTarget_AllNew_Tests()
        {
            string Sql = @"SELECT Id, Name FROM Product";

            IList <MetaEntity> metaEntities = metaEntityManager.ExtractEntity(MetaEntityType.Product, Sql);

            MetaEntitySyncResult result = metaEntityManager.SyncEntityToTarget(metaEntities);

            result.Targets.Count.ShouldBe(45);
            result.InsertedCount.ShouldBe(45);
            result.UpdatedCount.ShouldBe(0);
            result.UnchangedCount.ShouldBe(0);
        }
        public async Task AssignTag_Tests()
        {
            string               Sql1          = @"SELECT Id, Name FROM Product";
            IList <MetaEntity>   metaEntities1 = metaEntityManager.ExtractEntity(MetaEntityType.Product, Sql1);
            MetaEntitySyncResult result1       = metaEntityManager.SyncEntityToTarget(metaEntities1);

            string               Sql2          = @"SELECT Id, Name FROM Product WHERE VisibleIndividually = @param";
            IList <MetaEntity>   metaEntities2 = metaEntityManager.ExtractEntity(MetaEntityType.Product, Sql2, new { param = 0 });
            MetaEntitySyncResult result2       = metaEntityManager.SyncEntityToTarget(metaEntities2);

            // Root 1
            CreateTagDto createRoot1TagDto = new CreateTagDto {
                Name = "Root1"
            };
            var root1TagDto = await tagAppService.Create(createRoot1TagDto);

            // Sub 11
            CreateTagDto createSub11TagDto = new CreateTagDto {
                Name = "Sub11", ParentId = root1TagDto.Id
            };
            var sub11TagDto = await tagAppService.Create(createSub11TagDto);

            // Leaf 111
            CreateTagDto createLeaf111TagDto = new CreateTagDto {
                Name = "Leaf111", ParentId = sub11TagDto.Id
            };
            var leaf111TagDto = await tagAppService.Create(createLeaf111TagDto);

            AssignTagDto assignTagDto = new AssignTagDto()
            {
                Type  = MetaEntityType.Product,
                Sql   = @"SELECT Id, Name FROM Product WHERE VisibleIndividually = @param",
                Param = "{ \"param\": 0 }",
                TagId = leaf111TagDto.Id
            };

            tagTargetAppService.AssignTag(assignTagDto);

            IList <TagTarget> tagTargets = tagTargetRepository.GetAllList();

            tagTargets.Count.ShouldBe(2);
            tagTargets[0].TagId.ShouldBe(3);
            tagTargets[0].TargetId.ShouldBe(14);
            tagTargets[1].TagId.ShouldBe(3);
            tagTargets[1].TargetId.ShouldBe(15);
        }
        public void AssignTag(AssignTagDto input)
        {
            IDictionary <string, object> paramDict = GenerateParamDict(input);

            IList <MetaEntity> metaEntities = metaEntityManager.ExtractEntity(input.Type, input.Sql, paramDict);

            MetaEntitySyncResult targetResult = metaEntityManager.SyncEntityToTarget(metaEntities);

            Tag tagResult = tagRepository.FirstOrDefault(t => t.Id == input.TagId);

            tagTargetManager.AssignTag(targetResult.Targets, tagResult);
        }
Ejemplo n.º 4
0
        public async Task GetTargetsOfTagAsync_Tests()
        {
            string               Sql1          = @"SELECT Id, Name FROM Product WHERE VisibleIndividually = @vi AND ApprovedRatingSum = @ars";
            IList <MetaEntity>   metaEntities1 = metaEntityManager.ExtractEntity(MetaEntityType.Product, Sql1, new { vi = 1, ars = 4 });
            MetaEntitySyncResult result1       = metaEntityManager.SyncEntityToTarget(metaEntities1);

            // Root 1
            CreateTagDto createRoot1TagDto = new CreateTagDto {
                Name = "Root1"
            };
            var root1TagDto = await tagAppService.Create(createRoot1TagDto);

            // Sub 11
            CreateTagDto createSub11TagDto = new CreateTagDto {
                Name = "Sub11", ParentId = root1TagDto.Id
            };
            var sub11TagDto = await tagAppService.Create(createSub11TagDto);

            // Leaf 111
            CreateTagDto createLeaf111TagDto = new CreateTagDto {
                Name = "Leaf111", ParentId = sub11TagDto.Id
            };
            var leaf111TagDto = await tagAppService.Create(createLeaf111TagDto);

            Tag tag = tagRepository.FirstOrDefault(leaf111TagDto.Id);

            tagTargetManager.AssignTag(result1.Targets, tag);

            IList <TagTarget> tagTargets = tagTargetRepository.GetAllList();

            tagTargets.Count.ShouldBe(18);

            using (var context = Resolve <StarryNightDbContext>())
            {
                Tag tagResult = context.Tags
                                .Include(t => t.TagTargets)
                                .ThenInclude(tt => tt.Target)
                                .FirstOrDefault(t => t.Id == leaf111TagDto.Id);
                tagResult.TagTargets.Count.ShouldBe(18);

                ICollection <Target> taggedTargets1 = tagManager.GetTargetsOfTag(tagResult, 10, 0);
                taggedTargets1.Count.ShouldBe(10);

                ICollection <Target> taggedTargets2 = tagManager.GetTargetsOfTag(tagResult, 10, 10);
                taggedTargets2.Count.ShouldBe(8);

                ICollection <Target> taggedTargets3 = tagManager.GetTargetsOfTag(tagResult, 100, 0);
                taggedTargets3.Count.ShouldBe(18);
            }
        }
        public MetaEntityResultDto ExtractAndSyncEntity(MetaEntityQueryDto input)
        {
            IDictionary <string, object> paramDict = GenerateParamDict(input);

            IList <MetaEntity> metaEntities = metaEntityManager.ExtractEntity(input.Type, input.Sql, paramDict);

            MetaEntitySyncResult result = metaEntityManager.SyncEntityToTarget(metaEntities);

            return(new MetaEntityResultDto()
            {
                InsertedCount = result.InsertedCount,
                UpdatedCount = result.UpdatedCount,
                UnchangedCount = result.UnchangedCount
            });
        }