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 async Task <ICollection <TargetDto> > GetTargetsOfTag(QueryTagDto input, int takeNum = 100, int skipNum = 0) { CheckGetPermission(); Tag tag = await Repository.FirstOrDefaultAsync(input.Id); ICollection <Target> taggedTargets = tagManager.GetTargetsOfTag(tag, takeNum, skipNum); IList <TargetDto> targetDtos = new List <TargetDto>(); foreach (Target target in taggedTargets) { targetDtos.Add(ObjectMapper.Map <TargetDto>(target)); } return(targetDtos); }