public async Task WhenCreate_ThenSuccess() { var headers = await _defaultRequestHeadersService.GetAsync(); var supplier = await _create.Supplier .BuildAsync(); var comment = new SupplierComment { Id = Guid.NewGuid(), SupplierId = supplier.Id, Value = "Test".WithGuid() }; await _supplierCommentsClient.CreateAsync(comment, headers); var request = new SupplierCommentGetPagedListRequest { SupplierId = supplier.Id }; var createdComment = (await _supplierCommentsClient.GetPagedListAsync(request, headers)).Comments.First(); Assert.NotNull(createdComment); Assert.Equal(comment.SupplierId, createdComment.SupplierId); Assert.True(!createdComment.CommentatorUserId.IsEmpty()); Assert.Equal(comment.Value, createdComment.Value); Assert.True(createdComment.CreateDateTime.IsMoreThanMinValue()); }
public async Task <SupplierCommentGetPagedListResponse> GetPagedListAsync( SupplierCommentGetPagedListRequest request, CancellationToken ct) { var queryable = _storage.SupplierComments .AsNoTracking() .Where(x => x.SupplierId == request.SupplierId && (!request.BeforeCreateDateTime.HasValue || x.CreateDateTime < request.BeforeCreateDateTime) && (!request.AfterCreateDateTime.HasValue || x.CreateDateTime > request.AfterCreateDateTime)); var minCreateDateTime = _storage.SupplierComments .AsNoTracking() .Where(x => x.SupplierId == request.SupplierId) .Min(x => x != null ? x.CreateDateTime : (DateTime?)null); var comments = await queryable .SortBy(request.SortBy, request.OrderBy) .Take(request.Limit) .ToListAsync(ct); return(new SupplierCommentGetPagedListResponse { HasCommentsBefore = comments.Any() && minCreateDateTime < comments.Min(x => x.CreateDateTime), Comments = comments }); }
public async Task WhenGetPagedList_ThenSuccess() { var headers = await _defaultRequestHeadersService.GetAsync(); var supplier = await _create.Supplier .BuildAsync(); await Task.WhenAll( _create.SupplierComment .WithSupplierId(supplier.Id) .BuildAsync(), _create.SupplierComment .WithSupplierId(supplier.Id) .BuildAsync()); var request = new SupplierCommentGetPagedListRequest { SupplierId = supplier.Id }; var response = await _supplierCommentsClient.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); }
public Task <SupplierCommentGetPagedListResponse> GetPagedListAsync( SupplierCommentGetPagedListRequest request, Dictionary <string, string> headers = default, CancellationToken ct = default) { return(_factory.PostAsync <SupplierCommentGetPagedListResponse>( _host + "/Suppliers/Comments/v1/GetPagedList", null, request, headers, ct)); }
public async Task <ActionResult <SupplierCommentGetPagedListResponse> > GetPagedList( SupplierCommentGetPagedListRequest request, CancellationToken ct = default) { var supplier = await _suppliersService.GetAsync(request.SupplierId, false, ct); var response = await _supplierCommentsService.GetPagedListAsync(request, ct); return(ReturnIfAllowed(response, Roles.Suppliers, supplier.AccountId)); }