diff --git a/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobProvider.cs b/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobProvider.cs index b927bdbf47..a06c2c1018 100644 --- a/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobProvider.cs +++ b/framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobProvider.cs @@ -6,6 +6,7 @@ using Volo.Abp.IO; namespace Volo.Abp.BlobStoring.FileSystem { //TODO: What if the file is being used on create, delete or read? + //TODO: Implement all methods truly async! public class FileSystemBlobProvider : BlobProviderBase, ITransientDependency { diff --git a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainer.cs b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainer.cs index 700549e957..789271b6ee 100644 --- a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainer.cs +++ b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainer.cs @@ -147,11 +147,11 @@ namespace Volo.Abp.BlobStoring ); } - public virtual Task GetAsync( + public virtual async Task GetAsync( string name, CancellationToken cancellationToken = default) { - var stream = Provider.GetOrNullAsync( + var stream = await Provider.GetOrNullAsync( new BlobProviderGetArgs( ContainerName, Configuration, diff --git a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurations.cs b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurations.cs index 5e17793f21..ed2c5afe04 100644 --- a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurations.cs +++ b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurations.cs @@ -6,14 +6,17 @@ namespace Volo.Abp.BlobStoring { public class BlobContainerConfigurations { - public BlobContainerConfiguration Default { get; } + private BlobContainerConfiguration Default => GetConfiguration(); private readonly Dictionary _containers; public BlobContainerConfigurations() { - Default = new BlobContainerConfiguration(); - _containers = new Dictionary(); + _containers = new Dictionary + { + //Add default container + [BlobContainerNameAttribute.GetContainerName()] = new BlobContainerConfiguration() + }; } public BlobContainerConfigurations Configure( @@ -31,9 +34,14 @@ namespace Volo.Abp.BlobStoring { Check.NotNullOrWhiteSpace(name, nameof(name)); Check.NotNull(configureAction, nameof(configureAction)); - - configureAction(_containers.GetOrAdd(name, () => new BlobContainerConfiguration(Default))); - + + configureAction( + _containers.GetOrAdd( + name, + () => new BlobContainerConfiguration(Default) + ) + ); + return this; } @@ -42,7 +50,17 @@ namespace Volo.Abp.BlobStoring configureAction(Default); return this; } - + + public BlobContainerConfigurations ConfigureAll(Action configureAction) + { + foreach (var container in _containers) + { + configureAction(container.Key, container.Value); + } + + return this; + } + [NotNull] public BlobContainerConfiguration GetConfiguration() { @@ -54,7 +72,7 @@ namespace Volo.Abp.BlobStoring { Check.NotNullOrWhiteSpace(name, nameof(name)); - return _containers.GetOrDefault(name) ?? + return _containers.GetOrDefault(name) ?? Default; } } diff --git a/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo.Abp.BlobStoring.FileSystem.Tests.csproj b/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo.Abp.BlobStoring.FileSystem.Tests.csproj index 1ac7ba2414..b2741af89a 100644 --- a/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo.Abp.BlobStoring.FileSystem.Tests.csproj +++ b/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo.Abp.BlobStoring.FileSystem.Tests.csproj @@ -12,6 +12,7 @@ + diff --git a/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/AbpBlobStoringFileSystemTestModule.cs b/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/AbpBlobStoringFileSystemTestModule.cs index f151d8786d..a2ab6052bd 100644 --- a/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/AbpBlobStoringFileSystemTestModule.cs +++ b/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/AbpBlobStoringFileSystemTestModule.cs @@ -5,7 +5,8 @@ using Volo.Abp.Modularity; namespace Volo.Abp.BlobStoring.FileSystem { [DependsOn( - typeof(AbpBlobStoringFileSystemModule) + typeof(AbpBlobStoringFileSystemModule), + typeof(AbpBlobStoringTestModule) )] public class AbpBlobStoringFileSystemTestModule : AbpModule { @@ -13,9 +14,9 @@ namespace Volo.Abp.BlobStoring.FileSystem { Configure(options => { - options.Containers.ConfigureDefault(container => + options.Containers.ConfigureAll((containerName, containerConfiguration) => { - container.UseFileSystem(fileSystem => + containerConfiguration.UseFileSystem(fileSystem => { fileSystem.BasePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); }); diff --git a/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/BlogFilePathCalculator_Tests.cs b/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/BlogFilePathCalculator_Tests.cs index 2493dab733..f7b55de401 100644 --- a/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/BlogFilePathCalculator_Tests.cs +++ b/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/BlogFilePathCalculator_Tests.cs @@ -45,7 +45,7 @@ namespace Volo.Abp.BlobStoring.FileSystem ).ShouldBe($"C:{separator}my-files{separator}host{separator}my-blob"); } - private BlobProviderArgs GetArgs( + private static BlobProviderArgs GetArgs( string basePath, string containerName, string blobName, diff --git a/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobContainer_Tests.cs b/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobContainer_Tests.cs new file mode 100644 index 0000000000..cf2ca82398 --- /dev/null +++ b/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobContainer_Tests.cs @@ -0,0 +1,10 @@ +namespace Volo.Abp.BlobStoring.FileSystem +{ + public class FileSystemBlobContainer_Tests : BlobContainer_Tests + { + public FileSystemBlobContainer_Tests() + { + + } + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/TestObjects/TestContainer.cs b/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/TestObjects/TestContainer.cs deleted file mode 100644 index 91ac79f6c3..0000000000 --- a/framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/TestObjects/TestContainer.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Volo.Abp.BlobStoring.FileSystem.TestObjects -{ - [BlobContainerName("TestContainer")] - public class TestContainer - { - - } -} \ No newline at end of file diff --git a/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/BlobContainer_Tests.cs b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/BlobContainer_Tests.cs new file mode 100644 index 0000000000..195e51f335 --- /dev/null +++ b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/BlobContainer_Tests.cs @@ -0,0 +1,45 @@ +using System; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.BlobStoring.TestObjects; +using Volo.Abp.Modularity; +using Volo.Abp.Testing; +using Xunit; + +namespace Volo.Abp.BlobStoring +{ + public abstract class BlobContainer_Tests : AbpIntegratedTest + where TStartupModule : IAbpModule + { + protected IBlobContainer Container { get; } + + protected BlobContainer_Tests() + { + Container = GetRequiredService>(); + } + + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } + + [Fact] + public async Task SaveAsync() + { + var testContent = "test content".GetBytes(); + + using (var memoryStream = new MemoryStream(testContent)) + { + await Container.SaveAsync("test-blob-1", memoryStream); + } + + using (var stream = await Container.GetAsync("test-blob-1")) + { + var result = await stream.GetAllBytesAsync(); + result.SequenceEqual(testContent).ShouldBeTrue(); + } + } + } +} \ No newline at end of file