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_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); }
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_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_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); }