public void AddsStorageOutput_FromReturnType() { FunctionContext context = GetContextWithOutputBindings(nameof(JustStorage.MyQueueOutput), nameof(JustStorage.MyBlobOutput)); JustStorage result = new JustStorage() { MyQueueOutput = "queueStuff", MyBlobOutput = "blobStuff" }; context.GetBindings().InvocationResult = result; Assert.Empty(context.GetBindings().OutputBindingData); OutputBindingsMiddleware.AddOutputBindings(context); object returnedVal = context.GetBindings().InvocationResult; Assert.Null(returnedVal); Assert.Equal(2, context.GetBindings().OutputBindingData.Count); AssertDictionary(context.GetBindings().OutputBindingData, new Dictionary <string, object>() { { "MyQueueOutput", "queueStuff" }, { "MyBlobOutput", "blobStuff" } }); }
public void AddsStorageOutput_AndHttpReturn_FromReturnType() { FunctionContext context = GetContextWithOutputBindings(nameof(HttpAndStorage.MyQueueOutput), nameof(HttpAndStorage.MyBlobOutput), nameof(HttpAndStorage.MyHttpResponseData)); var emptyHttp = new TestHttpResponseData(context, HttpStatusCode.OK); HttpAndStorage result = new HttpAndStorage() { MyQueueOutput = "queueStuff", MyBlobOutput = "blobStuff", MyRandomValue = "ShouldNotAppear", MyHttpResponseData = emptyHttp }; context.GetBindings().InvocationResult = result; Assert.Equal(0, context.GetBindings().OutputBindingData.Count); OutputBindingsMiddleware.AddOutputBindings(context); object returnedVal = context.GetBindings().InvocationResult; Assert.Null(returnedVal); Assert.Equal(3, context.GetBindings().OutputBindingData.Count); AssertDictionary(context.GetBindings().OutputBindingData, new Dictionary <string, object>() { { "MyQueueOutput", "queueStuff" }, { "MyBlobOutput", "blobStuff" }, { "MyHttpResponseData", emptyHttp } }); }
public void SetsResult_NoBinding() { // No binding, should leave invocation result untouched FunctionContext context = GetContextWithOutputBindings(); string myData = "abc"; context.GetBindings().InvocationResult = myData; Assert.Empty(context.GetBindings().OutputBindingData); OutputBindingsMiddleware.AddOutputBindings(context); object returnedVal = context.GetBindings().InvocationResult; Assert.Equal("abc", returnedVal); Assert.Equal(0, context.GetBindings().OutputBindingData.Count); }
public void SetsOutput_FromMethodBinding() { // special binding to indicate the return value is set as an output binding FunctionContext context = GetContextWithOutputBindings("$return"); var emptyHttp = new TestHttpResponseData(context, HttpStatusCode.OK); context.GetBindings().InvocationResult = emptyHttp; Assert.Empty(context.GetBindings().OutputBindingData); OutputBindingsMiddleware.AddOutputBindings(context); object returnedVal = context.GetBindings().InvocationResult; Assert.Equal(returnedVal, emptyHttp); Assert.Empty(context.GetBindings().OutputBindingData); AssertDictionary(context.GetBindings().OutputBindingData, new Dictionary <string, object>()); }
public void AddsSingleOutput_FromMethodReturn() { // Special binding name indiciating return FunctionContext context = GetContextWithOutputBindings("$return"); string result = "MyStorageData"; context.GetBindings().InvocationResult = result; Assert.Empty(context.GetBindings().OutputBindingData); OutputBindingsMiddleware.AddOutputBindings(context); object returnedVal = context.GetBindings().InvocationResult; Assert.Equal(returnedVal, result); Assert.Empty(context.GetBindings().OutputBindingData); AssertDictionary(context.GetBindings().OutputBindingData, new Dictionary <string, object>()); }
/// <summary> /// Configures the <see cref="IFunctionsWorkerApplicationBuilder"/> to use the default <see cref="OutputBindingsMiddleware"/>. /// </summary> /// <param name="builder">The <see cref="IFunctionsWorkerApplicationBuilder"/> to configure.</param> /// <returns>The same instance of the <see cref="IFunctionsWorkerApplicationBuilder"/> for chanining.</returns> public static IFunctionsWorkerApplicationBuilder UseOutputBindingsMiddleware(this IFunctionsWorkerApplicationBuilder builder) { if (builder.Services.Any(d => d.ServiceType == typeof(OutputBindingsMiddleware))) { return(builder); } builder.Services.AddSingleton <OutputBindingsMiddleware>(p => throw new InvalidOperationException($"Type {nameof(OutputBindingsMiddleware)} cannot be resolved using the container.")); builder.Use(next => { return(context => { return OutputBindingsMiddleware.Invoke(context, next); }); }); return(builder); }