Ejemplo n.º 1
0
        public async Task <IEnumerable <GetCustomerWithAddressView> > Handle(CustomersBy query, CancellationToken cancellationToken)
        {
            var customersQuery = _db.Query <Customer>();

            // Id provided so only use that
            if (query.Id.HasValue)
            {
                var theCustomer = await customersQuery.Select(GetCustomerWithAddressView.Projector).FirstOrDefaultAsync(x => x.Id == query.Id, cancellationToken).ConfigureAwait(false);

                if (theCustomer == null)
                {
                    return(new List <GetCustomerWithAddressView>());
                }

                return(new [] { theCustomer });
            }

            // Apply filters
            if (!string.IsNullOrEmpty(query.FirstName))
            {
                customersQuery = customersQuery.Where(x => x.FirstName.Contains(query.FirstName));
            }

            if (!string.IsNullOrEmpty(query.LastName))
            {
                customersQuery = customersQuery.Where(x => x.LastName.Contains(query.LastName));
            }

            // Execute the query and return the results
            var customers = await customersQuery.Select(GetCustomerWithAddressView.Projector).ToListAsync(cancellationToken).ConfigureAwait(false);

            // Return the results
            return(customers);
        }
        public async Task GetCustomerEmployerMappingsDetailed()
        {
            var custQuery  = new Example.Domain.Customers.Queries.CustomersBy();
            var custsut    = new HandleCustomerByQuery(_readDb, _mapper);
            var custresult = await custsut.Handle(custQuery, CancellationToken.None);

            custresult.Should().HaveCount(1);
            //custresult.ElementAt(0).Address.Street.Should().NotBeNull(); // TODO: Address keeps coming back as NULL. it was populated on one debug but not sure why

            // TODO: Having issues getting mock sorted for the .Query(includes) method. SOrt this out
            //var query = new Example.Domain.CustomerEmployerMappings.Queries.GetCustomerEmployerMappings();
            //var sut = new HandleCustomerEmployerMappingsWithIncludeByQuery(_readDb, _mapper);
            //var result = await sut.Handle(query, CancellationToken.None);
            //result.Should().HaveCount(1);
        }