I am trying to write a unit test for the following:
[TestMethod]
public void GetInviteEndPoint_ShouldAccessAppSettings()
{
//Data pulled from the appsettings.test.json
var config = InitConfiguration();
var inviteEndPointConfig = config["InviteEndPoint"]; // <-- Pain Point
//Arrange Test && Mock if needed
string mockInviteEndPoint = "https://graph.microsoft.com/v1.0/invitations";
//Actual Code from Application (ACT)
SendInvite sendInvite = new SendInvite();
string inviteEndPoint = sendInvite.GetInviteEndPoint(config);
//Assert
// Assert always tests (Expected[Arranged], Actual[From Code Base])
Assert.AreEqual(mockInviteEndPoint, inviteEndPoint);
}
My both my appsettings.json and appsettings.test.json look identical. I am having a hard time getting the value from the .json file. I was wondering if anybody could provide any insight on this code that I am stuck on.
{
"SendeInvite": {
"InviteEndPoint": "https://graph.microsoft.com/v1.0/invitations"
...Code Omitted...
}
}
Am I calling the config["InvitedEndPoint"]
incorrectly?
Please note I have the following code at the top of the Test Class
public static IConfiguration InitConfiguration()
{
var config = new ConfigurationBuilder()
.AddJsonFile("appsettings.test.json")
.Build();
return config;
}