-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use random key for storage account in unit test
- Loading branch information
Showing
1 changed file
with
11 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,33 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using DurableTask.AzureStorage; | ||
using Microsoft.WindowsAzure.Storage; | ||
|
||
namespace Microsoft.Azure.WebJobs.Extensions.DurableTask.Tests | ||
{ | ||
internal class CustomTestStorageAccountProvider : IStorageAccountProvider | ||
{ | ||
private const string CustomConnectionString = "DefaultEndpointsProtocol=https;AccountName=test;AccountKey=dGVzdA==;EndpointSuffix=core.windows.net"; | ||
private readonly string customConnectionString; | ||
private readonly string customConnectionName; | ||
|
||
public CustomTestStorageAccountProvider(string connectionName) | ||
{ | ||
this.customConnectionName = connectionName; | ||
this.customConnectionString = $"DefaultEndpointsProtocol=https;AccountName=test;AccountKey={GenerateRandomKey()};EndpointSuffix=core.windows.net"; | ||
} | ||
|
||
public CloudStorageAccount GetCloudStorageAccount(string name) => | ||
CloudStorageAccount.Parse(name != this.customConnectionName ? TestHelpers.GetStorageConnectionString() : CustomConnectionString); | ||
CloudStorageAccount.Parse(name != this.customConnectionName ? TestHelpers.GetStorageConnectionString() : this.customConnectionString); | ||
|
||
public StorageAccountDetails GetStorageAccountDetails(string name) => | ||
new StorageAccountDetails { ConnectionString = name != this.customConnectionName ? TestHelpers.GetStorageConnectionString() : CustomConnectionString }; | ||
new StorageAccountDetails { ConnectionString = name != this.customConnectionName ? TestHelpers.GetStorageConnectionString() : this.customConnectionString }; | ||
|
||
private static string GenerateRandomKey() | ||
{ | ||
string key = Guid.NewGuid().ToString(); | ||
return Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(key)); | ||
} | ||
} | ||
} |