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);
        }
Esempio n. 2
0
        public async Task GetTagByNameAsync_Tests()
        {
            // 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);

            ICollection <Tag> tags1 = await tagManager.GetTagsByNameAsync("Root");

            tags1.Count.ShouldBe(1);

            ICollection <Tag> tags2 = await tagManager.GetTagsByNameAsync("Sub");

            tags2.Count.ShouldBe(1);

            ICollection <Tag> tags3 = await tagManager.GetTagsByNameAsync("Leaf");

            tags3.Count.ShouldBe(1);

            ICollection <Tag> tags4 = await tagManager.GetTagsByNameAsync("11");

            tags4.Count.ShouldBe(2);

            ICollection <Tag> tags5 = await tagManager.GetTagsByNameAsync("1");

            tags5.Count.ShouldBe(3);
        }
Esempio n. 3
0
        public async Task AddRootTag_Test()
        {
            // Root
            CreateTagDto createRootTagDto = new CreateTagDto {
                Name = "Root"
            };
            var rootTagDto = await tagAppService.Create(createRootTagDto);

            var outputDto = await tagAppService.Get(new EntityDto <long> {
                Id = rootTagDto.Id
            });

            outputDto.Name.ShouldBe("Root");
            outputDto.FullName.ShouldBe("Root");
            outputDto.Parent.ShouldBe(null);
            outputDto.Children.Count.ShouldBe(0);
        }
Esempio n. 4
0
        public async Task GetTagsOfTargetAsync_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);

            // Leaf 112
            CreateTagDto createLeaf112TagDto = new CreateTagDto {
                Name = "Leaf112", ParentId = sub11TagDto.Id
            };
            var leaf112TagDto = await tagAppService.Create(createLeaf112TagDto);

            Tag tag1 = tagRepository.FirstOrDefault(leaf111TagDto.Id);
            Tag tag2 = tagRepository.FirstOrDefault(leaf112TagDto.Id);

            tagTargetManager.AssignTag(result1.Targets, tag1);
            tagTargetManager.AssignTag(result1.Targets[0], tag2);

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

            tagTargets.Count.ShouldBe(19);

            using (var context = Resolve <StarryNightDbContext>())
            {
                Target target1 = context.Targets
                                 .Include(t => t.TagTargets)
                                 .ThenInclude(tt => tt.Tag)
                                 .FirstOrDefault(t => t.Id == result1.Targets[0].Id);
                target1.WithTags.Count().ShouldBe(2);

                ICollection <Tag> withTags1 = targetManager.GetTagsOfTarget(target1, 10, 0);
                withTags1.Count.ShouldBe(2);

                Target target2 = context.Targets
                                 .Include(t => t.TagTargets)
                                 .ThenInclude(tt => tt.Tag)
                                 .FirstOrDefault(t => t.Id == result1.Targets[1].Id);
                target2.WithTags.Count().ShouldBe(1);

                ICollection <Tag> withTags2 = targetManager.GetTagsOfTarget(target2, 10, 0);
                withTags2.Count.ShouldBe(1);
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> Create(CreateTagModel model, CancellationToken token = default)
        {
            await _service.Create(model, token);

            return(ApiCreatedResponse());
        }