I have some appsetting related to SendGrid Service like username, password and some resetpasswordemail settings. Now i wanted to use them in my unit test. My ResetPasswordSetting class looks like this.
public class ResetPasswordEmailSetting : IResetPasswordEmailSetting
{
public string ResetPasswordEmailUrl { get; set; }
public List<string> AddToEmails { get; set; }
public string FromEmail
{
get { return ConfigurationManager.AppSettings.Get("ResetPassword_FromEmail"); }
}
public string Subject
{
get { return ConfigurationManager.AppSettings.Get("ResetPassword_Subject"); }
}
public string SenderDisplayName
{
get { return ConfigurationManager.AppSettings.Get("ResetPassword_SenderDisplayName"); }
}
}
When i run my unit test using this class then the fields that get their value from Webconfig appsetting part are coming null.
My Unit Test looks like this.
[TestMethod]
[TestCategory("SendGrid-Service")]
public async Task email_recieved_when_correct_email_provided()
{
var sendgrid = new SendGridService();
var resetpasswordsetting = new ResetPasswordEmailSetting
{
AddToEmails = new List<string> { "[email protected]" },
ResetPasswordEmailUrl = "www.google.com",
};
// when i debug then resetpasswordsetting fields are coming null other then above.
var result = await sendgrid.SendResetPasswordEmail(resetpasswordsetting, new
SendGridSettings());
result.Should().BeTrue();
}
so any idea how to get these settings in unit test.