gpt4 book ai didi

c# - 协商身份验证和 Microsoft.AspNetCore.Mvc.Testing

转载 作者:行者123 更新时间:2023-12-04 13:57:04 30 4
gpt4 key购买 nike

docs.microsoft.com推荐使用 Microsoft.AspNetCore.Mvc.Testing对于集成测试,它似乎是一个不错的选择,但似乎他们错过了添加测试功能 NegotiateDefaults.AuthenticationScheme .

添加到 Startup.cs/ConfigureServices

 services.AddAuthentication (NegotiateDefaults.AuthenticationScheme).AddNegotiate ();

导致测试失败

Message: System.NotSupportedException : Negotiate authentication requires a server that supports IConnectionItemsFeature like Kestrel.



有谁知道怎么用 Microsoft.AspNetCore.Mvc.Testing使用 NegotiateDefaults.AuthenticationScheme 的端点?是不是不支持,就像异常声明一样?

最佳答案

我放弃了 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

关于c# - 协商身份验证和 Microsoft.AspNetCore.Mvc.Testing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60111553/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com