From 38aba327ccd5642cfafbc039bb37c2eda4fda131 Mon Sep 17 00:00:00 2001 From: liangshiwei Date: Wed, 27 Dec 2023 15:20:11 +0800 Subject: [PATCH] Add IMultiTenantUrlProvider --- framework/Volo.Abp.sln | 7 ++ .../MultiTenancy/IMultiTenantUrlProvider.cs | 9 +++ .../MultiTenancy/MultiTenantUrlProvider.cs | 78 +++++++++++++++++++ .../Volo.Abp.RemoteServices.csproj | 1 + .../Http/Client/RemoteServiceConfiguration.cs | 8 ++ .../RemoteServiceConfigurationProvider.cs | 33 ++++++-- .../RemoteServices/AbpRemoteServicesModule.cs | 2 + .../Abp/Ui/Navigation/Urls/AppUrlProvider.cs | 63 ++------------- .../MultiTenantUrlProivder_Tests.cs | 57 ++++++++++++++ .../Volo.Abp.RemoteServices.Tests.csproj | 17 ++++ .../Http/Client/AbpRemoteServicesTestBase.cs | 8 ++ .../Client/AbpRemoteServicesTestModule.cs | 13 ++++ ...emoteServiceConfigurationProvider_Tests.cs | 74 ++++++++++++++++++ 13 files changed, 308 insertions(+), 62 deletions(-) create mode 100644 framework/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/IMultiTenantUrlProvider.cs create mode 100644 framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantUrlProvider.cs create mode 100644 framework/test/Volo.Abp.MultiTenancy.Tests/Volo/Abp/MultiTenancy/MultiTenantUrlProivder_Tests.cs create mode 100644 framework/test/Volo.Abp.RemoteServices.Tests/Volo.Abp.RemoteServices.Tests.csproj create mode 100644 framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/AbpRemoteServicesTestBase.cs create mode 100644 framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/AbpRemoteServicesTestModule.cs create mode 100644 framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider_Tests.cs diff --git a/framework/Volo.Abp.sln b/framework/Volo.Abp.sln index 42339a60ac..b46a809403 100644 --- a/framework/Volo.Abp.sln +++ b/framework/Volo.Abp.sln @@ -463,6 +463,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Imaging.SkiaSharp" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.Imaging.SkiaSharp.Tests", "test\Volo.Abp.Imaging.SkiaSharp.Tests\Volo.Abp.Imaging.SkiaSharp.Tests.csproj", "{DFAF8763-D1D6-4EB4-B459-20E31007FE2F}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.RemoteServices.Tests", "test\Volo.Abp.RemoteServices.Tests\Volo.Abp.RemoteServices.Tests.csproj", "{DACD4485-61BE-4DE5-ACAE-4FFABC122500}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1381,6 +1383,10 @@ Global {DFAF8763-D1D6-4EB4-B459-20E31007FE2F}.Debug|Any CPU.Build.0 = Debug|Any CPU {DFAF8763-D1D6-4EB4-B459-20E31007FE2F}.Release|Any CPU.ActiveCfg = Release|Any CPU {DFAF8763-D1D6-4EB4-B459-20E31007FE2F}.Release|Any CPU.Build.0 = Release|Any CPU + {DACD4485-61BE-4DE5-ACAE-4FFABC122500}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DACD4485-61BE-4DE5-ACAE-4FFABC122500}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DACD4485-61BE-4DE5-ACAE-4FFABC122500}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DACD4485-61BE-4DE5-ACAE-4FFABC122500}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1614,6 +1620,7 @@ Global {F19A6E0C-F719-4ED9-A024-14E4B8D40883} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {198683D0-7DC6-40F2-B81B-8E446E70A9DE} = {5DF0E140-0513-4D0D-BE2E-3D4D85CD70E6} {DFAF8763-D1D6-4EB4-B459-20E31007FE2F} = {447C8A77-E5F0-4538-8687-7383196D04EA} + {DACD4485-61BE-4DE5-ACAE-4FFABC122500} = {447C8A77-E5F0-4538-8687-7383196D04EA} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5} diff --git a/framework/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/IMultiTenantUrlProvider.cs b/framework/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/IMultiTenantUrlProvider.cs new file mode 100644 index 0000000000..7e3bb097b7 --- /dev/null +++ b/framework/src/Volo.Abp.MultiTenancy.Abstractions/Volo/Abp/MultiTenancy/IMultiTenantUrlProvider.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; +using JetBrains.Annotations; + +namespace Volo.Abp.MultiTenancy; + +public interface IMultiTenantUrlProvider +{ + Task GetUrlAsync(string templateUrl); +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantUrlProvider.cs b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantUrlProvider.cs new file mode 100644 index 0000000000..47ac6105bb --- /dev/null +++ b/framework/src/Volo.Abp.MultiTenancy/Volo/Abp/MultiTenancy/MultiTenantUrlProvider.cs @@ -0,0 +1,78 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.MultiTenancy; + +public class MultiTenantUrlProvider : IMultiTenantUrlProvider , ITransientDependency +{ + public const string TenantPlaceHolder = "{0}"; + public const string TenantIdPlaceHolder = "{{tenantId}}"; + public const string TenantNamePlaceHolder = "{{tenantName}}"; + + protected ICurrentTenant CurrentTenant { get; } + protected ITenantStore TenantStore { get; } + + public MultiTenantUrlProvider( + ICurrentTenant currentTenant, + ITenantStore tenantStore) + { + CurrentTenant = currentTenant; + TenantStore = tenantStore; + } + + public virtual async Task GetUrlAsync(string templateUrl) + { + return await ReplacePlaceHoldersAsync(templateUrl); + } + + protected virtual async Task ReplacePlaceHoldersAsync(string templateUrl) + { + templateUrl = await ReplacePlaceHolderAsync(templateUrl, TenantIdPlaceHolder); + + templateUrl = await ReplacePlaceHolderAsync(templateUrl, TenantNamePlaceHolder); + + templateUrl = await ReplacePlaceHolderAsync(templateUrl, TenantPlaceHolder); + + return templateUrl; + } + + protected virtual async Task ReplacePlaceHolderAsync(string templateUrl, string placeHolder) + { + if (!templateUrl.Contains(placeHolder)) + { + return templateUrl; + } + + var placeHolderValue = string.Empty; + if (CurrentTenant.IsAvailable) + { + placeHolderValue = (placeHolder == TenantIdPlaceHolder ? CurrentTenant.Id!.Value.ToString() : await GetCurrentTenantNameAsync()) + "."; + } + + if (templateUrl.Contains(placeHolder + '.')) + { + placeHolder += '.'; + } + + templateUrl = templateUrl.Replace( + placeHolder, + placeHolderValue + ); + + return templateUrl; + } + + protected virtual async Task GetCurrentTenantNameAsync() + { + if (CurrentTenant.Id.HasValue && CurrentTenant.Name.IsNullOrEmpty()) + { + var tenantConfiguration = await TenantStore.FindAsync(CurrentTenant.Id.Value); + return tenantConfiguration!.Name; + } + + return CurrentTenant.Name!; + } +} \ No newline at end of file diff --git a/framework/src/Volo.Abp.RemoteServices/Volo.Abp.RemoteServices.csproj b/framework/src/Volo.Abp.RemoteServices/Volo.Abp.RemoteServices.csproj index b0f0ba2289..7b5fdf2289 100644 --- a/framework/src/Volo.Abp.RemoteServices/Volo.Abp.RemoteServices.csproj +++ b/framework/src/Volo.Abp.RemoteServices/Volo.Abp.RemoteServices.csproj @@ -18,6 +18,7 @@ + diff --git a/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs index 531b016a1d..881d783baf 100644 --- a/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs +++ b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfiguration.cs @@ -30,4 +30,12 @@ public class RemoteServiceConfiguration : Dictionary this[nameof(BaseUrl)] = baseUrl; this[nameof(Version)] = version; } + + public RemoteServiceConfiguration(RemoteServiceConfiguration configuration) + { + foreach (var keyValuePair in configuration) + { + this.Add(keyValuePair.Key, keyValuePair.Value); + } + } } diff --git a/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider.cs b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider.cs index db49557e94..c436fbc170 100644 --- a/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider.cs +++ b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider.cs @@ -1,25 +1,48 @@ using System.Threading.Tasks; using Microsoft.Extensions.Options; using Volo.Abp.DependencyInjection; +using Volo.Abp.MultiTenancy; namespace Volo.Abp.Http.Client; public class RemoteServiceConfigurationProvider : IRemoteServiceConfigurationProvider, IScopedDependency { protected AbpRemoteServiceOptions Options { get; } + protected IMultiTenantUrlProvider MultiTenantUrlProvider { get; } + protected ICurrentTenant CurrentTenant { get; } - public RemoteServiceConfigurationProvider(IOptionsMonitor options) + public RemoteServiceConfigurationProvider( + IOptionsMonitor options, + IMultiTenantUrlProvider multiTenantUrlProvider, + ICurrentTenant currentTenant) { + MultiTenantUrlProvider = multiTenantUrlProvider; + CurrentTenant = currentTenant; Options = options.CurrentValue; } - public Task GetConfigurationOrDefaultAsync(string name) + public virtual async Task GetConfigurationOrDefaultAsync(string name) { - return Task.FromResult(Options.RemoteServices.GetConfigurationOrDefault(name)); + return (await GetMultiTenantConfigurationAsync(Options.RemoteServices.GetConfigurationOrDefault(name)))!; } - public Task GetConfigurationOrDefaultOrNullAsync(string name) + public virtual async Task GetConfigurationOrDefaultOrNullAsync(string name) { - return Task.FromResult(Options.RemoteServices.GetConfigurationOrDefaultOrNull(name)); + return await GetMultiTenantConfigurationAsync(Options.RemoteServices.GetConfigurationOrDefaultOrNull(name)); + } + + protected virtual async Task GetMultiTenantConfigurationAsync(RemoteServiceConfiguration? configuration) + { + if (configuration == null) + { + return configuration; + } + + var multiTenantConfiguration = new RemoteServiceConfiguration(configuration) + { + BaseUrl = await MultiTenantUrlProvider.GetUrlAsync(configuration.BaseUrl) + }; + + return multiTenantConfiguration; } } diff --git a/framework/src/Volo.Abp.RemoteServices/Volo/Abp/RemoteServices/AbpRemoteServicesModule.cs b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/RemoteServices/AbpRemoteServicesModule.cs index dba4842597..43f1608c7c 100644 --- a/framework/src/Volo.Abp.RemoteServices/Volo/Abp/RemoteServices/AbpRemoteServicesModule.cs +++ b/framework/src/Volo.Abp.RemoteServices/Volo/Abp/RemoteServices/AbpRemoteServicesModule.cs @@ -1,9 +1,11 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Http.Client; using Volo.Abp.Modularity; +using Volo.Abp.MultiTenancy; namespace Volo.Abp.RemoteServices; +[DependsOn(typeof(AbpMultiTenancyAbstractionsModule))] public class AbpRemoteServicesModule : AbpModule { public override void ConfigureServices(ServiceConfigurationContext context) diff --git a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs index b8bebd95a5..179eb6e9a1 100644 --- a/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs +++ b/framework/src/Volo.Abp.UI.Navigation/Volo/Abp/Ui/Navigation/Urls/AppUrlProvider.cs @@ -13,29 +13,23 @@ namespace Volo.Abp.UI.Navigation.Urls; public class AppUrlProvider : IAppUrlProvider, ITransientDependency { - public const string TenantIdPlaceHolder = "{{tenantId}}"; - public const string TenantNamePlaceHolder = "{{tenantName}}"; - protected AppUrlOptions Options { get; } - protected ICurrentTenant CurrentTenant { get; } - protected ITenantStore TenantStore { get; } + protected IMultiTenantUrlProvider MultiTenantUrlProvider { get; } public ILogger Logger { get; set; } public AppUrlProvider( IOptions options, - ICurrentTenant currentTenant, - ITenantStore tenantStore) + IMultiTenantUrlProvider multiTenantUrlProvider) { - CurrentTenant = currentTenant; - TenantStore = tenantStore; + MultiTenantUrlProvider = multiTenantUrlProvider; Options = options.Value; Logger = NullLogger.Instance; } public virtual async Task GetUrlAsync(string appName, string? urlName = null) { - return await ReplacePlaceHoldersAsync( + return await MultiTenantUrlProvider.GetUrlAsync( await GetConfiguredUrl( appName, urlName @@ -59,8 +53,8 @@ public class AppUrlProvider : IAppUrlProvider, ITransientDependency { return url; } - - return await ReplacePlaceHoldersAsync(url!); + + return await MultiTenantUrlProvider.GetUrlAsync(url!); } protected virtual async Task GetConfiguredUrl(string appName, string? urlName) @@ -83,51 +77,6 @@ public class AppUrlProvider : IAppUrlProvider, ITransientDependency ); } - protected virtual async Task ReplacePlaceHoldersAsync(string url) - { - url = url.Replace( - TenantIdPlaceHolder, - CurrentTenant.Id.HasValue ? CurrentTenant.Id.Value.ToString() : "" - ); - - if (!url.Contains(TenantNamePlaceHolder)) - { - return url; - } - - var tenantNamePlaceHolder = TenantNamePlaceHolder; - - if (url.Contains(TenantNamePlaceHolder + '.')) - { - tenantNamePlaceHolder = TenantNamePlaceHolder + '.'; - } - - if (url.Contains(tenantNamePlaceHolder)) - { - if (CurrentTenant.Id.HasValue) - { - url = url.Replace(tenantNamePlaceHolder, await GetCurrentTenantNameAsync() + "."); - } - else - { - url = url.Replace(tenantNamePlaceHolder, ""); - } - } - - return url; - } - - private async Task GetCurrentTenantNameAsync() - { - if (CurrentTenant.Id.HasValue && CurrentTenant.Name.IsNullOrEmpty()) - { - var tenantConfiguration = await TenantStore.FindAsync(CurrentTenant.Id.Value); - return tenantConfiguration!.Name; - } - - return CurrentTenant.Name!; - } - public Task GetUrlOrNullAsync([NotNull] string appName, string? urlName = null) { var app = Options.Applications[appName]; diff --git a/framework/test/Volo.Abp.MultiTenancy.Tests/Volo/Abp/MultiTenancy/MultiTenantUrlProivder_Tests.cs b/framework/test/Volo.Abp.MultiTenancy.Tests/Volo/Abp/MultiTenancy/MultiTenantUrlProivder_Tests.cs new file mode 100644 index 0000000000..62a27ad059 --- /dev/null +++ b/framework/test/Volo.Abp.MultiTenancy.Tests/Volo/Abp/MultiTenancy/MultiTenantUrlProivder_Tests.cs @@ -0,0 +1,57 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.MultiTenancy.ConfigurationStore; +using Xunit; + +namespace Volo.Abp.MultiTenancy; + +public class MultiTenantUrlProivder_Tests : MultiTenancyTestBase +{ + private readonly ICurrentTenant _currentTenant; + private readonly IMultiTenantUrlProvider _multiTenantUrlProvider; + + private readonly Guid _tenantAId = Guid.NewGuid(); + + public MultiTenantUrlProivder_Tests() + { + _currentTenant = ServiceProvider.GetRequiredService(); + _multiTenantUrlProvider = ServiceProvider.GetRequiredService(); + } + protected override void BeforeAddApplication(IServiceCollection services) + { + services.Configure(options => + { + options.Tenants = + [ + new TenantConfiguration(_tenantAId, "TenantA") + ]; + }); + } + + [Fact] + public async Task GetUrlAsync() + { + var tenantNameHolderUrl = "https://{{tenantName}}.abp.io"; + var tenantIdHolderUrl = "https://{{tenantId}}.abp.io"; + var tenantHolderUrl = "https://{0}.abp.io"; + var hostUrl = "https://abp.io"; + + _currentTenant.Id.ShouldBeNull(); + (await _multiTenantUrlProvider.GetUrlAsync(tenantNameHolderUrl)).ShouldBe(hostUrl); + (await _multiTenantUrlProvider.GetUrlAsync(tenantIdHolderUrl)).ShouldBe(hostUrl); + (await _multiTenantUrlProvider.GetUrlAsync(tenantHolderUrl)).ShouldBe(hostUrl); + (await _multiTenantUrlProvider.GetUrlAsync(hostUrl)).ShouldBe(hostUrl); + + using (_currentTenant.Change(_tenantAId)) + { + _currentTenant.Id.ShouldBe(_tenantAId); + (await _multiTenantUrlProvider.GetUrlAsync(tenantNameHolderUrl)).ShouldBe("https://TenantA.abp.io"); + (await _multiTenantUrlProvider.GetUrlAsync(tenantIdHolderUrl)).ShouldBe("https://"+_tenantAId+".abp.io"); + (await _multiTenantUrlProvider.GetUrlAsync(tenantHolderUrl)).ShouldBe("https://TenantA.abp.io"); + (await _multiTenantUrlProvider.GetUrlAsync(hostUrl)).ShouldBe(hostUrl); + } + } + +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.RemoteServices.Tests/Volo.Abp.RemoteServices.Tests.csproj b/framework/test/Volo.Abp.RemoteServices.Tests/Volo.Abp.RemoteServices.Tests.csproj new file mode 100644 index 0000000000..45236b1241 --- /dev/null +++ b/framework/test/Volo.Abp.RemoteServices.Tests/Volo.Abp.RemoteServices.Tests.csproj @@ -0,0 +1,17 @@ + + + + + + net8.0 + + + + + + + + + + + diff --git a/framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/AbpRemoteServicesTestBase.cs b/framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/AbpRemoteServicesTestBase.cs new file mode 100644 index 0000000000..6fc2d64733 --- /dev/null +++ b/framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/AbpRemoteServicesTestBase.cs @@ -0,0 +1,8 @@ +using Volo.Abp.Testing; + +namespace Volo.Abp.Http.Client; + +public abstract class AbpRemoteServicesTestBase : AbpIntegratedTest +{ + +} diff --git a/framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/AbpRemoteServicesTestModule.cs b/framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/AbpRemoteServicesTestModule.cs new file mode 100644 index 0000000000..608991a489 --- /dev/null +++ b/framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/AbpRemoteServicesTestModule.cs @@ -0,0 +1,13 @@ +using Volo.Abp.Modularity; +using Volo.Abp.MultiTenancy; +using Volo.Abp.RemoteServices; + +namespace Volo.Abp.Http.Client; + +[DependsOn( + typeof(AbpMultiTenancyModule), + typeof(AbpRemoteServicesModule) +)] +public class AbpRemoteServicesTestModule: AbpModule +{ +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider_Tests.cs b/framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider_Tests.cs new file mode 100644 index 0000000000..a55633ec00 --- /dev/null +++ b/framework/test/Volo.Abp.RemoteServices.Tests/Volo/Abp/Http/Client/RemoteServiceConfigurationProvider_Tests.cs @@ -0,0 +1,74 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Shouldly; +using Volo.Abp.MultiTenancy; +using Volo.Abp.MultiTenancy.ConfigurationStore; +using Xunit; + +namespace Volo.Abp.Http.Client; + +public class RemoteServiceConfigurationProvider_Tests : AbpRemoteServicesTestBase +{ + private readonly ICurrentTenant _currentTenant; + private readonly IRemoteServiceConfigurationProvider _remoteServiceConfigurationProvider; + private readonly Guid _tenantAId = Guid.NewGuid(); + + public RemoteServiceConfigurationProvider_Tests() + { + _currentTenant = GetRequiredService(); + _remoteServiceConfigurationProvider = GetRequiredService(); + } + + protected override void AfterAddApplication(IServiceCollection services) + { + services.Configure(options => + { + options.RemoteServices[RemoteServiceConfigurationDictionary.DefaultName] = new RemoteServiceConfiguration("https://abp.io"); + options.RemoteServices["Identity"] = new RemoteServiceConfiguration("https://{{tenantName}}.abp.io"); + options.RemoteServices["Permission"] = new RemoteServiceConfiguration("https://{{tenantId}}.abp.io"); + options.RemoteServices["Setting"] = new RemoteServiceConfiguration("https://{0}.abp.io"); + }); + + services.Configure(options => + { + options.Tenants = + [ + new TenantConfiguration(_tenantAId, "TenantA") + ]; + }); + } + + [Fact] + public async Task GetConfigurationOrDefaultAsync() + { + _currentTenant.Id.ShouldBeNull(); + + var defaultConfiguration = await _remoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync(RemoteServiceConfigurationDictionary.DefaultName); + defaultConfiguration.BaseUrl.ShouldBe("https://abp.io"); + + var identityConfiguration = await _remoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Identity"); + identityConfiguration.BaseUrl.ShouldBe("https://abp.io"); + + var permissionConfiguration = await _remoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Permission"); + permissionConfiguration.BaseUrl.ShouldBe("https://abp.io"); + + var settingConfiguration = await _remoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Setting"); + settingConfiguration.BaseUrl.ShouldBe("https://abp.io"); + + using (_currentTenant.Change(_tenantAId, "TenantA")) + { + defaultConfiguration = await _remoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync(RemoteServiceConfigurationDictionary.DefaultName); + defaultConfiguration.BaseUrl.ShouldBe("https://abp.io"); + + identityConfiguration = await _remoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Identity"); + identityConfiguration.BaseUrl.ShouldBe($"https://{_currentTenant.Name}.abp.io"); + + permissionConfiguration = await _remoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Permission"); + permissionConfiguration.BaseUrl.ShouldBe($"https://{_currentTenant.Id}.abp.io"); + + settingConfiguration = await _remoteServiceConfigurationProvider.GetConfigurationOrDefaultAsync("Setting"); + settingConfiguration.BaseUrl.ShouldBe($"https://{_currentTenant.Name}.abp.io"); + } + } +} \ No newline at end of file