public async Task RunWithTemporaryDatabaseAsync(string instanceId, string databaseId, Func <string, Task> testFunction, params string[] extraStatements) { var operation = await DatabaseAdminClient.CreateDatabaseAsync(new CreateDatabaseRequest { ParentAsInstanceName = InstanceName.FromProjectInstance(ProjectId, instanceId), CreateStatement = $"CREATE DATABASE `{databaseId}`", ExtraStatements = { extraStatements }, }); var completedResponse = await operation.PollUntilCompletedAsync(); if (completedResponse.IsFaulted) { throw completedResponse.Exception; } try { await testFunction(databaseId); } finally { // Cleanup the test database. await DatabaseAdminClient.DropDatabaseAsync(DatabaseName.FormatProjectInstanceDatabase(ProjectId, instanceId, databaseId)); } }
/// <summary>Snippet for DropDatabaseAsync</summary> public async Task DropDatabaseAsync() { // Snippet: DropDatabaseAsync(DatabaseName,CallSettings) // Additional: DropDatabaseAsync(DatabaseName,CancellationToken) // Create client DatabaseAdminClient databaseAdminClient = await DatabaseAdminClient.CreateAsync(); // Initialize request argument(s) DatabaseName database = new DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"); // Make the request await databaseAdminClient.DropDatabaseAsync(database); // End snippet }
/// <summary>Snippet for DropDatabaseAsync</summary> public async Task DropDatabaseAsync_RequestObject() { // Snippet: DropDatabaseAsync(DropDatabaseRequest,CallSettings) // Create client DatabaseAdminClient databaseAdminClient = await DatabaseAdminClient.CreateAsync(); // Initialize request argument(s) DropDatabaseRequest request = new DropDatabaseRequest { DatabaseAsDatabaseName = new DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]"), }; // Make the request await databaseAdminClient.DropDatabaseAsync(request); // End snippet }