【发布时间】:2017-09-14 08:29:26
【问题描述】:
我尝试按照本指南在 .NET core 2 中运行测试时允许用户登录
http://geeklearning.io/how-to-deal-with-identity-when-testing-an-asp-net-core-application/
它说我应该为这样的测试目的配置身份验证中间件:
public class TestAuthenticationOptions : AuthenticationOptions
{
public virtual ClaimsIdentity Identity { get; } = new ClaimsIdentity(new Claim[]
{
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", Guid.NewGuid().ToString()),
new Claim("http://schemas.microsoft.com/identity/claims/tenantid", "test"),
new Claim("http://schemas.microsoft.com/identity/claims/objectidentifier", Guid.NewGuid().ToString()),
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname", "test"),
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname", "test"),
new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn", "test"),
}, "test");
public TestAuthenticationOptions()
{
this.AuthenticationScheme = "TestAuthenticationMiddleware";
this.AutomaticAuthenticate = true;
}
}
这不起作用,因为 AuthenticationOptions 类已从 .NET Core 2 中的 AuthenticationOptions 实例中删除了 AuthenticationScheme 和 AutomaticAuthenticate 属性,参见。
https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x#setting-default-authentication-schemes
所以现在我不知道如何登录测试以在 .NET Core 2 中工作。
【问题讨论】:
标签: c# asp.net testing .net-core