public async Task BindAsync_ReturnsExpectedTriggerData()
        {
            ParameterInfo parameter = GetType().GetMethod("TestTimerJob").GetParameters()[0];
            MethodInfo methodInfo = (MethodInfo)parameter.Member;
            string timerName = string.Format("{0}.{1}", methodInfo.DeclaringType.FullName, methodInfo.Name);

            Mock<ScheduleMonitor> mockScheduleMonitor = new Mock<ScheduleMonitor>(MockBehavior.Strict);
            ScheduleStatus status = new ScheduleStatus();
            mockScheduleMonitor.Setup(p => p.GetStatusAsync(timerName)).ReturnsAsync(status);

            TimerTriggerAttribute attribute = parameter.GetCustomAttribute<TimerTriggerAttribute>();
            TimersConfiguration config = new TimersConfiguration();
            config.ScheduleMonitor = mockScheduleMonitor.Object;
            TestTraceWriter trace = new TestTraceWriter();
            TimerTriggerBinding binding = new TimerTriggerBinding(parameter, attribute, config, trace);

            // when we bind to a non-TimerInfo (e.g. in a Dashboard invocation) a new
            // TimerInfo is created, with the ScheduleStatus populated
            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, trace);
            ValueBindingContext context = new ValueBindingContext(functionContext, CancellationToken.None);
            TriggerData triggerData = (TriggerData)(await binding.BindAsync("", context));
            TimerInfo timerInfo = (TimerInfo)triggerData.ValueProvider.GetValue();
            Assert.Same(status, timerInfo.ScheduleStatus);

            // when we pass in a TimerInfo that is used
            TimerInfo expected = new TimerInfo(attribute.Schedule, status);
            triggerData = (TriggerData)(await binding.BindAsync(expected, context));
            timerInfo = (TimerInfo)triggerData.ValueProvider.GetValue();
            Assert.Same(expected, timerInfo);
        }
        public void FormatNextOccurrences_ReturnsExpectedString()
        {
            DateTime now = new DateTime(2015, 9, 16, 10, 30, 00);
            TimerInfo timerInfo = new TimerInfo(new CronSchedule("0 0 * * * *"));
            string result = timerInfo.FormatNextOccurrences(10, now);

            string expected =
                "The next 10 occurrences of the schedule will be:\r\n" +
                "9/16/2015 11:00:00 AM\r\n" +
                "9/16/2015 12:00:00 PM\r\n" +
                "9/16/2015 1:00:00 PM\r\n" +
                "9/16/2015 2:00:00 PM\r\n" +
                "9/16/2015 3:00:00 PM\r\n" +
                "9/16/2015 4:00:00 PM\r\n" +
                "9/16/2015 5:00:00 PM\r\n" +
                "9/16/2015 6:00:00 PM\r\n" +
                "9/16/2015 7:00:00 PM\r\n" +
                "9/16/2015 8:00:00 PM\r\n";
            Assert.Equal(expected, result);

            timerInfo = new TimerInfo(new DailySchedule("2:00:00"));
            result = timerInfo.FormatNextOccurrences(5, now);

            expected =
                "The next 5 occurrences of the schedule will be:\r\n" +
                "9/17/2015 2:00:00 AM\r\n" +
                "9/18/2015 2:00:00 AM\r\n" +
                "9/19/2015 2:00:00 AM\r\n" +
                "9/20/2015 2:00:00 AM\r\n" +
                "9/21/2015 2:00:00 AM\r\n";
            Assert.Equal(expected, result);

            WeeklySchedule weeklySchedule = new WeeklySchedule();
            weeklySchedule.Add(DayOfWeek.Monday, new TimeSpan(8, 0, 0));
            weeklySchedule.Add(DayOfWeek.Wednesday, new TimeSpan(9, 30, 0));
            weeklySchedule.Add(DayOfWeek.Wednesday, new TimeSpan(21, 30, 0));
            weeklySchedule.Add(DayOfWeek.Friday, new TimeSpan(10, 0, 0));

            timerInfo = new TimerInfo(weeklySchedule);

            result = timerInfo.FormatNextOccurrences(5, now);

            expected =
                "The next 5 occurrences of the schedule will be:\r\n" +
                "9/16/2015 9:30:00 PM\r\n" +
                "9/18/2015 10:00:00 AM\r\n" +
                "9/21/2015 8:00:00 AM\r\n" +
                "9/23/2015 9:30:00 AM\r\n" +
                "9/23/2015 9:30:00 PM\r\n";
            Assert.Equal(expected, result);
        }
 public static void TimerTrigger(TimerInfo timerInfo, TraceWriter traceWriter)
 {
     traceWriter.Info(string.Format("C# TimerTrigger function invoked at ", DateTime.Now));
 }
 public static void TimerTrigger(TimerInfo timerInfo)
 {
     File.AppendAllText("joblog.txt", DateTime.Now.ToString() + "\r\n");
     InvokeCount++;
 }