Ejemplo n.º 1
0
        public async Task <Dto.Comment.Book.RootDto> MapAsync(BookRootComment rootEntity)
        {
            if (rootEntity == null)
            {
                return(new Dto.Comment.Book.RootDto());
            }

            Dto.Comment.Book.RootDto rootDto             = _mapper.Map <Dto.Comment.Book.RootDto>(rootEntity);
            Dictionary <int, Dto.Comment.OwnerDto> users = new Dictionary <int, Dto.Comment.OwnerDto>();

            rootDto.Comments = await MapChildRecursively(rootDto.Comments, users);

            if (!users.ContainsKey(rootDto.Owner.Id))
            {
                users.Add(rootDto.Owner.Id, _mapper.Map <Dto.Comment.OwnerDto>(
                              await _userRepository.GetAll().Include(entity => entity.Role).FirstOrDefaultAsync(entity => entity.Id == rootDto.Owner.Id)));
            }
            rootDto.Owner = users[rootDto.Owner.Id];

            return(rootDto);
        }
Ejemplo n.º 2
0
        public async Task GetById_BookRootCommentExists_Returns_BookRootCommentDtoWithRequestedId(string id)
        {
            var expectedEntity = new BookRootComment()
            {
                Id = id
            };
            var expectedDto = new RootDto()
            {
                Id = id
            };

            _mockRootRepository.Setup(s => s.FindByIdAsync(id)).ReturnsAsync(expectedEntity);
            _mockMapper.Setup(s => s.MapAsync(expectedEntity)).ReturnsAsync(new RootDto()
            {
                Id = expectedDto.Id
            });

            var result = await _bookRootCommentService.GetById(id);

            result.Should().BeOfType <RootDto>();
            result.Id.Should().Be(id);
        }