Exemple #1
0
        public async Task EntityFrameworkRepositoryTests_Paging_LastPageTestAsync()
        {
            int pageNumber = pagingTotalRecords / pageSize + 1;
            List<EFCustomer> customers = new List<EFCustomer>();
            SequentialIdentityGenerator g = new SequentialIdentityGenerator();
            for (int i = 1; i <= pagingTotalRecords; i++)
                customers.Add(new EFCustomer
                {
                    ID = (Guid)g.Next,
                    Address = new EFAddress("China", "SH", "SH", "A street", "12345"),
                    Email = "cust" + i + "@apworks.com",
                    Password = i.ToString(),
                    UserName = "******" + i,
                    Sequence = i
                });

            IRepository<EFCustomer> repository = ServiceLocator.Instance.GetService<IRepository<EFCustomer>>();
            foreach (var cust in customers)
                repository.Add(cust);
            await repository.Context.CommitAsync();


            ISpecification<EFCustomer> spec = Specification<EFCustomer>.Eval(c => c.UserName.StartsWith("cust"));

            var result = repository.FindAll(spec, p => p.Sequence, Storage.SortOrder.Ascending, pageNumber, pageSize);
            Assert.AreEqual<int>(pagingTotalRecords % pageSize, result.Count());
            Assert.AreEqual<string>(string.Format("cust{0}", (pageNumber - 1) * pageSize + 1), result.First().UserName);
            Assert.AreEqual<string>(string.Format("cust{0}", (pageSize * (pageNumber - 1)) + (pagingTotalRecords % pageSize)), result.Last().UserName);
            repository.Context.Dispose();
        }
        public void NHibernateRepositoryTests_Paging_LastPageTest()
        {
            int pageNumber = pagingTotalRecords / pageSize + 1;
            List<Customer> customers = new List<Customer>();
            SequentialIdentityGenerator g = new SequentialIdentityGenerator();
            for (int i = 1; i <= pagingTotalRecords; i++)
                customers.Add(new Customer
                {
                    ID = (Guid)g.Next,
                    Birth = DateTime.Now.AddYears(-23),
                    Email = "cust" + i + "@apworks.com",
                    FirstName = "cust" + i,
                    LastName = "cust" + i,
                    Password = i.ToString(),
                    Username = "******" + i,
                    Sequence = i
                });

            IRepository<Customer> repository = ServiceLocator.Instance.GetService<IRepository<Customer>>();
            foreach (var cust in customers)
                repository.Add(cust);
            repository.Context.Commit();


            ISpecification<Customer> spec = Specification<Customer>.Eval(c => c.FirstName.StartsWith("cust"));

            var result = repository.FindAll(spec, p => p.Sequence, Storage.SortOrder.Ascending, pageNumber, pageSize);
            Assert.AreEqual<int>(pagingTotalRecords % pageSize, result.Count());
            Assert.AreEqual<string>(string.Format("cust{0}", (pageNumber - 1) * pageSize + 1), result.First().FirstName);
            Assert.AreEqual<string>(string.Format("cust{0}", (pageSize * (pageNumber - 1)) + (pagingTotalRecords % pageSize)), result.Last().FirstName);
            repository.Context.Dispose();
        }