Browse Source

Small refactoring.

pull/4200/head
maliming 6 years ago
parent
commit
3acc5c8c85
  1. 4
      framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AbpBlobStoringAzureModule.cs
  2. 4
      framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AzureBlobProvider.cs
  3. 12
      framework/test/Volo.Abp.BlobStoring.Azure.Tests/Volo/Abp/BlobStoring/Azure/AbpBlobStoringAzureTestModule.cs
  4. 7
      framework/test/Volo.Abp.BlobStoring.Azure.Tests/Volo/Abp/BlobStoring/Azure/AzureBlobContainer_Tests.cs

4
framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AbpBlobStoringAzureModule.cs

@ -2,9 +2,7 @@
namespace Volo.Abp.BlobStoring.Azure namespace Volo.Abp.BlobStoring.Azure
{ {
[DependsOn( [DependsOn(typeof(AbpBlobStoringModule))]
typeof(AbpBlobStoringModule)
)]
public class AbpBlobStoringAzureModule : AbpModule public class AbpBlobStoringAzureModule : AbpModule
{ {

4
framework/src/Volo.Abp.BlobStoring.Azure/Volo/Abp/BlobStoring/Azure/AzureBlobProvider.cs

@ -45,7 +45,6 @@ namespace Volo.Abp.BlobStoring.Azure
} }
var download = await blobClient.DownloadAsync(); var download = await blobClient.DownloadAsync();
var memoryStream = new MemoryStream(); var memoryStream = new MemoryStream();
await download.Value.Content.CopyToAsync(memoryStream); await download.Value.Content.CopyToAsync(memoryStream);
return memoryStream; return memoryStream;
@ -65,8 +64,7 @@ namespace Volo.Abp.BlobStoring.Azure
private static async Task<bool> BlobExistsAsync(BlobClient blobClient) private static async Task<bool> BlobExistsAsync(BlobClient blobClient)
{ {
var response = await blobClient.ExistsAsync(); return (await blobClient.ExistsAsync()).Value;
return response.Value;
} }
} }
} }

12
framework/test/Volo.Abp.BlobStoring.Azure.Tests/Volo/Abp/BlobStoring/Azure/AbpBlobStoringAzureTestModule.cs

@ -12,7 +12,9 @@ namespace Volo.Abp.BlobStoring.Azure
)] )]
public class AbpBlobStoringAzureTestModule : AbpModule public class AbpBlobStoringAzureTestModule : AbpModule
{ {
public static string UserSecretsId = "9f0d2c00-80c1-435b-bfab-2c39c8249091"; private const string UserSecretsId = "9f0d2c00-80c1-435b-bfab-2c39c8249091";
private string _connectionString;
private readonly string _randomContainerName = "abp-azure-test-container-" + Guid.NewGuid().ToString("N"); private readonly string _randomContainerName = "abp-azure-test-container-" + Guid.NewGuid().ToString("N");
@ -25,7 +27,9 @@ namespace Volo.Abp.BlobStoring.Azure
var configuration = context.Services.GetConfiguration(); var configuration = context.Services.GetConfiguration();
var blobServiceClient = new BlobServiceClient(configuration["Azure:ConnectionString"]); _connectionString = configuration["Azure:ConnectionString"];
var blobServiceClient = new BlobServiceClient(_connectionString);
blobServiceClient.CreateBlobContainer(_randomContainerName); blobServiceClient.CreateBlobContainer(_randomContainerName);
Configure<AbpBlobStoringOptions>(options => Configure<AbpBlobStoringOptions>(options =>
@ -34,7 +38,7 @@ namespace Volo.Abp.BlobStoring.Azure
{ {
containerConfiguration.UseAzure(azure => containerConfiguration.UseAzure(azure =>
{ {
azure.ConnectionString = configuration["Azure:ConnectionString"]; azure.ConnectionString = _connectionString;
azure.ContainerName = _randomContainerName; azure.ContainerName = _randomContainerName;
}); });
}); });
@ -44,7 +48,7 @@ namespace Volo.Abp.BlobStoring.Azure
public override void OnApplicationShutdown(ApplicationShutdownContext context) public override void OnApplicationShutdown(ApplicationShutdownContext context)
{ {
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
var blobServiceClient = new BlobServiceClient(configuration["Azure:ConnectionString"]); var blobServiceClient = new BlobServiceClient(_connectionString);
blobServiceClient.DeleteBlobContainer(_randomContainerName); blobServiceClient.DeleteBlobContainer(_randomContainerName);
} }
} }

7
framework/test/Volo.Abp.BlobStoring.Azure.Tests/Volo/Abp/BlobStoring/Azure/AzureBlobContainer_Tests.cs

@ -1,9 +1,10 @@
using Xunit; using Xunit;
//#define I_HAVE_SET_THE_CORRECT_CONNECTIONSTRING_IN_THE_USERSECRETS_FILE
namespace Volo.Abp.BlobStoring.Azure namespace Volo.Abp.BlobStoring.Azure
{ {
#if I_HAVE_SET_THE_CORRECT_CONNECTION_STRING_IN_THE_USERSECRETS_FILE /*
//Please set the correct connection string in secrets.json and continue the test.
public class AzureBlobContainer_Tests : BlobContainer_Tests<AbpBlobStoringAzureTestModule> public class AzureBlobContainer_Tests : BlobContainer_Tests<AbpBlobStoringAzureTestModule>
{ {
public AzureBlobContainer_Tests() public AzureBlobContainer_Tests()
@ -11,5 +12,5 @@ namespace Volo.Abp.BlobStoring.Azure
} }
} }
#endif */
} }

Loading…
Cancel
Save