Ejemplo n.º 1
0
        public async Task <TagDto> ShiftTo(TagShiftDto input)
        {
            CheckUpdatePermission();

            Tag tag = await Repository.FirstOrDefaultAsync(input.Id);

            tag.DetachFromParent();
            if (input.NewParentId.HasValue)
            {
                Tag parent = await Repository.FirstOrDefaultAsync(input.NewParentId.Value);

                tag.AttachToParent(parent);
            }

            Tag shiftedTag = await Repository.UpdateAsync(tag);

            return(MapToEntityDto(shiftedTag));
        }
Ejemplo n.º 2
0
        public async Task ShiftTag_Test()
        {
            await CreateTagTree1();
            await CreateTagTree2();

            // Shift Sub
            TagShiftDto tagShiftDto = new TagShiftDto {
                Id = 9, NewParentId = 1
            };
            TagDto shiftedTagDto = await tagAppService.ShiftTo(tagShiftDto);

            // Unit test project does not support lazy loading.
            // Navigation properties need eager loading.
            await UsingDbContextAsync(async context =>
            {
                Tag root1Tag = await context.Tags.Include(t => t.Children)
                               .ThenInclude(t => t.Children).FirstOrDefaultAsync(t => t.Id == 1);
                root1Tag.Children.Count.ShouldBe(3);

                Tag shiftedSubTag = root1Tag.Children.ToList()[2];
                shiftedSubTag.Name.ShouldBe("Sub21");
                shiftedSubTag.Children.Count.ShouldBe(1);
            });
        }