public Task DropDatabaseAsync( string name, CancellationToken cancellationToken = default) { if (TryGetSession(out IClientSessionHandle? session)) { return(_client.DropDatabaseAsync(session, name, cancellationToken)); } return(_client.DropDatabaseAsync(name, cancellationToken)); }
public async Task GetStudentNotifications() { IMongoDatabase database = await InitializeDatabaseWithNotificationsUserStudent(_mongoClient, TestingDatabaseName); var notificationService = new NotificationService(database); var notifications = await notificationService.GetStudentNotifications(TestStudentGuid); notifications.Should().BeEquivalentTo(_notifications); await _mongoClient.DropDatabaseAsync(TestingDatabaseName); }
public async ValueTask DisposeAsync() { if (_destroy) { await _client.DropDatabaseAsync(_databaseId); } }
public async Task DisposeAsync() { var failed = GetPowershellErrors(); PowerShell.Dispose(); if (Environment.GetEnvironmentVariable("idsvr_mongodb_no_teardown") == null) { if (await _client.DatabaseExistsAsync(Database)) { await _client.DropDatabaseAsync(Database); } } //var dbns = (await (await _client.ListDatabasesAsync()).ToListAsync()).Select(x => x["name"].AsString); //foreach (var dbn in dbns) //{ // Guid ignored; // if (Guid.TryParse(dbn, out ignored)) // await _client.DropDatabaseAsync(dbn); //} if (failed != null) { ExceptionDispatchInfo.Capture(failed).Throw(); } }
public async Task Cleanup() { try { await client.DropDatabaseAsync(databaseName); } // ReSharper disable once EmptyGeneralCatchClause catch (Exception) { } }
private async Task Cleanup() { if (Config.ShouldCleanupOnFinish) { Console.WriteLine("Deleting Database {0}", Config.DatabaseName); await Client.DropDatabaseAsync(Config.DatabaseName); } }
public async Task Cleanup() { try { await client.DropDatabaseAsync(databaseName); } catch (Exception) { } }
public void DropDatabases() { var databaseNames = new List <string>() { _userDbName, _surveyDbName, _linkDbName, _sessionDbName }; Parallel.ForEach(databaseNames, name => { _mongoClient.DropDatabaseAsync(name); }); }
/// <summary> /// Drop databse. /// </summary> /// <param name="dbName"></param> /// <returns></returns> public async Task Drop(string dbName = DatabaseConstants.DefaultDatabaseName) { if (_client == null) { await MongoDbProvider.DropDatabase(dbName); } else { await _client.DropDatabaseAsync(dbName); } }
private async void OnClear(object sender, RoutedEventArgs e) { try { await _mongoClient.DropDatabaseAsync("testrs"); } catch (Exception ex) { Debug.WriteLine(ex); MessageBox.Show("Error dropping database"); } }
public async Task CreateDatabase() { var defaults = StoreSettings.DefaultSettings(); Assert.False(await _client.DatabaseExistsAsync(_database)); _ps.Invoke(); Assert.True(await _client.DatabaseExistsAsync(_database)); var db = _client.GetDatabase(_database); Assert.True(await db.CollectionExistsAsync(defaults.AuthorizationCodeCollection), "Authoriz"); Assert.True(await db.CollectionExistsAsync(defaults.ClientCollection)); Assert.True(await db.CollectionExistsAsync(defaults.ConsentCollection)); Assert.True(await db.CollectionExistsAsync(defaults.RefreshTokenCollection)); Assert.True(await db.CollectionExistsAsync(defaults.ScopeCollection)); Assert.True(await db.CollectionExistsAsync(defaults.TokenHandleCollection)); await _client.DropDatabaseAsync(_database); }
public async Task Stream_ExecuteCorrectOperationsInCorrectOrder() { var tailer = new Tailer(m_client); IOutlet outlet = Substitute.For <IOutlet>(); var stream = new Stream(tailer, outlet); Oplog lastOplog = await tailer.GetMostRecentOplog(); var databaseName = "_Test_MongoRiver"; var collectionName = "_Test_MongoRiver"; var newCollectionName = string.Concat(collectionName, "_foo"); var insertedDocument = new FooBarDocument { Id = "foo", Bar = "baz" }; var filterDocument = new BsonDocument("_id", "foo"); var updatedDocument = new FooBarDocument { Id = "foo", Bar = "qux" }; var indexName = "FooBar_Index"; var indexKeyDocument = new BsonDocument("Bar", 1); var indexOptionsDocument = new BsonDocument("name", indexName); IMongoDatabase database = m_client.GetDatabase(databaseName); IMongoCollection <FooBarDocument> collection = database.GetCollection <FooBarDocument>(collectionName); await collection.InsertOneAsync(insertedDocument); await collection.ReplaceOneAsync(filterDocument, updatedDocument); await collection.DeleteOneAsync(filterDocument); IndexKeysDefinition <FooBarDocument> indexDef = new IndexKeysDefinitionBuilder <FooBarDocument>().Ascending(d => d.Bar); await collection.Indexes.CreateOneAsync(indexDef, new CreateIndexOptions { Name = indexName }); await collection.Indexes.DropOneAsync(indexName); await database.RenameCollectionAsync(collectionName, newCollectionName); await database.DropCollectionAsync(newCollectionName); await m_client.DropDatabaseAsync(databaseName); await RunStream(stream, lastOplog); outlet.Received(9).UpdateOptime(Arg.Any <BsonTimestamp>()); Received.InOrder(() => { outlet.CreateCollection(databaseName, collectionName, new BsonDocument()); outlet.Insert(databaseName, collectionName, insertedDocument.ToBsonDocument()); outlet.Update(databaseName, collectionName, filterDocument, updatedDocument.ToBsonDocument()); outlet.Delete(databaseName, collectionName, filterDocument); outlet.CreateIndex(databaseName, collectionName, indexKeyDocument, indexOptionsDocument); outlet.DeleteIndex(databaseName, collectionName, indexName); outlet.RenameCollection(databaseName, collectionName, newCollectionName); outlet.DeleteCollection(databaseName, newCollectionName); outlet.DeleteDatabase(databaseName); }); }
public async Task RemoveDatabase() { await _client.DropDatabaseAsync(_settings.Database); }
public void DropDatabase() { m_Client.DropDatabaseAsync(_settings.Database).Wait(); }
public async Task SetupAsync() { // Drop the database between each test await _client.DropDatabaseAsync(_dbname); }
public async Task DeleteDatabase() { await _client.DropDatabaseAsync(_databaseName); }
public async Task Initialize(BenchmarkConfig config) { Config = config; var userName = Config.CosmosDbName; var mongoConnectionString = $"mongodb://{userName}:{Config.AuthorizationKey}@{Config.CosmosDbName}.documents.azure.com:10255/?ssl=true&replicaSet=globaldb"; var settings = MongoClientSettings.FromUrl(new MongoUrl(mongoConnectionString)); settings.SslSettings = new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 }; settings.ConnectionMode = ConnectionMode.Direct; Client = new MongoClient(settings); var collectionDescription = await GetCollectionIfExists(Client, Config.DatabaseName, Config.CollectionName); if (Config.ShouldCleanupOnStart || collectionDescription == null) { if (collectionDescription != null) { await Client.DropDatabaseAsync(Config.DatabaseName); } Database = Client.GetDatabase(Config.DatabaseName); Console.WriteLine("Creating database {0}", Config.DatabaseName); if (!string.IsNullOrEmpty(Config.PartitionKey)) { var result = await Database.RunCommandAsync <BsonDocument>(new BsonDocument { { "enableSharding", $"{Config.DatabaseName}" } }); result = await Database.RunCommandAsync <BsonDocument>(new BsonDocument { { "shardCollection", $"{Config.DatabaseName}.{Config.CollectionName}" }, { "key", new BsonDocument { { $"{Config.PartitionKey.Replace("/", "")}", "hashed" } } } }); } else { if (Config.CollectionThroughput > 10000) { throw new InvalidOperationException("MongoDB collections without partition key have a fixed size collection and only support 10K max RU's"); } await Database.CreateCollectionAsync(Config.CollectionName, new CreateCollectionOptions() { }); } // Hack to set collection RU's using DocumentDB API await DocumentDbApi.VerifyCollectionThroughput(Config); } else { Database = Client.GetDatabase(Config.DatabaseName); } Collection = Database.GetCollection <BsonDocument>(Config.CollectionName); if (!string.IsNullOrEmpty(Config.PartitionKey)) { PartitionKeyProperty = Config.PartitionKey.Replace("/", ""); } }
/// <inheritdoc /> public virtual Task DropDatabaseAsync(CancellationToken cancellationToken = default(CancellationToken)) => _mongoClient.DropDatabaseAsync(new MongoDbModelAnnotations(_model).Database, cancellationToken);
public Task DropDatabaseAsync(string name, CancellationToken cancellationToken = default(CancellationToken)) { return(wrapped.DropDatabaseAsync(name, cancellationToken)); }
public async Task DropDatabase(string database) { await _client.DropDatabaseAsync(database); }