You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abp/test/Volo.Abp.MultiTenancy.Tests/Volo/Abp/MultiTenancy/CurrentTenant_Tests.cs

68 lines
1.7 KiB

using System;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.MultiTenancy.ConfigurationStore;
using Xunit;
namespace Volo.Abp.MultiTenancy
{
public class CurrentTenant_Tests : MultiTenancyTestBase
{
private readonly ICurrentTenant _currentTenant;
private readonly Guid _tenantAId = Guid.NewGuid();
private readonly Guid _tenantBId = Guid.NewGuid();
public CurrentTenant_Tests()
{
_currentTenant = ServiceProvider.GetRequiredService<ICurrentTenant>();
}
[Fact]
public void CurrentTenant_Should_Be_Null_As_Default()
{
//Assert
_currentTenant.Id.ShouldBeNull();
}
protected override void BeforeAddApplication(IServiceCollection services)
{
services.Configure<ConfigurationTenantStoreOptions>(options =>
{
options.Tenants = new[]
{
new TenantInfo(_tenantAId, "A"),
new TenantInfo(_tenantAId, "B")
};
});
}
[Fact]
public void Should_Get_Null_If_Not_Set()
{
_currentTenant.Id.ShouldBeNull();
}
[Fact]
public void Should_Get_Changed_Tenant_If()
{
_currentTenant.Id.ShouldBe(null);
using (_currentTenant.Change(_tenantAId))
{
_currentTenant.Id.ShouldBe(_tenantAId);
using (_currentTenant.Change(_tenantBId))
{
_currentTenant.Id.ShouldBe(_tenantBId);
}
_currentTenant.Id.ShouldBe(_tenantAId);
}
_currentTenant.Id.ShouldBeNull();
}
}
}