mirror of https://github.com/abpframework/abp
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.
52 lines
1.9 KiB
52 lines
1.9 KiB
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using Microsoft.Extensions.Options;
|
|
using NSubstitute;
|
|
using Shouldly;
|
|
using Volo.Abp.Identity.Settings;
|
|
using Volo.Abp.Settings;
|
|
using Xunit;
|
|
|
|
namespace Volo.Abp.Identity
|
|
{
|
|
public class IdentityOptions_Tests : AbpIdentityDomainTestBase
|
|
{
|
|
private ISettingProvider _settingProvider;
|
|
|
|
protected override void AfterAddApplication(IServiceCollection services)
|
|
{
|
|
_settingProvider = Substitute.For<ISettingProvider>();
|
|
_settingProvider.GetOrNullAsync(Arg.Any<string>()).Returns((string) null);
|
|
services.Replace(ServiceDescriptor.Singleton(_settingProvider));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_Resolve_AbpIdentityOptionsFactory()
|
|
{
|
|
GetRequiredService<IOptionsFactory<IdentityOptions>>().ShouldBeOfType(typeof(AbpIdentityOptionsFactory));
|
|
}
|
|
|
|
[Fact]
|
|
public void Should_Get_Options_From_Custom_Settings_If_Available()
|
|
{
|
|
using (var scope1 = ServiceProvider.CreateScope())
|
|
{
|
|
var options = scope1.ServiceProvider.GetRequiredService<IOptions<IdentityOptions>>().Value;
|
|
options.Password.RequiredLength.ShouldBe(6); //Default value
|
|
options.Password.RequiredUniqueChars.ShouldBe(1); //Default value
|
|
}
|
|
|
|
_settingProvider.GetOrNullAsync(IdentitySettingNames.Password.RequiredLength).Returns(Task.FromResult("42"));
|
|
|
|
using (var scope2 = ServiceProvider.CreateScope())
|
|
{
|
|
var options = scope2.ServiceProvider.GetRequiredService<IOptions<IdentityOptions>>().Value;
|
|
options.Password.RequiredLength.ShouldBe(42); //Setting value
|
|
options.Password.RequiredUniqueChars.ShouldBe(1); //Default value
|
|
}
|
|
}
|
|
}
|
|
}
|