我正在将 IdentityServer4 升级到 3.1 版,升级后我遇到了单元测试问题。IdentityServer4.EntityFramework.Stores.ClientStore
如下所示:
public class IfloClientStore : ClientStore
{
private const string Saml2BearerClientSuffix = "_saml2bearer";
public IfloClientStore(IConfigurationDbContext context, ILogger<ClientStore> logger) : base(context, logger)
{
}
public override async Task<Client> FindClientByIdAsync(string clientId)
{
if(string.IsNullOrWhiteSpace(clientId))
throw new ArgumentException(nameof(clientId) +" is null or empty");
clientId = clientId.ToLowerInvariant();
var result = await base.FindClientByIdAsync(MapClientId(clientId));
if (result == null)
throw new ResourceNotFoundException(clientId);
if (IsSamlClient(clientId))
AllowSamlFlow(result);
return result;
}
private void AllowSamlFlow(Client client)
{
client.AllowedGrantTypes.Add(Constants.GrantTypes.Saml2BearerGrant);
}
private bool IsSamlClient(string clientId)
{
return clientId.EndsWith(Saml2BearerClientSuffix);
}
private string MapClientId(string clientId)
{
if (IsSamlClient(clientId))
return clientId.Substring(0, clientId.Length - Saml2BearerClientSuffix.Length);
return clientId;
}
}
我的单元测试:
[Test]
public async Task FindClientByIdAsync_Given_PFP_Saml2Bearer_Client_Return_PFP_SamlAllowed_Client()
{
var client = await underTest.FindClientByIdAsync(PfpWebClientIdForSaml);
client.ClientId.Should().Be(PfpWebClientId);
client.AllowedGrantTypes.Single().Should().Be("urn:ietf:params:oauth:grant-type:saml2-bearer");
}
执行时抛出此异常FindClientByIdAsync
:
Message:
System.InvalidOperationException : The provider for the source IQueryable doesn't implement IAsyncQueryProvider. Only providers that implement IAsyncQueryProvider can be used for Entity Framework asynchronous operations.
堆栈跟踪: EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable 1 source, Expression expression, CancellationToken cancellationToken)
EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable
1 源,CancellationToken cancelToken) EntityFrameworkQueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable 1 source, CancellationToken cancellationToken)
ClientStore.FindClientByIdAsync(String clientId)
IfloClientStore.FindClientByIdAsync(String clientId) line 27
TestIfloClientStore.FindClientByIdAsync_Given_PFP_Saml2Bearer_Client_Return_PFP_SamlAllowed_Client() line 43
GenericAdapter
1.GetResult() AsyncToSyncAdapter.Await(Func`1 调用) TestMethodCommand.RunTestMethod(TestExecutionContext 上下文) TestMethodCommand.Execute(TestExecutionContext context) <>c__DisplayClass1_0.b__0() BeforeAndAfterTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
如果我降级IdentityServer4.EntityFramework
到 3.0 版,它工作得很好。但我想确定 IDS4 是否有错误,或者我是否因为升级而必须更改某些内容。有人可以帮助我吗?