mirror of https://github.com/abpframework/abp.git
3 changed files with 73 additions and 21 deletions
@ -0,0 +1,68 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Hosting; |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Microsoft.Extensions.Options; |
|||
using Shouldly; |
|||
using Volo.Abp.MultiTenancy; |
|||
using Volo.Abp.MultiTenancy.ConfigurationStore; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.AspNetCore.MultiTenancy |
|||
{ |
|||
public class AspNetCoreMultiTenancy_WithDomainResolver_Tests : AspNetCoreMultiTenancyTestBase |
|||
{ |
|||
private readonly Guid _testTenantId = Guid.NewGuid(); |
|||
private readonly string _testTenantName = "acme"; |
|||
|
|||
private readonly AspNetCoreMultiTenancyOptions _options; |
|||
|
|||
public AspNetCoreMultiTenancy_WithDomainResolver_Tests() |
|||
{ |
|||
_options = ServiceProvider.GetRequiredService<IOptions<AspNetCoreMultiTenancyOptions>>().Value; |
|||
} |
|||
|
|||
protected override IWebHostBuilder CreateWebHostBuilder() |
|||
{ |
|||
return base.CreateWebHostBuilder().ConfigureServices(services => |
|||
{ |
|||
services.Configure<DefaultTenantStoreOptions>(options => |
|||
{ |
|||
options.Tenants = new[] |
|||
{ |
|||
new TenantConfiguration(_testTenantId, _testTenantName) |
|||
}; |
|||
}); |
|||
|
|||
services.Configure<TenantResolveOptions>(options => |
|||
{ |
|||
options.AddDomainTenantResolver("{0}.abp.io"); |
|||
}); |
|||
}); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Use_Host_If_Tenant_Is_Not_Specified() |
|||
{ |
|||
var result = await GetResponseAsObjectAsync<Dictionary<string, string>>("http://abp.io"); |
|||
result["TenantId"].ShouldBe(""); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Use_Domain_If_Specified() |
|||
{ |
|||
var result = await GetResponseAsObjectAsync<Dictionary<string, string>>("http://acme.abp.io"); |
|||
result["TenantId"].ShouldBe(_testTenantId.ToString()); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_Use_Domain_As_First_Priority_If_Specified() |
|||
{ |
|||
Client.DefaultRequestHeaders.Add(_options.TenantKey, Guid.NewGuid().ToString()); |
|||
|
|||
var result = await GetResponseAsObjectAsync<Dictionary<string, string>>("http://acme.abp.io"); |
|||
result["TenantId"].ShouldBe(_testTenantId.ToString()); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue