public void FindAll_Should_Return_All_Items_Which_Satisfy_Composite_Specification(ICompoundKeyRepository<User, string, int> repository)
        {
            for (var i = 1; i <= 3; i++)
            {
                var contact = new User { Username = "******" + i, Age = i };
                repository.Add(contact);
            }

            var result = repository.FindAll(new Specification<User>(p => p.Username == "Test User 1").OrElse(new Specification<User>(p => p.Username == "Test User 2")));
            result.Count().ShouldEqual(2);
        }
        public void FindAll_Should_Return_All_Items_Which_Satisfy_Composite_Specification(ICompoundKeyRepository <User, string, int> repository)
        {
            for (var i = 1; i <= 3; i++)
            {
                var contact = new User {
                    Username = "******" + i, Age = i
                };
                repository.Add(contact);
            }

            var result = repository.FindAll(new Specification <User>(p => p.Username == "Test User 1").OrElse(new Specification <User>(p => p.Username == "Test User 2")));

            result.Count().ShouldEqual(2);
        }
        public void FindAll_Should_Return_All_Items_Which_Satisfy_Predicate(ICompoundKeyRepository <User, string, int> repository)
        {
            for (var i = 1; i <= 3; i++)
            {
                var contact = new User {
                    Username = "******" + i, Age = i
                };
                repository.Add(contact);
            }

            var result = repository.FindAll(p => p.Username == "Test User 1"); // Note: Raven doesn't like p.Name.Equals("...");

            result.Count().ShouldEqual(1);
        }
        public void FindAll_Should_Return_All_Items_Which_Satisfy_Specification_With_Paging(ICompoundKeyRepository <User, string, int> repository)
        {
            const int resultingPage = 2;
            const int pageSize      = 2;
            const int totalItems    = 10;

            var queryOptions = new PagingOptions <User, string>(resultingPage, pageSize, m => m.Username);

            for (var i = 1; i <= totalItems; i++)
            {
                var contact = new User {
                    Username = "******" + i, Age = i
                };
                repository.Add(contact);
            }

            var result = repository.FindAll(new Specification <User>(p => p.Age <= totalItems / 2), queryOptions);

            result.Count().ShouldEqual(pageSize);
            queryOptions.TotalItems.ShouldEqual(totalItems / 2);
            result.First().Username.ShouldEqual("Test User 3");
        }
        public void FindAll_Should_Return_All_Items_Which_Satisfy_Composite_Specification_With_Paging_And_Sort_Descending(ICompoundKeyRepository<User, string, int> repository)
        {
            const int resultingPage = 2;
            const int pageSize = 2;
            var queryOptions = new PagingOptions<User>(resultingPage, pageSize, "Username", true);

            for (var i = 1; i <= 10; i++)
            {
                var contact = new User { Username = "******" + i, Age = i };
                repository.Add(contact);
            }

            IEnumerable<User> result = repository
                .FindAll(new Specification<User>(p => p.Username == "Test User 1")
                                .OrElse(new Specification<User>(p => p.Username == "Test User 5")
                                        .OrElse(new Specification<User>(p => p.Username == "Test User 8"))),
                            queryOptions);

            result.Count().ShouldEqual(1);
            queryOptions.TotalItems.ShouldEqual(3);
            result.First().Username.ShouldEqual("Test User 1");
        }
        public void FindAll_Should_Return_All_Items_Which_Satisfy_Specification_With_Paging_MagicString(ICompoundKeyRepository <User, string, int> repository)
        {
            const int resultingPage = 2;
            const int pageSize      = 2;
            const int totalItems    = 10;

            var queryOptions = new PagingOptions <User>(resultingPage, pageSize, "Username");

            for (var i = 1; i <= totalItems; i++)
            {
                var contact = new User {
                    Username = "******" + i, Age = i
                };
                repository.Add(contact);
            }

            // this fails for RavenDb because the ContactId is an int but is being used as the key, so the check on ContactId <= 5 is doing a string comparison and including ContactId = 10 as well
            //  need to look into why this happens and how to get around it
            var result = repository.FindAll(new Specification <User>(p => p.Age <= totalItems / 2), queryOptions);

            result.Count().ShouldEqual(pageSize);
            queryOptions.TotalItems.ShouldEqual(totalItems / 2);
            result.First().Username.ShouldEqual("Test User 3");
        }
        public void FindAll_Should_Return_All_Items_Which_Satisfy_Composite_Specification_With_Paging_MagicString_And_Sort_Descending(ICompoundKeyRepository <User, string, int> repository)
        {
            const int resultingPage = 2;
            const int pageSize      = 2;
            var       queryOptions  = new PagingOptions <User>(resultingPage, pageSize, "Username", true);

            for (var i = 1; i <= 10; i++)
            {
                var contact = new User {
                    Username = "******" + i, Age = i
                };
                repository.Add(contact);
            }

            IEnumerable <User> result = repository
                                        .FindAll(new Specification <User>(p => p.Username == "Test User 1")
                                                 .OrElse(new Specification <User>(p => p.Username == "Test User 5")
                                                         .OrElse(new Specification <User>(p => p.Username == "Test User 8"))),
                                                 queryOptions);

            result.Count().ShouldEqual(1);
            queryOptions.TotalItems.ShouldEqual(3);
            result.First().Username.ShouldEqual("Test User 1");
        }
        public void FindAll_Should_Return_All_Items_Which_Satisfy_Specification_With_Paging_MagicString(ICompoundKeyRepository<User, string, int> repository)
        {
            const int resultingPage = 2;
            const int pageSize = 2;
            const int totalItems = 10;

            var queryOptions = new PagingOptions<User>(resultingPage, pageSize, "Username");

            for (var i = 1; i <= totalItems; i++)
            {
                var contact = new User { Username = "******" + i, Age = i };
                repository.Add(contact);
            }

            // this fails for RavenDb because the ContactId is an int but is being used as the key, so the check on ContactId <= 5 is doing a string comparison and including ContactId = 10 as well
            //  need to look into why this happens and how to get around it
            var result = repository.FindAll(new Specification<User>(p => p.Age <= totalItems / 2), queryOptions);
            result.Count().ShouldEqual(pageSize);
            queryOptions.TotalItems.ShouldEqual(totalItems / 2);
            result.First().Username.ShouldEqual("Test User 3");
        }
        public void FindAll_Should_Return_All_Items_Which_Satisfy_Specification_With_Paging(ICompoundKeyRepository<User, string, int> repository)
        {
            const int resultingPage = 2;
            const int pageSize = 2;
            const int totalItems = 10;

            var queryOptions = new PagingOptions<User, string>(resultingPage, pageSize, m => m.Username);

            for (var i = 1; i <= totalItems; i++)
            {
                var contact = new User { Username = "******" + i, Age = i };
                repository.Add(contact);
            }

            var result = repository.FindAll(new Specification<User>(p => p.Age <= totalItems / 2), queryOptions);
            result.Count().ShouldEqual(pageSize);
            queryOptions.TotalItems.ShouldEqual(totalItems / 2);
            result.First().Username.ShouldEqual("Test User 3");
        }
        public void FindAll_Should_Return_All_Items_Which_Satisfy_Predicate(ICompoundKeyRepository<User, string, int> repository)
        {
            for (var i = 1; i <= 3; i++)
            {
                var contact = new User { Username = "******" + i, Age = i };
                repository.Add(contact);
            }

            var result = repository.FindAll(p => p.Username == "Test User 1"); // Note: Raven doesn't like p.Name.Equals("...");
            result.Count().ShouldEqual(1);
        }
Esempio n. 11
0
 public IEnumerable <T> FindAll(Expression <Func <T, bool> > predicate, IQueryOptions <T> queryOptions = null)
 {
     return(Repository.FindAll(predicate, queryOptions));
 }