To Unit Testing HTTP triggered Azure Functions with test data is well and often described. For example here: How to write unit test for azure function v1
Mock data are given in the http request.
But I have a timer triggerd Azure function which reads data from a FTP server. I would like to Unit Test the function with test data.
My function:
[FunctionName("MyTimerTriggeredFunction")]
public static void Run([TimerTrigger("0 */2 * * * *")]TimerInfo myTimer, ILogger log, ExecutionContext context)
{
log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
ServiceClass serviceClass = new ServiceClass(log, context);
List<Order> orderList = serviceClass.getOrdersFromFtp();
...
a running Unit Test function to test the logger, just to show how I started:
public void TestLogger()
{
// https://learn.microsoft.com/de-de/azure/azure-functions/functions-test-a-function
var logger = (ListLogger)TestFactory.CreateLogger(LoggerTypes.List);
MyTimerTriggeredFunction.Run(null, logger, null);
var msg = logger.Logs[0];
bool testString = msg.Contains("C# Timer trigger function executed at");
Assert.IsTrue(testString);
}
serviceClass.getOrdersFromFtp() return a list of objects. I could create this list with mock data in the unit test but how to give it to the timer triggered azure function?