示例#1
0
        public void DataIsProjected()
        {
            // Arrange
            var queryBuilder = new QueryWithProjectionBuilder <Invoice, InvoiceDto>()
                               .AddFilter(new UnpaidInvoiceSpecification())
                               .AddSelector(new SelectInvoiceSpecification());

            // Act
            var result = this.Invoices.EvaluateQuery(queryBuilder.GetQuery()).ToList();

            // Assert
            Assert.NotEmpty(result);

            var expectedType = typeof(InvoiceDto);
            var actualType   = result.First();

            Assert.IsType(expectedType, actualType);
        }
        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);
        }