我正在尝试为以下内容编写一个单元测试:
[TestMethod]
public void GetInviteEndPoint_ShouldAccessAppSettings()
{
var config = InitConfiguration();
var inviteEndPointConfig = config["InviteEndPoint"];
string mockInviteEndPoint = "https://graph.microsoft.com/v1.0/invitations";
SendInvite sendInvite = new SendInvite();
string inviteEndPoint = sendInvite.GetInviteEndPoint(config);
Assert.AreEqual(mockInviteEndPoint, inviteEndPoint);
}
我的appsettings.json和appsettings.test.json看起来完全相同。我很难从.json文件中获取值。我想知道是否有人能提供关于我一直坚持的代码的任何见解。
{
"SendeInvite": {
"InviteEndPoint": "https://graph.microsoft.com/v1.0/invitations"
...Code Omitted...
}
}
我要打电话给警察吗
config["InvitedEndPoint"]
不正确?
请注意,我在测试类的顶部有以下代码
public static IConfiguration InitConfiguration()
{
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.test.json")
.Build();
return config;
}