I have a few C# Azure Functions that run on a schedule using timer triggers. I\'ve set them up like so, where %TimerSchedule% refers to a cron expression in the
I had the same question. I fixed it with a Unittest. Indeed you need to stub out the TraceWriter and the TimerInfo.
Here some code how I did this.
TimerInfo:
public class ScheduleStub : TimerInfo
{
public ScheduleStub(TimerSchedule schedule, ScheduleStatus status, bool isPastDue = false) : base(schedule, status, isPastDue)
{
}
}
And the TraceWriter:
public class TraceWriterStub : TraceWriter
{
protected TraceLevel _level;
protected List _traces;
public TraceWriterStub(TraceLevel level) : base(level)
{
_level = level;
_traces = new List();
}
public override void Trace(TraceEvent traceEvent)
{
_traces.Add(traceEvent);
}
public List Traces => _traces;
}