-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
fb8b051
commit e1d83df
Showing
135 changed files
with
3,016 additions
and
3,610 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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"version": 1, | ||
"isRoot": true, | ||
"tools": { | ||
"dotnet-reportgenerator-globaltool": { | ||
"version": "5.1.17", | ||
"commands": [ | ||
"reportgenerator" | ||
] | ||
} | ||
} | ||
} |
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
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
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 |
---|---|---|
@@ -0,0 +1,132 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Azure; | ||
using Azure.Storage; | ||
using Azure.Storage.Blobs; | ||
using NUnit.Framework; | ||
|
||
namespace Testing.Common | ||
{ | ||
public class AzureStorageManager | ||
{ | ||
#pragma warning disable | ||
// This the default test secret available in public MS documentation | ||
private static readonly string DefaultAzuriteConnectionString = | ||
"DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1;"; | ||
#pragma warning restore | ||
private string _storageContainerName; | ||
|
||
private readonly string _storageAccountName; | ||
private readonly string _storageAccountKey; | ||
|
||
private BlobContainerClient _blobContainerClient; | ||
private BlobClient _blobClient; | ||
|
||
public AzureStorageManager() | ||
{ | ||
} | ||
|
||
public AzureStorageManager(string accountName, string accountKey, string containerName) | ||
{ | ||
_storageAccountName = accountName; | ||
_storageAccountKey = accountKey; | ||
_storageContainerName = containerName; | ||
} | ||
|
||
public AzureStorageManager SetStorageContainerName(string storageContainerName) | ||
{ | ||
_storageContainerName = storageContainerName; | ||
return this; | ||
} | ||
|
||
public AzureStorageManager CreateBlobClient(string filePathWithoutExtension) | ||
{ | ||
_blobContainerClient = CreateContainerClient(); | ||
_blobClient = _blobContainerClient.GetBlobClient($"{filePathWithoutExtension}.mp4"); | ||
return this; | ||
} | ||
|
||
public AzureStorageManager CreateBlobClient(string filePathWithoutExtension, string connectionString) | ||
{ | ||
_blobContainerClient = CreateContainerClient(connectionString); | ||
_blobClient = _blobContainerClient.GetBlobClient($"{filePathWithoutExtension}.mp4"); | ||
return this; | ||
} | ||
|
||
public AzureStorageManager CreateBlobContainerClient(string connectionString) | ||
{ | ||
_blobContainerClient = CreateContainerClient(connectionString); | ||
return this; | ||
} | ||
|
||
public async IAsyncEnumerable<BlobClient> GetAllBlobsAsync(string filePathNamePrefix) | ||
{ | ||
await foreach (var page in _blobContainerClient.GetBlobsAsync(prefix: filePathNamePrefix)) | ||
{ | ||
yield return _blobContainerClient.GetBlobClient(page.Name); | ||
} | ||
} | ||
|
||
public async Task UploadAudioFileToStorage(string file) | ||
{ | ||
await _blobClient.UploadAsync(file); | ||
|
||
if (!await _blobClient.ExistsAsync()) | ||
{ | ||
throw new RequestFailedException($"Can not find file: {file}"); | ||
} | ||
|
||
TestContext.WriteLine($"Uploaded audio file to : {file}"); | ||
} | ||
|
||
public async Task UploadFileToStorage(string localFileName, string filePathOnStorage) | ||
{ | ||
var blobClient = _blobContainerClient.GetBlobClient(filePathOnStorage); | ||
|
||
await blobClient.UploadAsync(localFileName); | ||
|
||
if (!await blobClient.ExistsAsync()) | ||
{ | ||
throw new RequestFailedException($"Can not find file: {localFileName} with full path {filePathOnStorage}"); | ||
} | ||
|
||
TestContext.WriteLine($"Uploaded audio file to : {localFileName} with full path: {filePathOnStorage}"); | ||
} | ||
|
||
public async Task<bool> VerifyAudioFileExistsInStorage() | ||
{ | ||
return await _blobClient.ExistsAsync(); | ||
} | ||
|
||
public async Task RemoveAudioFileFromStorage() | ||
{ | ||
await _blobClient.DeleteAsync(); | ||
TestContext.WriteLine("Deleted audio file"); | ||
} | ||
|
||
public static BlobServiceClient CreateAzuriteBlobServiceClient(string connectionString) | ||
{ | ||
connectionString ??= DefaultAzuriteConnectionString; | ||
TestContext.WriteLine($"Azure Connection string {connectionString}"); | ||
var serviceClient = new BlobServiceClient(connectionString, new BlobClientOptions {Retry = { MaxRetries = 2}}); | ||
return serviceClient; | ||
} | ||
|
||
private BlobContainerClient CreateContainerClient(string connectionString) | ||
{ | ||
var serviceClient = CreateAzuriteBlobServiceClient(connectionString); | ||
var containerClient = serviceClient.GetBlobContainerClient(_storageContainerName); | ||
containerClient.CreateIfNotExists(); | ||
return containerClient; | ||
} | ||
|
||
private BlobContainerClient CreateContainerClient() | ||
{ | ||
var storageSharedKeyCredential = new StorageSharedKeyCredential(_storageAccountName, _storageAccountKey); | ||
var serviceEndpoint = $"https://{_storageAccountName}.blob.core.windows.net/"; | ||
var serviceClient = new BlobServiceClient(new Uri(serviceEndpoint), storageSharedKeyCredential); | ||
return serviceClient.GetBlobContainerClient(_storageContainerName); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
VideoApi/Testing.Common/Configuration/ConfigRootBuilder.cs
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Testing.Common.Configuration | ||
{ | ||
public static class ConfigRootBuilder | ||
{ | ||
private const string UserSecretId = "9AECE566-336D-4D16-88FA-7A76C27321CD"; | ||
public static IConfigurationRoot Build(string userSecretId = UserSecretId, bool useSecrets = true) | ||
{ | ||
var builder = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.json") | ||
.AddJsonFile("appsettings.Development.json", true) | ||
.AddJsonFile("appsettings.Production.json", true); // CI write variables in the pipeline to this file | ||
|
||
if (useSecrets) | ||
{ | ||
builder = builder.AddUserSecrets(userSecretId); | ||
} | ||
|
||
return builder.AddEnvironmentVariables() | ||
.Build(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
namespace Testing.Common | ||
{ | ||
public static class FileManager | ||
{ | ||
public static string GetAssemblyDirectory() | ||
{ | ||
return AppDomain.CurrentDomain.BaseDirectory; | ||
} | ||
|
||
public static string CreateNewAudioFile(string originalFileName, string fileNameWithoutExtension, string path = "TestAudioFiles") | ||
{ | ||
var originalFilePath = Path.Join(GetAssemblyDirectory(), path, originalFileName); | ||
if (!File.Exists(originalFilePath)) | ||
{ | ||
throw new FileNotFoundException($"Unable to find audio file with path : {originalFilePath}"); | ||
} | ||
|
||
var fileWithExtension = $"{fileNameWithoutExtension}.mp4"; | ||
var newFilePath = Path.Join(GetAssemblyDirectory(), path, fileWithExtension); | ||
File.Copy(originalFilePath, newFilePath, true); | ||
return newFilePath; | ||
} | ||
|
||
public static void RemoveLocalAudioFile(string filepath) | ||
{ | ||
if (!File.Exists(filepath)) | ||
{ | ||
throw new FileNotFoundException($"Unable to find audio file with path : {filepath}"); | ||
} | ||
File.Delete(filepath); | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.