public static CreateTestBinding ( JObject json ) : FunctionBinding | ||
json | JObject | |
Результат | FunctionBinding |
public void ValidateFunctionBindingArguments_ReturnBinding_Succeeds() { Collection <FunctionParameter> parameters = new Collection <FunctionParameter>() { new FunctionParameter("input", "String", false, RefKind.None) }; FunctionSignature signature = new FunctionSignature("Test", "Test", ImmutableArray.CreateRange <FunctionParameter>(parameters), "Test", false); Collection <FunctionBinding> inputBindings = new Collection <FunctionBinding>() { TestHelpers.CreateTestBinding(new JObject { { "type", "blobTrigger" }, { "name", "input" }, { "direction", "in" }, { "path", "test" } }) }; Collection <FunctionBinding> outputBindings = new Collection <FunctionBinding>() { TestHelpers.CreateTestBinding(new JObject { { "type", "blob" }, { "name", ScriptConstants.SystemReturnParameterBindingName }, { "direction", "out" }, { "path", "test/test" } }) }; var diagnostics = DotNetFunctionInvoker.ValidateFunctionBindingArguments(signature, "input", inputBindings, outputBindings); Assert.Equal(0, diagnostics.Count()); }
public void TryCreateReturnValueParameterDescriptor_ReturnBindingPresent_ReturnsExpectedValue() { JObject json = new JObject { { "type", "blob" }, { "name", ScriptConstants.SystemReturnParameterBindingName }, { "direction", "out" }, { "path", "foo/bar" } }; FunctionBinding functionBinding = TestHelpers.CreateTestBinding(json); FunctionBinding[] bindings = new FunctionBinding[] { functionBinding }; ParameterDescriptor descriptor = null; var result = DotNetFunctionDescriptorProvider.TryCreateReturnValueParameterDescriptor(typeof(string), bindings, out descriptor); Assert.True(result); Assert.Equal(ScriptConstants.SystemReturnParameterName, descriptor.Name); Assert.True((descriptor.Attributes & ParameterAttributes.Out) != 0); Assert.Equal(typeof(string).MakeByRefType(), descriptor.Type); Assert.Equal(1, descriptor.CustomAttributes.Count); result = DotNetFunctionDescriptorProvider.TryCreateReturnValueParameterDescriptor(typeof(Task <string>), bindings, out descriptor); Assert.True(result); Assert.Equal(ScriptConstants.SystemReturnParameterName, descriptor.Name); Assert.True((descriptor.Attributes & ParameterAttributes.Out) != 0); Assert.Equal(typeof(string).MakeByRefType(), descriptor.Type); Assert.Equal(1, descriptor.CustomAttributes.Count); // return type task means no return value result = DotNetFunctionDescriptorProvider.TryCreateReturnValueParameterDescriptor(typeof(Task), bindings, out descriptor); Assert.False(result); }
public void TryCreateReturnValueParameterDescriptor_NoReturnBinding_ReturnsExpectedValue() { JObject json = new JObject { { "type", "httpTrigger" }, { "name", "myInput" }, { "direction", "in" } }; FunctionBinding functionBinding = TestHelpers.CreateTestBinding(json); FunctionBinding[] bindings = new FunctionBinding[] { functionBinding }; ParameterDescriptor descriptor = null; var result = DotNetFunctionDescriptorProvider.TryCreateReturnValueParameterDescriptor(typeof(void), bindings, out descriptor); Assert.False(result); }
public void TryCreateReturnValueParameterDescriptor_ReturnBindingPresent_ReturnsExpectedValue() { JObject json = new JObject { { "type", "blob" }, { "name", ScriptConstants.SystemReturnParameterBindingName }, { "direction", "out" }, { "path", "foo/bar" } }; FunctionBinding functionBinding = TestHelpers.CreateTestBinding(json); FunctionBinding[] bindings = new FunctionBinding[] { functionBinding }; ParameterDescriptor descriptor = null; var result = DotNetFunctionDescriptorProvider.TryCreateReturnValueParameterDescriptor(typeof(string), bindings, out descriptor); Assert.True(result); Assert.Equal(ScriptConstants.SystemReturnParameterName, descriptor.Name); Assert.True((descriptor.Attributes & ParameterAttributes.Out) != 0); Assert.Equal(typeof(string).MakeByRefType(), descriptor.Type); Assert.Equal(1, descriptor.CustomAttributes.Count); result = DotNetFunctionDescriptorProvider.TryCreateReturnValueParameterDescriptor(typeof(Task <string>), bindings, out descriptor); Assert.True(result); Assert.Equal(ScriptConstants.SystemReturnParameterName, descriptor.Name); Assert.True((descriptor.Attributes & ParameterAttributes.Out) != 0); Assert.Equal(typeof(string).MakeByRefType(), descriptor.Type); Assert.Equal(1, descriptor.CustomAttributes.Count); var ex = Assert.Throws <InvalidOperationException>(() => { DotNetFunctionDescriptorProvider.TryCreateReturnValueParameterDescriptor(typeof(Task), bindings, out descriptor); }); Assert.Equal($"{ScriptConstants.SystemReturnParameterBindingName} cannot be bound to return type {typeof(Task).Name}.", ex.Message); }