コード例 #1
0
        public async Task <OrderCommentGetPagedListResponse> GetPagedListAsync(
            OrderCommentGetPagedListRequest request,
            CancellationToken ct)
        {
            var queryable = _storage.OrderComments
                            .AsNoTracking()
                            .Where(x =>
                                   x.OrderId == request.OrderId &&
                                   (!request.BeforeCreateDateTime.HasValue || x.CreateDateTime < request.BeforeCreateDateTime) &&
                                   (!request.AfterCreateDateTime.HasValue || x.CreateDateTime > request.AfterCreateDateTime));

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

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

            return(new OrderCommentGetPagedListResponse
            {
                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.OrderType.BuildAsync();

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

            var order = await _create.Order
                        .WithTypeId(type.Id)
                        .WithStatusId(status.Id)
                        .BuildAsync();

            await Task.WhenAll(
                _create.OrderComment
                .WithOrderId(order.Id)
                .BuildAsync(),
                _create.OrderComment
                .WithOrderId(order.Id)
                .BuildAsync());

            var request = new OrderCommentGetPagedListRequest
            {
                OrderId = order.Id,
            };

            var response = await _orderCommentsClient.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 async Task WhenCreate_ThenSuccess()
        {
            var headers = await _defaultRequestHeadersService.GetAsync();

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

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

            var order = await _create.Order
                        .WithTypeId(type.Id)
                        .WithStatusId(status.Id)
                        .BuildAsync();

            var comment = new OrderComment
            {
                Id      = Guid.NewGuid(),
                OrderId = order.Id,
                Value   = "Test".WithGuid()
            };

            await _orderCommentsClient.CreateAsync(comment, headers);

            var request = new OrderCommentGetPagedListRequest
            {
                OrderId = order.Id
            };

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

            Assert.NotNull(createdComment);
            Assert.Equal(comment.OrderId, createdComment.OrderId);
            Assert.True(!createdComment.CommentatorUserId.IsEmpty());
            Assert.Equal(comment.Value, createdComment.Value);
            Assert.True(createdComment.CreateDateTime.IsMoreThanMinValue());
        }
コード例 #4
0
 public Task <OrderCommentGetPagedListResponse> GetPagedListAsync(
     OrderCommentGetPagedListRequest request,
     Dictionary <string, string> headers = default,
     CancellationToken ct = default)
 {
     return(_factory.PostAsync <OrderCommentGetPagedListResponse>(
                _host + "/Orders/Comments/v1/GetPagedList", null, request, headers, ct));
 }
コード例 #5
0
        public async Task <ActionResult <OrderCommentGetPagedListResponse> > GetPagedList(
            OrderCommentGetPagedListRequest request,
            CancellationToken ct = default)
        {
            var order = await _ordersService.GetAsync(request.OrderId, false, ct);

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

            return(ReturnIfAllowed(response, Roles.Orders, order.AccountId));
        }