Пример #1
0
        /// <summary>
        /// An example of a method to retrieve a collection of entities.
        /// </summary>
        /// <param name="orderByPropertyName"></param>
        /// <returns>List of customers</returns>
        public Task<IEnumerable<Customer>> GetCustomersAsync(string orderByPropertyName)
        {
            IEntityQuery<Customer> query = Manager.Customers;
            if (orderByPropertyName != null)
            {
                var selector = new SortSelector(typeof(Customer), orderByPropertyName);
                query = query.OrderBySelector(selector);
            }

            return query.ExecuteAsync();
        }
Пример #2
0
        /// <summary>
        /// An example of a method to retrieve a collection of entities.
        /// </summary>
        /// <param name="orderByPropertyName"></param>
        /// <returns>List of customers</returns>
        public Task <IEnumerable <Customer> > GetCustomersAsync(string orderByPropertyName)
        {
            IEntityQuery <Customer> query = Manager.Customers;

            if (orderByPropertyName != null)
            {
                var selector = new SortSelector(typeof(Customer), orderByPropertyName);
                query = query.OrderBySelector(selector);
            }

            return(query.ExecuteAsync());
        }
Пример #3
0
        public async Task ShouldRetrieveCustomersIfSortedWithSortSelector()
        {
            var provider   = EntityManagerProviderFactory.CreateTestEntityManagerProvider();
            var unitOfWork = new UnitOfWork <Customer>(provider);

            var selector = new SortSelector("City");

            await InitFakeBackingStoreAsync(CompositionContext.Fake.Name);

            var customers = await unitOfWork.Entities.AllAsync(q => q.OrderBySelector(selector));

            Assert.IsTrue(customers.Any());
        }
Пример #4
0
        public async Task ShouldPageCustomersWithPredicate()
        {
            var provider   = EntityManagerProviderFactory.CreateTestEntityManagerProvider();
            var repository = new PagerRepository <Customer>(provider);

            var sortSelector = new SortSelector("CompanyName");

            await InitFakeBackingStoreAsync(CompositionContext.Fake.Name);

            var pager = repository.Pager(sortSelector, 2, x => x.City == "SomeCity");
            var page  = await pager.LastPageAsync();

            Assert.IsTrue(page.PageWasFound);
            Assert.IsTrue(page.Results.Count() == 1);
            Assert.IsTrue(pager.TotalItemCount == 3);
            Assert.IsTrue(pager.TotalNumberOfPages == 2);
            Assert.IsTrue(page.PageIndex == 1);
        }
Пример #5
0
        public async Task ShouldPageProjection()
        {
            var provider   = EntityManagerProviderFactory.CreateTestEntityManagerProvider();
            var repository = new PagerRepository <Customer>(provider);

            var sortSelector = new SortSelector("CompanyName");

            await InitFakeBackingStoreAsync(CompositionContext.Fake.Name);

            var pager = repository.Pager(
                q => q.Select(x => new PageProjection()
            {
                CompanyName = x.CompanyName, City = x.City
            }),
                2, sortSelector, x => x.City == "SomeCity");
            var page = await pager.FirstPageAsync();

            Assert.IsTrue(page.PageWasFound);
            Assert.IsTrue(page.Results.Count() == 2);
            Assert.IsTrue(page.PageIndex == 0);
        }
Пример #6
0
        public async Task ShouldRetrieveCustomersWithProjectionSelector()
        {
            var provider   = EntityManagerProviderFactory.CreateTestEntityManagerProvider();
            var unitOfWork = new UnitOfWork <Customer>(provider);

            var selector =
                ProjectionSelector.Combine(new[]
            {
                new ProjectionSelector("CustomerID"),
                new ProjectionSelector("CompanyName")
            });
            var pd           = PredicateBuilder.Make("City", FilterOperator.IsEqualTo, "SomeCity");
            var sortSelector = new SortSelector("CompanyName");

            await InitFakeBackingStoreAsync(CompositionContext.Fake.Name);

            var result = await unitOfWork.Entities.FindAsync(
                q => q.Select(selector), pd.ToPredicate <Customer>(), q => q.OrderBySelector(sortSelector));

            Assert.IsTrue(result.Cast <object>().Any());
        }
Пример #7
0
        public async Task ShouldPageProjection()
        {
            var provider = EntityManagerProviderFactory.CreateTestEntityManagerProvider();
            var repository = new PagerRepository<Customer>(provider);

            var sortSelector = new SortSelector("CompanyName");

            await InitFakeBackingStoreAsync(CompositionContext.Fake.Name);
            var pager = repository.Pager(
                q => q.Select(x => new PageProjection() { CompanyName = x.CompanyName, City = x.City }),
                2, sortSelector, x => x.City == "SomeCity");
            var page = await pager.FirstPageAsync();

            Assert.IsTrue(page.PageWasFound);
            Assert.IsTrue(page.Results.Count() == 2);
            Assert.IsTrue(page.PageIndex == 0);
        }
Пример #8
0
        public async Task ShouldPageCustomersWithPredicate()
        {
            var provider = EntityManagerProviderFactory.CreateTestEntityManagerProvider();
            var repository = new PagerRepository<Customer>(provider);

            var sortSelector = new SortSelector("CompanyName");

            await InitFakeBackingStoreAsync(CompositionContext.Fake.Name);
            var pager = repository.Pager(sortSelector, 2, x => x.City == "SomeCity");
            var page = await pager.LastPageAsync();

            Assert.IsTrue(page.PageWasFound);
            Assert.IsTrue(page.Results.Count() == 1);
            Assert.IsTrue(pager.TotalItemCount == 3);
            Assert.IsTrue(pager.TotalNumberOfPages == 2);
            Assert.IsTrue(page.PageIndex == 1);
        }
Пример #9
0
        public async Task ShouldRetrieveCustomersWithProjectionSelector()
        {
            var provider = EntityManagerProviderFactory.CreateTestEntityManagerProvider();
            var unitOfWork = new UnitOfWork<Customer>(provider);

            var selector =
                ProjectionSelector.Combine(new[]
                                        {
                                            new ProjectionSelector("CustomerID"),
                                            new ProjectionSelector("CompanyName")
                                        });
            var pd = PredicateBuilder.Make("City", FilterOperator.IsEqualTo, "SomeCity");
            var sortSelector = new SortSelector("CompanyName");

            await InitFakeBackingStoreAsync(CompositionContext.Fake.Name);
            var result = await unitOfWork.Entities.FindAsync(q => q.Select(selector),
                                                             pd.ToPredicate<Customer>(),
                                                             q => q.OrderBySelector(sortSelector));

            Assert.IsTrue(result.Cast<object>().Any());
        }
Пример #10
0
        public async Task ShouldRetrieveCustomersIfSortedWithSortSelector()
        {
            var provider = EntityManagerProviderFactory.CreateTestEntityManagerProvider();
            var unitOfWork = new UnitOfWork<Customer>(provider);

            var selector = new SortSelector("City");
            await InitFakeBackingStoreAsync(CompositionContext.Fake.Name);
            var customers = await unitOfWork.Entities.AllAsync(q => q.OrderBySelector(selector));

            Assert.IsTrue(customers.Any());
        }