From 1f41cd5671b2c142a266b30e7bf56d7e4da8aea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Mon, 25 May 2020 22:32:19 +0300 Subject: [PATCH] Introduce AbpBlobStoringOptions --- .../Abp/BlobStoring/AbpBlobStoringOptions.cs | 12 ++++++++ .../BlobStoring/BlobContainerConfiguration.cs | 9 ++++++ .../BlobContainerConfigurationDictionary.cs | 22 ++++++++++++++ .../AbpBlobStoringOptions_Tests.cs | 29 +++++++++++++++++++ .../BlobStoring/AbpBlobStoringTestModule.cs | 16 +++++++++- .../Volo/Abp/BlobStoring/TestContainer1.cs | 12 ++++++++ 6 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/AbpBlobStoringOptions.cs create mode 100644 framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfiguration.cs create mode 100644 framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurationDictionary.cs create mode 100644 framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringOptions_Tests.cs create mode 100644 framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/TestContainer1.cs diff --git a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/AbpBlobStoringOptions.cs b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/AbpBlobStoringOptions.cs new file mode 100644 index 0000000000..5c8fbe4666 --- /dev/null +++ b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/AbpBlobStoringOptions.cs @@ -0,0 +1,12 @@ +namespace Volo.Abp.BlobStoring +{ + public class AbpBlobStoringOptions + { + public BlobContainerConfigurationDictionary Containers { get; set; } + + public AbpBlobStoringOptions() + { + Containers = new BlobContainerConfigurationDictionary(); + } + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfiguration.cs b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfiguration.cs new file mode 100644 index 0000000000..096e5f9a67 --- /dev/null +++ b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfiguration.cs @@ -0,0 +1,9 @@ +using System.Collections.Generic; + +namespace Volo.Abp.BlobStoring +{ + public class BlobContainerConfiguration : Dictionary + { + + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurationDictionary.cs b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurationDictionary.cs new file mode 100644 index 0000000000..4ea2d2ba6e --- /dev/null +++ b/framework/src/Volo.Abp.BlobStoring/Volo/Abp/BlobStoring/BlobContainerConfigurationDictionary.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; + +namespace Volo.Abp.BlobStoring +{ + public class BlobContainerConfigurationDictionary : Dictionary + { + public BlobContainerConfigurationDictionary Configure(Action configureAction) + { + return Configure( + BlobContainerNameAttribute.GetContainerName(), + configureAction + ); + } + + public BlobContainerConfigurationDictionary Configure(string name, Action configureAction) + { + configureAction(this.GetOrAdd(name, () => new BlobContainerConfiguration())); + return this; + } + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringOptions_Tests.cs b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringOptions_Tests.cs new file mode 100644 index 0000000000..250ec0b737 --- /dev/null +++ b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringOptions_Tests.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; +using Microsoft.Extensions.Options; +using Shouldly; +using Xunit; + +namespace Volo.Abp.BlobStoring +{ + public class AbpBlobStoringOptions_Tests : AbpBlobStoringTestBase + { + private readonly AbpBlobStoringOptions _options; + + public AbpBlobStoringOptions_Tests() + { + _options = GetRequiredService>().Value; + } + + [Fact] + public void Should_Property_Set_And_Get_Options_For_Different_Containers() + { + var testContainer1Config = _options.Containers + .GetOrDefault(BlobContainerNameAttribute.GetContainerName()); + testContainer1Config.ShouldContainKeyAndValue("TestConfig1", "TestValue1"); + + var testContainer2Config = _options.Containers + .GetOrDefault(BlobContainerNameAttribute.GetContainerName()); + testContainer2Config.ShouldContainKeyAndValue("TestConfig2", "TestValue2"); + } + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestModule.cs b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestModule.cs index 63a0c5deb5..429349d28f 100644 --- a/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestModule.cs +++ b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/AbpBlobStoringTestModule.cs @@ -8,6 +8,20 @@ namespace Volo.Abp.BlobStoring )] public class AbpBlobStoringTestModule : AbpModule { - + public override void ConfigureServices(ServiceConfigurationContext context) + { + Configure(options => + { + options.Containers + .Configure(container => + { + container["TestConfig1"] = "TestValue1"; + }) + .Configure(container => + { + container["TestConfig2"] = "TestValue2"; + }); + }); + } } } \ No newline at end of file diff --git a/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/TestContainer1.cs b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/TestContainer1.cs new file mode 100644 index 0000000000..1c11f61d50 --- /dev/null +++ b/framework/test/Volo.Abp.BlobStoring.Tests/Volo/Abp/BlobStoring/TestContainer1.cs @@ -0,0 +1,12 @@ +namespace Volo.Abp.BlobStoring +{ + public class TestContainer1 + { + + } + + public class TestContainer2 + { + + } +} \ No newline at end of file