示例#1
0
        public async Task <TaskCommentGetPagedListResponse> GetPagedListAsync(
            TaskCommentGetPagedListRequest request,
            CancellationToken ct)
        {
            var queryable = _storage.TaskComments
                            .AsNoTracking()
                            .Where(x =>
                                   x.TaskId == request.TaskId &&
                                   (!request.BeforeCreateDateTime.HasValue || x.CreateDateTime < request.BeforeCreateDateTime) &&
                                   (!request.AfterCreateDateTime.HasValue || x.CreateDateTime > request.AfterCreateDateTime));

            var minCreateDateTime = _storage.TaskComments
                                    .AsNoTracking()
                                    .Where(x => x.TaskId == request.TaskId)
                                    .Min(x => x != null ? x.CreateDateTime : (DateTime?)null);

            var comments = await queryable
                           .SortBy(request.SortBy, request.OrderBy)
                           .Take(request.Limit)
                           .ToListAsync(ct);

            return(new TaskCommentGetPagedListResponse
            {
                HasCommentsBefore = comments.Any() && minCreateDateTime < comments.Min(x => x.CreateDateTime),
                Comments = comments
            });
        }
示例#2
0
        public async Task WhenGetPagedList_ThenSuccess()
        {
            var headers = await _defaultRequestHeadersService.GetAsync();

            var type = await _create.TaskType.BuildAsync();

            var status = await _create.TaskStatus.BuildAsync();

            var task = await _create.Task
                       .WithTypeId(type.Id)
                       .WithStatusId(status.Id)
                       .BuildAsync();

            await Task.WhenAll(
                _create.TaskComment
                .WithTaskId(task.Id)
                .BuildAsync(),
                _create.TaskComment
                .WithTaskId(task.Id)
                .BuildAsync());

            var request = new TaskCommentGetPagedListRequest
            {
                TaskId = task.Id
            };

            var response = await _taskCommentsClient.GetPagedListAsync(request, headers);

            var results = response.Comments
                          .Skip(1)
                          .Zip(response.Comments, (previous, current) => current.CreateDateTime >= previous.CreateDateTime);

            Assert.NotEmpty(response.Comments);
            Assert.All(results, Assert.True);
        }
示例#3
0
 public Task <TaskCommentGetPagedListResponse> GetPagedListAsync(
     TaskCommentGetPagedListRequest request,
     Dictionary <string, string> headers = default,
     CancellationToken ct = default)
 {
     return(_factory.PostAsync <TaskCommentGetPagedListResponse>(
                _host + "/Tasks/Comments/v1/GetPagedList", null, request, headers, ct));
 }
示例#4
0
        public async Task <ActionResult <TaskCommentGetPagedListResponse> > GetPagedList(
            TaskCommentGetPagedListRequest request,
            CancellationToken ct = default)
        {
            var task = await _tasksService.GetAsync(request.TaskId, false, ct);

            var response = await _taskCommentsService.GetPagedListAsync(request, ct);

            return(ReturnIfAllowed(response, Roles.Tasks, task.AccountId));
        }
示例#5
0
        public async Task WhenCreate_ThenSuccess()
        {
            var headers = await _defaultRequestHeadersService.GetAsync();

            var type = await _create.TaskType.BuildAsync();

            var status = await _create.TaskStatus.BuildAsync();

            var task = await _create.Task
                       .WithTypeId(type.Id)
                       .WithStatusId(status.Id)
                       .BuildAsync();

            var comment = new TaskComment
            {
                Id     = Guid.NewGuid(),
                TaskId = task.Id,
                Value  = "Test".WithGuid()
            };

            await _taskCommentsClient.CreateAsync(comment, headers);

            var request = new TaskCommentGetPagedListRequest
            {
                TaskId = task.Id
            };

            var createdComment = (await _taskCommentsClient.GetPagedListAsync(request, headers)).Comments
                                 .First();

            Assert.NotNull(createdComment);
            Assert.Equal(comment.TaskId, createdComment.TaskId);
            Assert.True(!createdComment.CommentatorUserId.IsEmpty());
            Assert.Equal(comment.Value, createdComment.Value);
            Assert.True(createdComment.CreateDateTime.IsMoreThanMinValue());
        }