public async Task <List <CommentDto> > GetGiftCommentsOlderById(GetCommentDto getCommentDto) { var query = Db.Set <GiftLinkComment>().Where(x => x.GiftId == getCommentDto.Id).AsQueryable(); //берём коммент var comment = await Db.Set <Comment>().FirstOrDefaultAsync(x => x.Id == getCommentDto.CommentId); //смотрим, корневой ли он if (comment.ParentCommentId == null) { //корневой query = query.Where(x => x.Comment.UpdateTime <= comment.UpdateTime); } else { //ищем корневой var rootComment = await Db.Set <Comment>().FirstOrDefaultAsync(x => x.Id == comment.ParentCommentId); query = query.Where(x => x.Comment.UpdateTime <= rootComment.UpdateTime); } query = query.OrderByDescending(x => x.Comment.UpdateTime).Skip(getCommentDto.Offset).Take(getCommentDto.Length); var collection = await query.ToListAsync(); return(ConvertToCommentDto(collection)); }
public void GetCommentsByPostIdTest() { //arange var postId = Guid.NewGuid(); var controller = new CommentsController(_dataRepository, _profileRepository) { _getUserId = _getUserIdFake }; var comments = new List <Comment> { new Comment { Id = Guid.NewGuid(), PostId = postId, ProfileId = Guid.NewGuid(), CreatedOn = DateTime.Now, Text = "just a unit test" } }; var commentDto = new GetCommentDto { Id = Guid.NewGuid(), CreatedOn = DateTime.Now, Text = "just a unit test", UserId = Guid.NewGuid() }; var fakeMapper = A.Fake <IMapper>(); A.CallTo(() => _dataRepository.GetCommentsByPostId(postId)).Returns(comments); A.CallTo(() => fakeMapper.Map <List <GetCommentDto> >(comments)).Returns(new List <GetCommentDto> { commentDto } ); //act var response = controller.GetCommentsByPostId(postId); var okResult = response as ObjectResult; //assert A.CallTo(() => _dataRepository.GetCommentsByPostId(postId)).MustHaveHappened(); Assert.NotNull(okResult); Assert.Equal(200, okResult.StatusCode); }
public void CommentMapperToDomainEntityTest() { GetCommentDto commentDto = new GetCommentDto { UserId = Guid.NewGuid(), CreatedOn = DateTime.Now, Id = Guid.NewGuid(), Text = "Test", Handle = "UserName" }; var comment = _mapper.ToDomainEntity(commentDto); Assert.AreEqual(commentDto.Handle, comment.CreatedBy); Assert.AreEqual(commentDto.CreatedOn, comment.CreatedOn); Assert.AreEqual(commentDto.Id, comment.Id); Assert.AreEqual(commentDto.Text, comment.Text); }
public async Task <IHttpActionResult> GetGiftCommentById(GetCommentDto idModel) { return(SuccessApiResult(await _commentRepository.GetGiftCommentsOlderById(idModel))); }
public IActionResult Get(int id, [FromServices] IGetOneCommentQuery query) { GetCommentDto comment = _useCaseExecutor.ExecuteQuery(query, id); return(Ok(comment)); }