Browse Source

Added initial tests for the file system blob container.

pull/4127/head
Halil İbrahim Kalkan 6 years ago
parent
commit
49da37d1ad
  1. 1
      framework/src/Volo.Abp.BlobStoring.FileSystem/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobProvider.cs
  2. 4
      framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainer.cs
  3. 26
      framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurations.cs
  4. 1
      framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo.Abp.BlobStoring.FileSystem.Tests.csproj
  5. 7
      framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/AbpBlobStoringFileSystemTestModule.cs
  6. 2
      framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/BlogFilePathCalculator_Tests.cs
  7. 10
      framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/FileSystemBlobContainer_Tests.cs
  8. 8
      framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/TestObjects/TestContainer.cs
  9. 45
      framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/BlobContainer_Tests.cs

1
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 namespace Volo.Abp.BlobStoring.FileSystem
{ {
//TODO: What if the file is being used on create, delete or read? //TODO: What if the file is being used on create, delete or read?
//TODO: Implement all methods truly async!
public class FileSystemBlobProvider : BlobProviderBase, ITransientDependency public class FileSystemBlobProvider : BlobProviderBase, ITransientDependency
{ {

4
framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainer.cs

@ -147,11 +147,11 @@ namespace Volo.Abp.BlobStoring
); );
} }
public virtual Task<Stream> GetAsync( public virtual async Task<Stream> GetAsync(
string name, string name,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var stream = Provider.GetOrNullAsync( var stream = await Provider.GetOrNullAsync(
new BlobProviderGetArgs( new BlobProviderGetArgs(
ContainerName, ContainerName,
Configuration, Configuration,

26
framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurations.cs

@ -6,14 +6,17 @@ namespace Volo.Abp.BlobStoring
{ {
public class BlobContainerConfigurations public class BlobContainerConfigurations
{ {
public BlobContainerConfiguration Default { get; } private BlobContainerConfiguration Default => GetConfiguration<DefaultContainer>();
private readonly Dictionary<string, BlobContainerConfiguration> _containers; private readonly Dictionary<string, BlobContainerConfiguration> _containers;
public BlobContainerConfigurations() public BlobContainerConfigurations()
{ {
Default = new BlobContainerConfiguration(); _containers = new Dictionary<string, BlobContainerConfiguration>
_containers = new Dictionary<string, BlobContainerConfiguration>(); {
//Add default container
[BlobContainerNameAttribute.GetContainerName<DefaultContainer>()] = new BlobContainerConfiguration()
};
} }
public BlobContainerConfigurations Configure<TContainer>( public BlobContainerConfigurations Configure<TContainer>(
@ -32,7 +35,12 @@ namespace Volo.Abp.BlobStoring
Check.NotNullOrWhiteSpace(name, nameof(name)); Check.NotNullOrWhiteSpace(name, nameof(name));
Check.NotNull(configureAction, nameof(configureAction)); Check.NotNull(configureAction, nameof(configureAction));
configureAction(_containers.GetOrAdd(name, () => new BlobContainerConfiguration(Default))); configureAction(
_containers.GetOrAdd(
name,
() => new BlobContainerConfiguration(Default)
)
);
return this; return this;
} }
@ -43,6 +51,16 @@ namespace Volo.Abp.BlobStoring
return this; return this;
} }
public BlobContainerConfigurations ConfigureAll(Action<string, BlobContainerConfiguration> configureAction)
{
foreach (var container in _containers)
{
configureAction(container.Key, container.Value);
}
return this;
}
[NotNull] [NotNull]
public BlobContainerConfiguration GetConfiguration<TContainer>() public BlobContainerConfiguration GetConfiguration<TContainer>()
{ {

1
framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo.Abp.BlobStoring.FileSystem.Tests.csproj

@ -12,6 +12,7 @@
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> <ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" /> <ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<ProjectReference Include="..\Volo.Abp.BlobStoring.Tests\Volo.Abp.BlobStoring.Tests.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

7
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 namespace Volo.Abp.BlobStoring.FileSystem
{ {
[DependsOn( [DependsOn(
typeof(AbpBlobStoringFileSystemModule) typeof(AbpBlobStoringFileSystemModule),
typeof(AbpBlobStoringTestModule)
)] )]
public class AbpBlobStoringFileSystemTestModule : AbpModule public class AbpBlobStoringFileSystemTestModule : AbpModule
{ {
@ -13,9 +14,9 @@ namespace Volo.Abp.BlobStoring.FileSystem
{ {
Configure<AbpBlobStoringOptions>(options => Configure<AbpBlobStoringOptions>(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")); fileSystem.BasePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));
}); });

2
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"); ).ShouldBe($"C:{separator}my-files{separator}host{separator}my-blob");
} }
private BlobProviderArgs GetArgs( private static BlobProviderArgs GetArgs(
string basePath, string basePath,
string containerName, string containerName,
string blobName, string blobName,

10
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<AbpBlobStoringFileSystemTestModule>
{
public FileSystemBlobContainer_Tests()
{
}
}
}

8
framework/test/Volo.Abp.BlobStoring.FileSystem.Tests/Volo/Abp/BlobStoring/FileSystem/TestObjects/TestContainer.cs

@ -1,8 +0,0 @@
namespace Volo.Abp.BlobStoring.FileSystem.TestObjects
{
[BlobContainerName("TestContainer")]
public class TestContainer
{
}
}

45
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<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
{
protected IBlobContainer<TestContainer1> Container { get; }
protected BlobContainer_Tests()
{
Container = GetRequiredService<IBlobContainer<TestContainer1>>();
}
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();
}
}
}
}
Loading…
Cancel
Save