public void Drop_should_drop_the_files_and_chunks_collections( [Values(false, true)] bool async) { var client = DriverTestConfiguration.Client; var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); var subject = new GridFSBucket(database); subject.UploadFromBytes("test", new byte[] { 0 }); // causes the collections to be created if (async) { subject.DropAsync().GetAwaiter().GetResult(); } else { subject.Drop(); } var collections = database.ListCollections().ToList(); var collectionNames = collections.Select(c => c["name"].AsString); collectionNames.Should().NotContain("fs.files"); collectionNames.Should().NotContain("fs.chunks"); }
public void Drop_should_throw_when_a_write_concern_error_occurss( [Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.CommandsThatWriteAcceptWriteConcern).ClusterType(ClusterType.ReplicaSet); var client = DriverTestConfiguration.Client; var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); EnsureBucketExists(new GridFSBucket(database)); // with default WriteConcern var options = new GridFSBucketOptions { WriteConcern = new WriteConcern(9) }; var subject = new GridFSBucket(database, options); var exception = Record.Exception(() => { if (async) { subject.DropAsync().GetAwaiter().GetResult(); } else { subject.Drop(); } }); exception.Should().BeOfType <MongoWriteConcernException>(); }
public void Drop_should_drop_the_files_and_chunks_collections( [Values(false, true)] bool async) { RequireServer.Check(); var client = DriverTestConfiguration.Client; var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); var subject = new GridFSBucket(database); EnsureBucketExists(subject); if (async) { subject.DropAsync().GetAwaiter().GetResult(); } else { subject.Drop(); } var collections = database.ListCollections().ToList(); var collectionNames = collections.Select(c => c["name"].AsString); collectionNames.Should().NotContain("fs.files"); collectionNames.Should().NotContain("fs.chunks"); }
public async Task DropAsync_should_drop_the_files_and_chunks_collections() { var client = DriverTestConfiguration.Client; var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); var subject = new GridFSBucket(database); await subject.UploadFromBytesAsync("test", new byte[] { 0 }); // causes the collections to be created await subject.DropAsync(); var collections = await(await database.ListCollectionsAsync()).ToListAsync(); var collectionNames = collections.Select(c => c["name"].AsString); collectionNames.Should().NotContain("fs.files"); collectionNames.Should().NotContain("fs.chunks"); }
private static async Task MainAsync() { const string connectionString = "mongodb://localhost"; //const string connectionString = // "mongodb://localhost/?replicaSet=myReplSet&readPreference=primary"; var client = new MongoClient(connectionString); // Use the client to access the 'entities' database IMongoDatabase database = client.GetDatabase("TestMongoDB"); IMongoCollection <ClubMember> collection = database.GetCollection <ClubMember>("CarClub"); var demoManager = new DemoManager(collection); long count = await collection.CountAsync(new BsonDocument()); if (count == 0) { Console.WriteLine("About to add Club members to the database"); count = ConsoleHelper.GetNumberFromUser(ConsoleHelper.MINIMUMMEMBERSHIPSIZE, ConsoleHelper.MAXIMUMMEMBERSHIPSIZE); var clubMembersBuilder = new ClubMembersBuilder(); Console.WriteLine("Adding {0} new ClubMembers", count); await clubMembersBuilder.BuildClubMembersAsync(collection, count); } else { Console.WriteLine("Number of ClubMembers in Collection {0}", count); } //Build an index if it is not already built IndexKeysDefinition <ClubMember> keys = Builders <ClubMember> .IndexKeys.Ascending("Lastname").Ascending("Forename").Descending("Age"); //Add an optional name- useful for admin var options = new CreateIndexOptions { Name = "MyIndex" }; await collection.Indexes.CreateOneAsync(keys, options); await demoManager.RunDemosAsync(); Console.WriteLine("Press return key to empty the collection and exit "); Console.ReadLine(); var gridFsBucket = new GridFSBucket(database); await gridFsBucket.DropAsync(); var emptyFilter = new BsonDocument(); await collection.DeleteManyAsync(emptyFilter); }
public void Kill() { _bucket.DropAsync().GetAwaiter().GetResult(); }
public async Task DropAsync_should_drop_the_files_and_chunks_collections() { var client = DriverTestConfiguration.Client; var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); var subject = new GridFSBucket(database); await subject.UploadFromBytesAsync("test", new byte[] { 0 }); // causes the collections to be created await subject.DropAsync(); var collections = await (await database.ListCollectionsAsync()).ToListAsync(); var collectionNames = collections.Select(c => c["name"].AsString); collectionNames.Should().NotContain("fs.files"); collectionNames.Should().NotContain("fs.chunks"); }
public void Kill() { SystemDateTime.Reset(); _bucket.DropAsync().GetAwaiter().GetResult(); }
public void Drop_should_throw_when_a_write_concern_error_occurss( [Values(false, true)] bool async) { RequireServer.Check().Supports(Feature.CommandsThatWriteAcceptWriteConcern).ClusterType(ClusterType.ReplicaSet); var client = DriverTestConfiguration.Client; var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); EnsureBucketExists(new GridFSBucket(database)); // with default WriteConcern var options = new GridFSBucketOptions { WriteConcern = new WriteConcern(9) }; var subject = new GridFSBucket(database, options); var exception = Record.Exception(() => { if (async) { subject.DropAsync().GetAwaiter().GetResult(); } else { subject.Drop(); } }); exception.Should().BeOfType<MongoWriteConcernException>(); }