public void QueryManyPersons_WhereClauseUsingJson_ReturnsAllExceptOne()
        {
            var person = new[]
            {
                new Person {
                    Name = "Daniel1", Age = 29
                },
                new Person {
                    Name = "Daniel2", Age = 29
                },
                new Person {
                    Name = "Daniel3", Age = 30
                }
            };

            TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, person);

            using (var cn = TestHelper.CreateConnection())
            {
                var queryCommand = new QueryDocumentsCommand <Person>(cn)
                {
                    FullCollectionName = Constants.Collections.PersonsFullCollectionName,
                    QuerySelector      = @"{$where : ""this.Name.indexOf('Daniel') > -1 && this.Age < 30""}"
                };
                queryCommand.Execute();

                Assert.AreEqual(2, queryCommand.Response.NumberOfDocuments);
            }
        }
        public void QueryManyPersons_NoQuery_ReturnsAll()
        {
            var tempDate = new DateTime(2010, 1, 1, 10, 02, 03, 04);
            var persons  = new[]
            {
                new Person {
                    Name = "Daniel", Age = 29, TempDate = tempDate
                },
                new Person {
                    Name = "Daniel", Age = 30, TempDate = tempDate
                }
            };

            TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, persons);

            using (var cn = TestHelper.CreateConnection())
            {
                var queryCommand = new QueryDocumentsCommand <Person>(cn)
                {
                    FullCollectionName = Constants.Collections.PersonsFullCollectionName
                };
                queryCommand.Execute();

                Assert.AreEqual(2, queryCommand.Response.NumberOfDocuments);
            }
        }
        public void QueryManyPersonsUsingCursor_SpecificNumberOfDocumentsToReturnGivesNoCursor_SpecifiedNumberOfPersonsAreReturned()
        {
            var person = new[]
            {
                new Person {
                    Name = "Daniel1", Age = 28
                },
                new Person {
                    Name = "Daniel2", Age = 29
                },
                new Person {
                    Name = "Daniel3", Age = 30
                },
                new Person {
                    Name = "Daniel4", Age = 31
                },
                new Person {
                    Name = "Daniel5", Age = 32
                }
            };

            TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, person);

            using (var cn = TestHelper.CreateConnection())
            {
                var queryCommand = new QueryDocumentsCommand <Person>(cn)
                {
                    FullCollectionName        = Constants.Collections.PersonsFullCollectionName,
                    NumberOfDocumentsToReturn = 2
                };
                queryCommand.Execute();

                Assert.AreEqual(2, queryCommand.Response.NumberOfDocuments);
            }
        }
        public void QueryManyPersons_WhereClauseUsingWhereOperator_ReturnsThreePersons()
        {
            var person = new[]
            {
                new Person {
                    Name = "Daniel1", Age = 28
                },
                new Person {
                    Name = "Daniel2", Age = 29
                },
                new Person {
                    Name = "Daniel3", Age = 30
                },
                new Person {
                    Name = "Daniel4", Age = 31
                },
                new Person {
                    Name = "Daniel5", Age = 32
                }
            };

            TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, person);

            using (var cn = TestHelper.CreateConnection())
            {
                var queryCommand = new QueryDocumentsCommand <Person>(cn)
                {
                    FullCollectionName = Constants.Collections.PersonsFullCollectionName,
                    QuerySelector      = Query.New(q => q.Where("this.Name.indexOf('Daniel') > -1 && this.Age <= 30"))
                };
                queryCommand.Execute();

                Assert.AreEqual(3, queryCommand.Response.NumberOfDocuments);
            }
        }
        public IList <string> GetCollectionNames(bool incluceSystemCollections = false)
        {
            var cmd = new QueryDocumentsCommand <SimoKeyValues>(Session.Connection)
            {
                FullCollectionName = Name + ".system.namespaces"
            };

            cmd.Execute();

            var fullCollectionNamePrefix = Name + ".";
            var prefixLen           = fullCollectionNamePrefix.Length;
            var fullCollectionNames = cmd.Response.Documents.Select(kv =>
            {
                var cn = kv.GetString("name");
                var collectionNameIsFullCollectionName =
                    cn.StartsWith(fullCollectionNamePrefix);
                if (collectionNameIsFullCollectionName)
                {
                    cn = cn.Substring(prefixLen);
                }

                return(cn);
            });


            fullCollectionNames = incluceSystemCollections
                                      ? fullCollectionNames
                                      : fullCollectionNames.Where(cn => !MongoSystem.ReservedCollections.IsReserved(cn));

            return(fullCollectionNames.ToList());
        }
示例#6
0
        public IList <T> FindInfered <T>(T inferedTemplate, object selector = null, int?limit = null, int?skip = null)
            where T : class
        {
            var cmd = new QueryDocumentsCommand <T>(Database.Session.Connection)
            {
                FullCollectionName        = FullCollectionName,
                QuerySelector             = selector,
                NumberOfDocumentsToSkip   = skip,
                NumberOfDocumentsToReturn = limit
            };

            cmd.Execute();

            return(cmd.Response.Documents);
        }
        public void QuerySinglePerson_AnonymousTypeQueryWithString_ItemReturned()
        {
            var person = new Person {
                Name = "Daniel", Age = 29
            };

            TestHelper.InsertDocument(Constants.Collections.PersonsCollectionName, person);

            using (var cn = TestHelper.CreateConnection())
            {
                var queryCommand = new QueryDocumentsCommand <Person>(cn)
                {
                    FullCollectionName = Constants.Collections.PersonsFullCollectionName,
                    QuerySelector      = new { Name = "Daniel" }
                };
                queryCommand.Execute();

                Assert.AreEqual(1, queryCommand.Response.NumberOfDocuments);
            }
        }
        public void QueryManyPersons_NoQuery_ReturnsAll()
        {
            var tempDate = new DateTime(2010, 1, 1, 10, 02, 03, 04);
            var persons = new[]
                          {
                              new Person { Name = "Daniel", Age = 29, TempDate = tempDate },
                              new Person { Name = "Daniel", Age = 30, TempDate = tempDate }
                          };
            TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, persons);

            using (var cn = TestHelper.CreateConnection())
            {
                var queryCommand = new QueryDocumentsCommand<Person>(cn)
                                   {
                                       FullCollectionName = Constants.Collections.PersonsFullCollectionName
                                   };
                queryCommand.Execute();

                Assert.AreEqual(2, queryCommand.Response.NumberOfDocuments);
            }
        }
        public void QueryManyPersons_WhereClauseUsingJsonObject_ReturnsAllExceptOne()
        {
            var person = new[]
                         {
                             new Person { Name = "Daniel1", Age = 29 },
                             new Person { Name = "Daniel2", Age = 29 },
                             new Person { Name = "Daniel3", Age = 30 }
                         };
            TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, person);

            using (var cn = TestHelper.CreateConnection())
            {
                var queryCommand = new QueryDocumentsCommand<Person>(cn)
                                   {
                                       FullCollectionName = Constants.Collections.PersonsFullCollectionName,
                                       QuerySelector = new SimoJson(@"{$where : ""this.Name.indexOf('Daniel') > -1 && this.Age < 30""}")
                                   };
                queryCommand.Execute();

                Assert.AreEqual(2, queryCommand.Response.NumberOfDocuments);
            }
        }
        public void QueryManyPersonsUsingCursor_SpecificNumberOfDocumentsToReturnGivesNoCursor_SpecifiedNumberOfPersonsAreReturned()
        {
            var person = new[]
                         {
                             new Person { Name = "Daniel1", Age = 28 },
                             new Person { Name = "Daniel2", Age = 29 },
                             new Person { Name = "Daniel3", Age = 30 },
                             new Person { Name = "Daniel4", Age = 31},
                             new Person { Name = "Daniel5", Age = 32}
                         };
            TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, person);

            using (var cn = TestHelper.CreateConnection())
            {
                var queryCommand = new QueryDocumentsCommand<Person>(cn)
                {
                    FullCollectionName = Constants.Collections.PersonsFullCollectionName,
                    NumberOfDocumentsToReturn = 2
                };
                queryCommand.Execute();

                Assert.AreEqual(2, queryCommand.Response.NumberOfDocuments);
            }
        }
        public void QuerySinglePerson_AnonymousTypeQueryWithString_ItemReturned()
        {
            var person = new Person { Name = "Daniel", Age = 29 };
            TestHelper.InsertDocument(Constants.Collections.PersonsCollectionName, person);

            using (var cn = TestHelper.CreateConnection())
            {
                var queryCommand = new QueryDocumentsCommand<Person>(cn)
                                   {
                                       FullCollectionName = Constants.Collections.PersonsFullCollectionName,
                                       QuerySelector = new { Name = "Daniel" }
                                   };
                queryCommand.Execute();

                Assert.AreEqual(1, queryCommand.Response.NumberOfDocuments);
            }
        }
        public void QueryManyPersons_WhereClauseUsingWhereOperator_ReturnsThreePersons()
        {
            var person = new[]
                         {
                             new Person { Name = "Daniel1", Age = 28 },
                             new Person { Name = "Daniel2", Age = 29 },
                             new Person { Name = "Daniel3", Age = 30 },
                             new Person { Name = "Daniel4", Age = 31},
                             new Person { Name = "Daniel5", Age = 32}
                         };
            TestHelper.InsertDocuments(Constants.Collections.PersonsCollectionName, person);

            using (var cn = TestHelper.CreateConnection())
            {
                var queryCommand = new QueryDocumentsCommand<Person>(cn)
                                   {
                                       FullCollectionName = Constants.Collections.PersonsFullCollectionName,
                                       QuerySelector = Query.New(q => q.Where("this.Name.indexOf('Daniel') > -1 && this.Age <= 30"))
                                   };
                queryCommand.Execute();

                Assert.AreEqual(3, queryCommand.Response.NumberOfDocuments);
            }
        }