示例#1
0
        public void QueryWithWhereAnd()
        {
            var users    = Database.Query <User>().Where(x => x.UserId > 10 && x.UserId < 12).ToList();
            var inmemory = InMemoryUsers.Where(x => x.UserId > 10 && x.UserId < 12).ToList();

            Assert.AreEqual(1, users.Count);
            for (int i = 0; i < users.Count; i++)
            {
                AssertUserValues(inmemory[i], users[i]);
            }
        }
示例#2
0
        public void QueryWithIncludeAndNestedOrderBy()
        {
            var users    = Database.Query <User>().Include(x => x.House).Where(x => x.House != null).OrderBy(x => x.House.Address).ToList();
            var inmemory = InMemoryUsers.Where(x => x.House != null).OrderBy(x => x.House.Address).ToList();

            Assert.AreEqual(7, users.Count);
            for (int i = 0; i < users.Count; i++)
            {
                AssertUserValues(inmemory[i], users[i]);
                AssertUserHouseValues(inmemory[i], users[i]);
            }
        }
        public void QueryWithIncludeAndNestedWhere()
        {
            var users = Database.Query <User>().Include(x => x.House).Where(x => x.House.Address == InMemoryHouses[0].Address).ToList();

            InMemoryUsers.ForEach(x => x.House = InMemoryHouses.SingleOrDefault(y => y.HouseId == x.HouseId));
            var inmemory = InMemoryUsers.Where(x => x.House != null && x.House.Address == InMemoryHouses[0].Address).ToList();

            Assert.AreEqual(1, users.Count);
            for (int i = 0; i < users.Count; i++)
            {
                AssertUserValues(inmemory[i], users[i]);
                AssertUserHouseValues(inmemory[i], users[i]);
            }
        }
示例#4
0
        public void QueryWithIncludeNestedOrderByLimitAndProjection()
        {
            var users = Database.Query <User>()
                        .Include(x => x.House)
                        .Where(x => x.House != null)
                        .OrderBy(x => x.House.HouseId)
                        .Limit(5)
                        .ProjectTo(x => new { Address = (x.House != null ? x.House.Address : string.Empty), x.House.HouseId });

            var inmemory = InMemoryUsers.Where(x => x.House != null).OrderBy(x => x.House.HouseId).Select(x => new { x.House.Address, x.House.HouseId }).ToList();

            Assert.AreEqual(5, users.Count);
            for (int i = 0; i < users.Count; i++)
            {
                Assert.AreEqual(inmemory[i].Address, users[i].Address);
                Assert.AreEqual(inmemory[i].HouseId, users[i].HouseId);
            }
        }
示例#5
0
        public void QueryWithIncludeNestedOrderByLimitAndProjectionToProjectUserWithList()
        {
            var users = Database.Query <User>()
                        .Include(x => x.House)
                        .Where(x => x.House != null)
                        .OrderBy(x => x.House.HouseId)
                        .Limit(5)
                        .ProjectTo(x => new ProjectUser()
            {
                Array = new object[] { x.Name, x.Age }
            });

            var inmemory = InMemoryUsers.Where(x => x.House != null).OrderBy(x => x.House.HouseId).ToList();

            Assert.AreEqual(5, users.Count);
            for (int i = 0; i < users.Count; i++)
            {
                Assert.AreEqual(inmemory[i].Name, users[i].Array[0]);
                Assert.AreEqual(inmemory[i].Age, users[i].Array[1]);
            }
        }
示例#6
0
        public void QueryWithIncludeNestedOrderByLimitAndProjectionToProjectUser()
        {
            var users = Database.Query <User>()
                        .Include(x => x.House)
                        .Where(x => x.House.HouseId > 2)
                        .OrderBy(x => x.House.HouseId)
                        .Limit(5)
                        .ProjectTo(x => new ProjectUser()
            {
                UserId = x.UserId, NameWithAge = x.Name + x.Age
            });

            var inmemory = InMemoryUsers.Where(x => x.House != null).OrderBy(x => x.House.HouseId).ToList();

            Assert.AreEqual(4, users.Count);
            for (int i = 0; i < users.Count; i++)
            {
                var inMem = inmemory.First(x => x.UserId == users[i].UserId);
                Assert.AreEqual(inMem.Name + inMem.Age, users[i].NameWithAge);
            }
        }
        public void QueryWithIncludeNestedOrderByLimitAndProjectionToProjectUser()
        {
            var users = Database.Query <User>()
                        .Include(x => x.House)
                        .Where(x => x.HouseId != null)
                        .OrderBy(x => x.House.HouseId)
                        .Limit(5)
                        .ProjectTo(x => new ProjectUser()
            {
                NameWithAge = x.Name + x.Age
            });

            InMemoryUsers.ForEach(x => x.House = InMemoryHouses.SingleOrDefault(y => y.HouseId == x.HouseId));
            var inmemory = InMemoryUsers.Where(x => x.HouseId != null).OrderBy(x => x.House.HouseId).ToList();

            Assert.AreEqual(5, users.Count);
            for (int i = 0; i < users.Count; i++)
            {
                Assert.AreEqual(inmemory[i].Name + inmemory[i].Age, users[i].NameWithAge);
            }
        }