public void DataIsFitered() { var dueDate = DateTime.Now.AddDays(4); // Arrange var unpaidInvoice = new UnpaidInvoiceSpecification(); var dueDateInvoice = new InvoiceDueDateSpecification(dueDate); var queryBuilder = new QueryBuilder <Invoice>() .AddFilter(unpaidInvoice.And(dueDateInvoice)); // Act var result = this.Invoices.EvaluateQuery(queryBuilder.GetQuery()).ToList(); // Assert Assert.NotEmpty(result); Assert.Equal(2, result.Count); Assert.True(result.All(x => x.DueDate.Date == dueDate.Date)); Assert.True(result.All(x => x.IsPaid == false)); }
public async Task <List <InvoiceDto> > GetAllUnPaidInvoices(string customer, DateTime?dueDate) { InvoiceByCustomerSpecification invoiceByCustomer; InvoiceDueDateSpecification dueDateInvoice; var orderByDate = new InvoiceOrderedByDateSpecification(); var unpaidInvoice = new UnpaidInvoiceSpecification(); var queryBuilder = new QueryWithProjectionBuilder <Invoice, InvoiceDto>(); queryBuilder.AddOrderBy(orderByDate).AddSelector(new SelectInvoiceSpecification()); if (string.IsNullOrEmpty(customer) && dueDate == null) { queryBuilder.AddFilter(unpaidInvoice); } if (!string.IsNullOrEmpty(customer) && dueDate == null) { invoiceByCustomer = new InvoiceByCustomerSpecification(customer); var unpaidIvoiceByCustomer = unpaidInvoice.And(invoiceByCustomer); queryBuilder.AddFilter(unpaidIvoiceByCustomer); } if (!string.IsNullOrEmpty(customer) && dueDate.HasValue) { invoiceByCustomer = new InvoiceByCustomerSpecification(customer); dueDateInvoice = new InvoiceDueDateSpecification(dueDate.Value); var updaidIvoiceByCustomerAndDueDate = unpaidInvoice.And(invoiceByCustomer).And(dueDateInvoice); queryBuilder.AddFilter(updaidIvoiceByCustomerAndDueDate); } var result = await this.repository.QueryAsync(queryBuilder.GetQuery()); return(result); }