public async Task GetInvoiceList_Should_GetList(GetInvoiceListInputDto dto, int count) { Guid? orderId = null; Order order = DataSeed.Orders.FirstOrDefault(o => o.OrderNo == dto.OrderNo); orderId = order?.Id; _orderRepository.Setup(s => s.GetAsync(It.IsAny <Expression <Func <Order, bool> > >(), It.IsAny <Expression <Func <Order, object> > >())) .ReturnsAsync(order); InvoiceSpecification invoiceSpecification = new(dto.InvoiceCodeNo, dto.Drawer, dto.IsRed, orderId, dto.StartTime, dto.EndTime); var invoices = DataSeed.Invoices.AsQueryable().Where(invoiceSpecification); _orderRepository.Setup(s => s.GetListAsync(It.IsAny <Expression <Func <Order, bool> > >(), It.IsAny <Func <IQueryable <Order>, IOrderedQueryable <Order> > >(), It.IsAny <Expression <Func <Order, object> > >())) .ReturnsAsync(DataSeed.Orders.Where(o => invoices.Select(i => i.OrderId).Contains(o.Id)).AsQueryable()); _invoiceService.Setup(s => s.GetInvoices(It.IsAny <InvoiceSpecification>(), It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(new PageResult <Invoice>(invoices, dto.Index, dto.PageSize)); var result = await _invoiceViewService.GetInvoiceList(dto); Assert.NotNull(result); Assert.Equal(count, result.Total); Assert.NotNull(result.Data); int pageCount = count - dto.PageSize * dto.Index; Assert.Equal(pageCount >= dto.PageSize ? dto.PageSize : (pageCount > 0 ? count : 0), result.Data.Count()); }
public async Task <IPageResult <GetInvoiceListOutputDto> > GetInvoiceList(GetInvoiceListInputDto dto) { Guard.Against.NegativeIndexPage(dto.PageSize, dto.Index); Guid?orderId = null; if (!string.IsNullOrWhiteSpace(dto.OrderNo)) { Order order = await _orderRepository.GetAsync(o => o.OrderNo == dto.OrderNo.Trim()); orderId = order.Id; } InvoiceSpecification invoiceSpecification = new(dto.InvoiceCodeNo, dto.Drawer, dto.IsRed, orderId, dto.StartTime, dto.EndTime); var list = await _invoiceService.GetInvoices(invoiceSpecification, dto.Index, dto.PageSize); var orders = await _orderRepository.GetListAsync(o => list.Data.Select(i => i.OrderId).Contains(o.Id)); IEnumerable <GetInvoiceListOutputDto> resultData = list.Data.Join(orders.ToList(), i => i.OrderId, o => o.Id, (i, o) => new GetInvoiceListOutputDto { Id = i.Id, Drawer = i.Drawer, InvoiceCode = i.InvoiceCode, InvoiceDate = i.InvoiceDate, InvoiceNo = i.InvoiceNo, IsRed = i.IsRed, OrderNo = o.OrderNo, Remark = i.Remark, Amount = i.Amount }); return(new PageResult <GetInvoiceListOutputDto> { Total = list.Total, Data = resultData }); }
public async Task <ActionResult <IPageResult <GetInvoiceListOutputDto> > > GetInvoices([FromQuery] GetInvoiceListInputDto dto) { var result = await _invoiceViewService.GetInvoiceList(dto); return(Ok(result)); }