Good day,
I am confused about unit testing the following:
1. MVC Controller:
[HttpGet]
public async Task<PartialViewResult> DoExternalCallsAsync()
{
var model = new MyModel();
await MyStaticLibrary.DoExternalWorkAsync(Server.MapPath("~\\") + "WorkSource.txt", model);
return PartialView("_MyResults", model);
}
2. Static library:
public static async Task DoExternalWorkAsync(string sourcePath, MyModel model)
{
var externalCalls =
System.IO.File.ReadAllLines(sourcePath)
.Where(line => (!string.IsNullOrEmpty(line) && line.First() != '#'))
.Select(p => DoExternalCall(p, model));
await Task.WhenAll(externalCalls);
}
private static async Task DoExternalCall(string urlPath, MyModel model)
{
var result = await GetExternalApiResultAysnc(urlPath);
// some code here...
return;
}
Basically, all that the controller does is call an external API, which does some work and returns a result or throws an error.
There are no interfaces or abstract classes with the external Api.
How do I go about unit testing this? N. B. I am not at liberty to change the design of the external Api.
Thanks,