public async Task StartAsync_SchedulePastDue_InvokesJobFunctionImmediately()
        {
            DateTime lastOccurrence = default(DateTime);

            _mockScheduleMonitor.Setup(p => p.IsPastDueAsync(_testTimerName, It.IsAny <DateTime>(), It.IsAny <TimerSchedule>()))
            .Callback <string, DateTime, TimerSchedule>((mockTimerName, mockNow, mockNext) =>
            {
                lastOccurrence = mockNow;
            })
            .Returns(Task.FromResult(true));

            _mockScheduleMonitor.Setup(p => p.UpdateAsync(_testTimerName, It.IsAny <DateTime>(), It.IsAny <DateTime>()))
            .Callback <string, DateTime, DateTime>((mockTimerName, mockLastOccurrence, mockNextOccurrence) =>
            {
                Assert.Equal(lastOccurrence, mockLastOccurrence);
                DateTime expectedNextOccurrence = _attribute.Schedule.GetNextOccurrence(lastOccurrence);
                Assert.Equal(expectedNextOccurrence, mockNextOccurrence);
            })
            .Returns(Task.FromResult(true));

            CancellationToken cancellationToken = new CancellationToken();
            await _listener.StartAsync(cancellationToken);

            TimerInfo timerInfo = (TimerInfo)_triggeredFunctionData.TriggerValue;

            Assert.True(timerInfo.IsPastDue);

            _listener.Dispose();
        }
        public async Task StartAsync_SchedulePastDue_InvokesJobFunctionImmediately()
        {
            // Set this to true to ensure that the function is only executed once
            // In this case, because it is run on startup due to being behind schedule,
            // it shouldn't be run twice.
            _attribute.RunOnStartup = true;

            ScheduleStatus status = new ScheduleStatus();

            _mockScheduleMonitor.Setup(p => p.GetStatusAsync(_testTimerName)).ReturnsAsync(status);

            DateTime lastOccurrence = default(DateTime);
            TimeSpan pastDueAmount  = TimeSpan.FromMinutes(3);

            _mockScheduleMonitor.Setup(p => p.CheckPastDueAsync(_testTimerName, It.IsAny <DateTime>(), It.IsAny <TimerSchedule>(), status))
            .Callback <string, DateTime, TimerSchedule, ScheduleStatus>((mockTimerName, mockNow, mockNext, mockStatus) =>
            {
                lastOccurrence = mockNow;
            })
            .ReturnsAsync(pastDueAmount);

            _mockScheduleMonitor.Setup(p => p.UpdateStatusAsync(_testTimerName, It.IsAny <ScheduleStatus>()))
            .Callback <string, ScheduleStatus>((mockTimerName, mockStatus) =>
            {
                Assert.Equal(lastOccurrence, mockStatus.Last);
                DateTime expectedNextOccurrence = _schedule.GetNextOccurrence(lastOccurrence);
                Assert.Equal(expectedNextOccurrence, mockStatus.Next);
            })
            .Returns(Task.FromResult(true));

            CancellationToken cancellationToken = new CancellationToken();
            await _listener.StartAsync(cancellationToken);

            TimerInfo timerInfo = (TimerInfo)_triggeredFunctionData.TriggerValue;

            Assert.Same(status, timerInfo.ScheduleStatus);
            Assert.True(timerInfo.IsPastDue);

            _mockTriggerExecutor.Verify(p => p.TryExecuteAsync(It.IsAny <TriggeredFunctionData>(), It.IsAny <CancellationToken>()), Times.Once());

            _listener.Dispose();
        }