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);
        }
        /// <summary>
        /// Enables use of the Timer extensions
        /// </summary>
        /// <param name="config">The <see cref="JobHostConfiguration"/> to configure.</param>
        /// <param name="timersConfig">The <see cref="TimersConfiguration"/> to use.</param>
        public static void UseTimers(this JobHostConfiguration config, TimersConfiguration timersConfig)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            config.RegisterExtensionConfigProvider(new TimersExtensionConfig(timersConfig));
        }
 private void CreateTestListener(string expression, bool useMonitor = true)
 {
     _attribute = new TimerTriggerAttribute(expression);
     _attribute.UseMonitor = useMonitor;
     _config = new TimersConfiguration();
     _mockScheduleMonitor = new Mock<ScheduleMonitor>(MockBehavior.Strict);
     _config.ScheduleMonitor = _mockScheduleMonitor.Object;
     _mockTriggerExecutor = new Mock<ITriggeredFunctionExecutor>(MockBehavior.Strict);
     FunctionResult result = new FunctionResult(true);
     _mockTriggerExecutor.Setup(p => p.TryExecuteAsync(It.IsAny<TriggeredFunctionData>(), It.IsAny<CancellationToken>()))
         .Callback<TriggeredFunctionData, CancellationToken>((mockFunctionData, mockToken) =>
         {
             _triggeredFunctionData = mockFunctionData;
         })
         .Returns(Task.FromResult(result));
     _listener = new TimerListener(_attribute, _testTimerName, _config, _mockTriggerExecutor.Object, new TestTraceWriter());
 }
 public TimersExtensionConfig(TimersConfiguration config)
 {
     _config = config;
 }