Apologies - this is a likely duplicate. But I was unable to find a useful answer elsewhere on the site.
Currently working on adding email-sending functions to an application. It's not been done under TDD but we've built the tests as we go along and have good coverage.
My task involves adding an email dispatch to an existing function.
public ActionResult RequestApproval(int? id)
{
Job job = rep.GetJob(id);
//widgets
job.IsApproved = true;
SaveJob(job);
}
This is done through a static helper class:
public static class EmailHelper
{
public static void SendEmail(string subject, string body, params string[] to)
{
//gubbins
}
}
So I'm adding
EmailHelper.SendEmail("Approval", "Please approve a thing", job.UsersWhoCanApprove.Select(a => a.Email).ToArray());
To the RequestApproval function.
I know I can effectively test email delivery functions by fiddling with the config, but I don't want to do that here. In the first instance, it's slow and in the second that test belongs in the test suite for the static class.
You're not allowed to put interfaces on a static class. So how can I refactor this to that I can mock out or bypass the call to the static class?