Skip to content

Commit

Permalink
[Storage] [DataMovement] [Samples] Randomize Container Names (Azure#3…
Browse files Browse the repository at this point in the history
…3558)

* Randomize container name in DataMovement Sample to allow delete container delay between test runs

* Remove random space
  • Loading branch information
amnguye authored Jan 31, 2023
1 parent 4dc0c01 commit 7300977
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task UploadSingle_ConnectionStringAsync()
// using an environment variable.

string connectionString = ConnectionString;
string containerName = ("sample-container");
string containerName = Randomize("sample-container");

// Create a client that can authenticate with a connection string
BlobContainerClient container = new BlobContainerClient(connectionString, containerName);
Expand Down Expand Up @@ -103,13 +103,14 @@ public async Task DownloadSingle_SharedKeyAuthAsync()
string accountName = StorageAccountName;
string accountKey = StorageAccountKey;
Uri serviceUri = StorageAccountBlobUri;
string containerName = Randomize("sample-container");

// Create a SharedKeyCredential that we can use to authenticate
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);

// Create a client that can authenticate with a SharedKeyCredential
BlobServiceClient service = new BlobServiceClient(serviceUri, credential);
BlobContainerClient container = service.GetBlobContainerClient("sample-container");
BlobContainerClient container = service.GetBlobContainerClient(containerName);
await container.CreateIfNotExistsAsync();

try
Expand Down Expand Up @@ -204,8 +205,7 @@ public async Task UploadDirectory_SasAsync()
// Create a client that can authenticate with the SAS URI
BlobServiceClient service = new BlobServiceClient(sasUri.Uri);

string connectionString = ConnectionString;
string containerName = "sample-container";
string containerName = Randomize("sample-container");

// Create a client that can authenticate with a connection string
BlobContainerClient container = service.GetBlobContainerClient(containerName);
Expand Down Expand Up @@ -296,7 +296,7 @@ public async Task UploadDirectory_CompletedEventHandler()
BlobServiceClient service = new BlobServiceClient(sasUri.Uri);

string connectionString = ConnectionString;
string containerName = ("sample-container");
string containerName = Randomize("sample-container");

// Create a client that can authenticate with a connection string
BlobContainerClient container = service.GetBlobContainerClient(containerName);
Expand Down Expand Up @@ -383,7 +383,7 @@ public async Task UploadDirectory_EventHandler_SasAsync()
BlobServiceClient service = new BlobServiceClient(sasUri.Uri);

string connectionString = ConnectionString;
string containerName = ("sample-container");
string containerName = Randomize("sample-container");

// Create a client that can authenticate with a connection string
BlobContainerClient container = service.GetBlobContainerClient(containerName);
Expand Down Expand Up @@ -468,7 +468,7 @@ public async Task DownloadDirectory_EventHandler_ActiveDirectoryAuthAsync()

// Create a client that can authenticate using our token credential
BlobServiceClient service = new BlobServiceClient(ActiveDirectoryBlobUri, credential);
string containerName = "sample-container";
string containerName = Randomize("sample-container");

// Create a client that can authenticate with a connection string
BlobContainerClient container = service.GetBlobContainerClient(containerName);
Expand Down Expand Up @@ -548,7 +548,7 @@ public async Task CopySingle_ConnectionStringAsync()
// using an environment variable.

string connectionString = ConnectionString;
string containerName = "sample-container";
string containerName = Randomize("sample-container");

// Create a client that can authenticate with a connection string
BlobContainerClient container = new BlobContainerClient(connectionString, containerName);
Expand Down Expand Up @@ -609,13 +609,14 @@ public async Task CopyDirectory()
string accountName = StorageAccountName;
string accountKey = StorageAccountKey;
Uri serviceUri = StorageAccountBlobUri;
string containerName = Randomize("sample-container");

// Create a SharedKeyCredential that we can use to authenticate
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);

// Create a client that can authenticate with a connection string
BlobServiceClient service = new BlobServiceClient(serviceUri, credential);
BlobContainerClient container = service.GetBlobContainerClient("sample-container");
BlobContainerClient container = service.GetBlobContainerClient(containerName);

// Make a service request to verify we've successfully authenticated
await container.CreateIfNotExistsAsync();
Expand Down

0 comments on commit 7300977

Please sign in to comment.