예제 #1
0
        public Task <List <ReceiptDto> > Handle(GetArchiveReceiptsByUserQuery request, CancellationToken cancellationToken)
        {
            var entities = _context.Receipts
                           .Where(x => x.Deleted != null && x.DeletedByUserId == _currentUserService.UserId);

            var mapped = entities.ProjectTo <ReceiptDto>(_mapper.ConfigurationProvider).ToList();

            foreach (var receiptDto in mapped)
            {
                if (_currentUserService.UserId != null)
                {
                    receiptDto.CurrentUserId = _currentUserService.UserId;
                }
            }

            return(Task.FromResult(mapped));
        }
        public async Task Handle_ValidUserId_ShouldReturnListOfReceipts()
        {
            var projectId = await CreateFinancialProject();

            var receiptId = await CreateReceipt(projectId);

            var deleteCommand = new DeleteReceiptCommand
            {
                Id = receiptId
            };

            await SendAsync(deleteCommand);

            var query = new GetArchiveReceiptsByUserQuery();

            var entities = await SendAsync(query);

            entities.Should().NotBeNull();
            entities.Count.Should().Be(1);
            entities.First().Id.Should().Be(receiptId);
            entities.First().FinancialProject.Id.Should().Be(projectId);
            entities.First().Deleted.Should().BeCloseTo(DateTime.Now, 1000);
        }