Пример #1
0
 public void Dispose()
 {
     _server.Database.DropCollection("People");
     using (var admin = new MongoAdmin("mongodb://localhost/NormTests?pooling=false"))
     {
         admin.DropDatabase();
     }
     _server.Dispose();
 }
Пример #2
0
 public QueryTests()
 {
     var admin = new MongoAdmin("mongodb://localhost/admin?pooling=false&strict=true");
     _server = Mongo.Create("mongodb://localhost/NormTests?pooling=false");
     _collection = _server.GetCollection<Person>("People");
     _buildInfo = admin.BuildInfo();
     //cause the collection to exist on the server by inserting, then deleting some things.
     _collection.Insert(new Person());
     _collection.Delete(new { });
 }
Пример #3
0
        public IList<string> GetDatabases()
        {
            using (IMongo mongo = Mongo.Create(_connectionString)) {

                List<string> databases = new List<string>();
                using (MongoAdmin admin = new MongoAdmin(_connectionString)) {
                    admin.GetAllDatabases().ForEach(d => databases.Add(d.Name));
                }

                return databases;
            }
        }
Пример #4
0
 public GridFSTests()
 {
     //construct a random 10MB stream.
     Random r = new Random(DateTime.Now.Millisecond);
     for (int i = 0; i < 1024 * 1024 * 1.5; i++)
     {
         this._randomBytes.Write(BitConverter.GetBytes(r.NextDouble()), 0, 8);
     }
     this._randomBytes.Position = 0;
     this._randomByteHash = _hasher.ComputeHash(_randomBytes);
     this._randomBytes.Position = 0;
     this._db = Mongo.Create(TestHelper.ConnectionString());
     using (var admin = new MongoAdmin(TestHelper.ConnectionString()))
     {
         admin.DropDatabase();
     }
 }
Пример #5
0
        public void Find_Subset_Returns_Appropriate_Subset()
        {
            using (var admin = new MongoAdmin(TestHelper.ConnectionString()))
            {
                admin.SetProfileLevel(2);
            }
            using (var db = Mongo.Create(TestHelper.ConnectionString()))
            {
                var coll = db.GetCollection<TestProduct>();
                coll.Delete(new { });
                var oid = ObjectId.NewObjectId();

                coll.Insert(new TestProduct
                {
                    _id = oid,
                    Price = 42.42f,
                    Supplier = new Supplier
                    {
                        Name = "Bob's house of pancakes",
                        RefNum = 12,
                        CreatedOn = DateTime.MinValue
                    }
                });

                var subset = db.GetCollection<TestProduct>().Find(new { }, new { }, Int32.MaxValue, 0,
                    j => new { SupplierName = j.Supplier.Name, Cost = j.Price, Id = j._id }).ToArray();

                Assert.Equal("Bob's house of pancakes", subset[0].SupplierName);
                Assert.Equal(42.42f, subset[0].Cost);
                Assert.Equal(oid, subset[0].Id);
            }
        }