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 BindingContext(ValueBindingContext valueContext, IReadOnlyDictionary <string, object> bindingData)
        {
            _functionContext   = valueContext.FunctionContext;
            _bindingData       = bindingData;
            _cancellationToken = valueContext.CancellationToken;

            _valueContext = valueContext;
        }
        public BindingContext(AmbientBindingContext ambientContext, CancellationToken cancellationToken)
        {
            _functionContext   = ambientContext.FunctionContext;
            _bindingData       = ambientContext.BindingData;
            _cancellationToken = cancellationToken;

            _ambientContext = ambientContext;
        }
示例#4
0
        internal BindingContext(AmbientBindingContext ambientContext, CancellationToken cancellationToken)
        {
            if (ambientContext == null)
            {
                throw new ArgumentNullException("ambientContext");
            }

            _ambientContext    = ambientContext;
            _functionContext   = ambientContext.FunctionContext;
            _bindingData       = ambientContext.BindingData;
            _cancellationToken = cancellationToken;
        }
示例#5
0
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="valueContext">The value binding context.</param>
        /// <param name="bindingData">The binding data.</param>
        public BindingContext(ValueBindingContext valueContext, IReadOnlyDictionary <string, object> bindingData)
        {
            if (valueContext == null)
            {
                throw new ArgumentNullException("valueContext");
            }

            _valueContext      = valueContext;
            _bindingData       = bindingData;
            _functionContext   = valueContext.FunctionContext;
            _cancellationToken = valueContext.CancellationToken;
        }
        internal BindingContext(AmbientBindingContext ambientContext, CancellationToken cancellationToken)
        {
            if (ambientContext == null)
            {
                throw new ArgumentNullException("ambientContext");
            }

            _ambientContext = ambientContext;
            _functionContext = ambientContext.FunctionContext;
            _bindingData = ambientContext.BindingData;
            _cancellationToken = cancellationToken;
        }
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="valueContext">The value binding context.</param>
        /// <param name="bindingData">The binding data.</param>
        public BindingContext(ValueBindingContext valueContext, IReadOnlyDictionary<string, object> bindingData)
        {
            if (valueContext == null)
            {
                throw new ArgumentNullException("valueContext");
            }

            _valueContext = valueContext;
            _bindingData = bindingData;
            _functionContext = valueContext.FunctionContext;
            _cancellationToken = valueContext.CancellationToken;
        }
        public async Task TryCreate_ReturnsTableArgumentBindingExtensionWrapper()
        {
            DefaultExtensionRegistry extensions = new DefaultExtensionRegistry();
            FooBarTableArgumentBindingExtensionProvider fooBarExtensionProvider = new FooBarTableArgumentBindingExtensionProvider();
            extensions.RegisterExtension<ITableArgumentBindingExtensionProvider>(fooBarExtensionProvider);

            TableArgumentBindingExtensionProvider provider = new TableArgumentBindingExtensionProvider(extensions);

            ITableArgumentBinding binding = provider.TryCreate(_parameters[0]);
            Assert.Equal(typeof(TableArgumentBindingExtensionProvider.TableArgumentBindingExtension), binding.GetType());

            Assert.Null(BoundTable);
            CloudTable table = new CloudTable(new Uri("http://localhost:10000/test/table"));
            IStorageTable storageTable = new StorageTable(table);
            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, new StringWriter());
            ValueBindingContext context = new ValueBindingContext(functionContext, CancellationToken.None);
            IValueProvider valueProvider = await binding.BindAsync(storageTable, context);
            Assert.NotNull(valueProvider);
            Assert.Same(table, BoundTable);
        }
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="functionContext">The context for the parent function.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
 public ValueBindingContext(FunctionBindingContext functionContext, CancellationToken cancellationToken)
 {
     _functionContext   = functionContext;
     _cancellationToken = cancellationToken;
 }
        public async Task BindAsync_Poco_FromRequestBody()
        {
            ParameterInfo parameterInfo = GetType().GetMethod("TestPocoFunction").GetParameters()[0];
            HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(), parameterInfo, true);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://functions/myfunc?code=abc123");

            JObject requestBody = new JObject
            {
                { "Name", "Mathew Charles" },
                { "Location", "Seattle" }
            };
            request.Content = new StringContent(requestBody.ToString());
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, new TestTraceWriter(TraceLevel.Verbose));
            ValueBindingContext context = new ValueBindingContext(functionContext, CancellationToken.None);
            ITriggerData triggerData = await binding.BindAsync(request, context);

            Assert.Equal(2, triggerData.BindingData.Count);
            Assert.Equal("Mathew Charles", triggerData.BindingData["Name"]);
            Assert.Equal("Seattle", triggerData.BindingData["Location"]);

            TestPoco testPoco = (TestPoco)triggerData.ValueProvider.GetValue();
            Assert.Equal("Mathew Charles", testPoco.Name);
            Assert.Equal("Seattle", testPoco.Location);
        }
        public async Task BindAsync_Poco_MergedBindingData()
        {
            ParameterInfo parameterInfo = GetType().GetMethod("TestPocoFunctionEx").GetParameters()[0];
            HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(), parameterInfo, true);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://functions/myfunc?code=abc123&Age=25");

            JObject requestBody = new JObject
            {
                { "Name", "Mathew Charles" },
                { "Phone", "(425) 555-6666" }
            };
            request.Content = new StringContent(requestBody.ToString());
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            Dictionary<string, object> routeData = new Dictionary<string, object>
            {
                { "Location", "Seattle" }
            };
            request.Properties.Add(ScriptConstants.AzureFunctionsHttpRouteDataKey, routeData);

            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, new TestTraceWriter(TraceLevel.Verbose));
            ValueBindingContext context = new ValueBindingContext(functionContext, CancellationToken.None);
            ITriggerData triggerData = await binding.BindAsync(request, context);

            Assert.Equal(6, triggerData.BindingData.Count);
            Assert.Equal("Mathew Charles", triggerData.BindingData["Name"]);
            Assert.Equal("Seattle", triggerData.BindingData["Location"]);
            Assert.Equal("(425) 555-6666", triggerData.BindingData["Phone"]);
            Assert.Equal("25", triggerData.BindingData["Age"]);

            TestPocoEx testPoco = (TestPocoEx)triggerData.ValueProvider.GetValue();
            Assert.Equal("Mathew Charles", testPoco.Name);
            Assert.Equal("Seattle", testPoco.Location);
            Assert.Equal("(425) 555-6666", testPoco.Phone);
            Assert.Equal(25, testPoco.Age);
        }
        public async Task BindAsync_HttpRequestMessage_FromRequestBody()
        {
            ParameterInfo parameterInfo = GetType().GetMethod("TestHttpRequestMessageFunction").GetParameters()[0];
            HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(), parameterInfo, false);

            // we intentionally do not send a content type on the request
            // to ensure that we can still extract binding data in such cases
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://functions/myfunc?code=abc123");
            JObject requestBody = new JObject
            {
                { "Name", "Mathew Charles" },
                { "Location", "Seattle" }
            };
            request.Content = new StringContent(requestBody.ToString());

            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, new TestTraceWriter(TraceLevel.Verbose));
            ValueBindingContext context = new ValueBindingContext(functionContext, CancellationToken.None);
            ITriggerData triggerData = await binding.BindAsync(request, context);

            Assert.Equal(2, triggerData.BindingData.Count);
            Assert.Equal("Mathew Charles", triggerData.BindingData["Name"]);
            Assert.Equal("Seattle", triggerData.BindingData["Location"]);

            HttpRequestMessage result = (HttpRequestMessage)triggerData.ValueProvider.GetValue();
            Assert.Same(request, result);
        }
        public async Task BindAsync_Poco_FromRouteParameters()
        {
            ParameterInfo parameterInfo = GetType().GetMethod("TestPocoFunction").GetParameters()[0];
            HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(), parameterInfo, true);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://functions/myfunc");

            Dictionary<string, object> routeData = new Dictionary<string, object>
            {
                { "Name", "Mathew Charles" },
                { "Location", "Seattle" }
            };
            request.Properties.Add(ScriptConstants.AzureFunctionsHttpRouteDataKey, routeData);

            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, new TestTraceWriter(TraceLevel.Verbose));
            ValueBindingContext context = new ValueBindingContext(functionContext, CancellationToken.None);
            ITriggerData triggerData = await binding.BindAsync(request, context);

            Assert.Equal(2, triggerData.BindingData.Count);
            Assert.Equal("Mathew Charles", triggerData.BindingData["Name"]);
            Assert.Equal("Seattle", triggerData.BindingData["Location"]);

            TestPoco testPoco = (TestPoco)triggerData.ValueProvider.GetValue();
            Assert.Equal("Mathew Charles", testPoco.Name);
            Assert.Equal("Seattle", testPoco.Location);
        }
        public async Task BindAsync_Poco_WebHookData()
        {
            ParameterInfo parameterInfo = GetType().GetMethod("TestPocoFunction").GetParameters()[0];
            HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(), parameterInfo, true);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://functions/myfunc?code=abc123");
            TestPoco testPoco = new TestPoco
            {
                Name = "Mathew Charles",
                Location = "Seattle"
            };
            request.Properties.Add(ScriptConstants.AzureFunctionsWebHookDataKey, testPoco);

            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, new TestTraceWriter(TraceLevel.Verbose));
            ValueBindingContext context = new ValueBindingContext(functionContext, CancellationToken.None);
            ITriggerData triggerData = await binding.BindAsync(request, context);

            Assert.Equal(2, triggerData.BindingData.Count);
            Assert.Equal("Mathew Charles", triggerData.BindingData["Name"]);
            Assert.Equal("Seattle", triggerData.BindingData["Location"]);

            TestPoco result = (TestPoco)triggerData.ValueProvider.GetValue();
            Assert.Same(testPoco, result);
        }
 public AmbientBindingContext(FunctionBindingContext functionContext, IReadOnlyDictionary<string, object> bindingData)
 {
     _functionContext = functionContext;
     _bindingData = bindingData;
 }
示例#16
0
 /// <summary>
 /// Constructs a new instance.
 /// </summary>
 /// <param name="functionContext">The <see cref="FunctionBindingContext"/>.</param>
 /// <param name="bindingData">The binding data.</param>
 public AmbientBindingContext(FunctionBindingContext functionContext, IReadOnlyDictionary <string, object> bindingData)
 {
     _functionContext = functionContext;
     _bindingData     = bindingData;
 }
        public async Task BindAsync_String()
        {
            ParameterInfo parameterInfo = GetType().GetMethod("TestStringFunction").GetParameters()[0];
            HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(), parameterInfo, false);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "http://functions/myfunc?code=abc123");
            request.Content = new StringContent("This is a test");
            request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/text");

            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, new TestTraceWriter(TraceLevel.Verbose));
            ValueBindingContext context = new ValueBindingContext(functionContext, CancellationToken.None);
            ITriggerData triggerData = await binding.BindAsync(request, context);

            Assert.Equal(0, triggerData.BindingData.Count);

            string result = (string)triggerData.ValueProvider.GetValue();
            Assert.Equal("This is a test", result);
        }
        public async Task BindAsync_HttpRequestMessage_FromQueryParameters()
        {
            ParameterInfo parameterInfo = GetType().GetMethod("TestHttpRequestMessageFunction").GetParameters()[0];
            HttpTriggerAttributeBindingProvider.HttpTriggerBinding binding = new HttpTriggerAttributeBindingProvider.HttpTriggerBinding(new HttpTriggerAttribute(), parameterInfo, false);

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://functions/myfunc?code=abc123&Name=Mathew%20Charles&Location=Seattle");

            FunctionBindingContext functionContext = new FunctionBindingContext(Guid.NewGuid(), CancellationToken.None, new TestTraceWriter(TraceLevel.Verbose));
            ValueBindingContext context = new ValueBindingContext(functionContext, CancellationToken.None);
            ITriggerData triggerData = await binding.BindAsync(request, context);

            Assert.Equal(2, triggerData.BindingData.Count);
            Assert.Equal("Mathew Charles", triggerData.BindingData["Name"]);
            Assert.Equal("Seattle", triggerData.BindingData["Location"]);

            HttpRequestMessage result = (HttpRequestMessage)triggerData.ValueProvider.GetValue();
            Assert.Same(request, result);
        }
 /// <summary>
 /// Creates a new instance.
 /// </summary>
 /// <param name="functionContext">The context for the parent function.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> to use.</param>
 public ValueBindingContext(FunctionBindingContext functionContext, CancellationToken cancellationToken)
 {
     _functionContext = functionContext;
     _cancellationToken = cancellationToken;
 }