小编Gir*_*uly的帖子

如何在 dotnet core V2.2 中对 services.AddHttpClient() 注册进行单元测试

我正在研究 Web API dotnet core V2.2 项目。我在 Startup.cs 文件中注册了以下指定的客户端。我想使用 NSubstitute 进行单元测试,以便为以下方法进行可能的代码覆盖。有人可以帮我解决这个问题吗?提前致谢。

public void ConfigureServices(IServiceCollection services) {
    services.AddHttpClient("myapi", (serviceProvider, client) = >{
    var config = serviceProvider.GetService < IConfiguration > ();
    client.BaseAddress = new URI(config["mybaseURL"]);
});
Run Code Online (Sandbox Code Playgroud)

}

c# unit-testing .net-core asp.net-core

7
推荐指数
1
解决办法
1110
查看次数

标签 统计

.net-core ×1

asp.net-core ×1

c# ×1

unit-testing ×1