Exemplo n.º 1
0
        public void TestSetIndexOptionDefaults()
        {
            var options = CollectionOptions.SetIndexOptionDefaults(new IndexOptionDefaults {
                StorageEngine = new BsonDocument("mmapv1", new BsonDocument())
            });
            var expected = "{ \"indexOptionDefaults\" : { \"storageEngine\" : { \"mmapv1\" : { } } } }";

            Assert.AreEqual(expected, options.ToJson());
        }
        public void TestCreateCollectionSetIndexOptionDefaults()
        {
            var collection = _database.GetCollection("testindexoptiondefaults");

            collection.Drop();
            Assert.IsFalse(collection.Exists());
            var storageEngineOptions = new BsonDocument("mmapv1", new BsonDocument());
            var indexOptionDefaults  = new IndexOptionDefaults {
                StorageEngine = storageEngineOptions
            };
            var expectedIndexOptionDefaultsDocument = new BsonDocument("storageEngine", storageEngineOptions);
            var options = CollectionOptions.SetIndexOptionDefaults(indexOptionDefaults);

            _database.CreateCollection(collection.Name, options);

            var commandResult  = _database.RunCommand("listCollections");
            var collectionInfo = commandResult.Response["cursor"]["firstBatch"].AsBsonArray.Where(doc => doc["name"] == collection.Name).Single().AsBsonDocument;

            Assert.AreEqual(expectedIndexOptionDefaultsDocument, collectionInfo["options"]["indexOptionDefaults"]);
        }
        public void TestCreateCollectionSetIndexOptionDefaults()
        {
            RequireServer.Check().Supports(Feature.IndexOptionsDefaults).ClusterTypes(ClusterType.Standalone, ClusterType.ReplicaSet);
            var collection = _database.GetCollection("testindexoptiondefaults");

            collection.Drop();
            Assert.False(collection.Exists());
            var storageEngine        = CoreTestConfiguration.GetStorageEngine();
            var storageEngineOptions = new BsonDocument(storageEngine, new BsonDocument());
            var indexOptionDefaults  = new IndexOptionDefaults {
                StorageEngine = storageEngineOptions
            };
            var expectedIndexOptionDefaultsDocument = new BsonDocument("storageEngine", storageEngineOptions);
            var options = CollectionOptions.SetIndexOptionDefaults(indexOptionDefaults);

            _database.CreateCollection(collection.Name, options);

            var commandResult  = _database.RunCommand("listCollections");
            var collectionInfo = commandResult.Response["cursor"]["firstBatch"].AsBsonArray.Where(doc => doc["name"] == collection.Name).Single().AsBsonDocument;

            Assert.Equal(expectedIndexOptionDefaultsDocument, collectionInfo["options"]["indexOptionDefaults"]);
        }