docs.microsoft.com建议使用Microsoft.AspNetCore.Mvc.Testing进行集成测试,这似乎是一个不错的选择,但似乎他们错过了增加使用NegotiateDefaults.AuthenticationScheme进行测试的能力。
添加到Startup.cs / ConfigureServices
services.AddAuthentication (NegotiateDefaults.AuthenticationScheme).AddNegotiate ();
导致测试失败
消息: System.NotSupportedException:协商身份验证需要一台支持IConnectionItemsFeature的服务器,例如Kestrel。
任何人都知道如何将Microsoft.AspNetCore.Mvc.Testing与使用NegotiateDefaults.AuthenticationScheme的端点一起使用吗?是否像异常声明那样不被支持?
答案 0 :(得分:0)
我删除了Microsoft.AspNetCore.Mvc.Testing并改用了自定义NUnit基类:
public class AspNetCoreIntegrationTestBase {
public CancellationTokenSource CancellationTokenSource {
get;
private set;
}
public Task TestWebserver {
get;
private set;
}
[OneTimeSetUp]
public void Setup() {
CancellationTokenSource = new CancellationTokenSource();
TestWebserver = Program.CreateHostBuilder(new string[0]).Build().StartAsync(CancellationTokenSource.Token);
}
[OneTimeTearDown]
public void CleanUp() {
CancellationTokenSource.Cancel();
TestWebserver.Dispose();
}
}
要使用的httpclient必须用
初始化UseDefaultCredentials = true