public async Task ToFunctionTrigger_Codeless_ReturnsExpected() { var functionMetadata = new FunctionMetadata { Name = "TestFunction1" }; var options = new ScriptJobHostOptions { RootScriptPath = _testRootScriptPath }; functionMetadata.SetIsCodeless(true); JObject functionConfig = JObject.Parse(_sampleBindingsJson); JArray bindingArray = (JArray)functionConfig["bindings"]; foreach (JObject binding in bindingArray) { BindingMetadata bindingMetadata = BindingMetadata.Create(binding); functionMetadata.Bindings.Add(bindingMetadata); } var result = await functionMetadata.ToFunctionTrigger(options); Assert.Equal("TestFunction1", result["functionName"].Value <string>()); Assert.Equal("httpTrigger", result["type"].Value <string>()); // make sure original binding did not change Assert.Null(functionMetadata.Bindings[0].Raw["functionName"]?.Value <string>()); Assert.Equal("httpTrigger", functionMetadata.Bindings[0].Raw["type"].Value <string>()); }
public async Task ToFunctionTrigger_InvalidConfig_ReturnsNull(string functionConfig) { var functionMetadata = new FunctionMetadata { Name = "TestFunction" }; var options = new ScriptJobHostOptions { RootScriptPath = _testRootScriptPath }; var functionPath = Path.Combine(_testRootScriptPath, functionMetadata.Name); var functionMetadataFilePath = Path.Combine(functionPath, ScriptConstants.FunctionMetadataFileName); FileUtility.EnsureDirectoryExists(functionPath); File.WriteAllText(functionMetadataFilePath, functionConfig); var result = await functionMetadata.ToFunctionTrigger(options); Assert.Null(result); }
public async Task ToFunctionTrigger_NoFile_ReturnsExpected() { var functionMetadata = new FunctionMetadata { Name = "AnyFunction", EntryPoint = "MyEntry" }; AddSampleBindings(functionMetadata); var options = new ScriptJobHostOptions { RootScriptPath = _testRootScriptPath }; var result = await functionMetadata.ToFunctionTrigger(options); Assert.Equal("AnyFunction", result["functionName"].Value <string>()); Assert.Equal("httpTrigger", result["type"].Value <string>()); }
public async Task ToFunctionTrigger_Codeless_ReturnsExpected() { var functionMetadata = new FunctionMetadata { Name = "TestFunction1" }; var options = new ScriptJobHostOptions { RootScriptPath = _testRootScriptPath }; functionMetadata.SetIsCodeless(true); AddSampleBindings(functionMetadata); var result = await functionMetadata.ToFunctionTrigger(options); Assert.Equal("TestFunction1", result["functionName"].Value <string>()); Assert.Equal("httpTrigger", result["type"].Value <string>()); // make sure original binding did not change Assert.Null(functionMetadata.Bindings[0].Raw["functionName"]?.Value <string>()); Assert.Equal("httpTrigger", functionMetadata.Bindings[0].Raw["type"].Value <string>()); }