Skip to content

Commit 81c80ae

Browse files
committed
Fixing issue with type/function indexing when multiple functions are defined in a single type
1 parent e378c87 commit 81c80ae

File tree

5 files changed

+46
-4
lines changed

5 files changed

+46
-4
lines changed

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ private void GenerateFunctions()
500500
Type functionWrapperType = FunctionGenerator.Generate(HostAssemblyName, typeName, typeAttributes, Functions);
501501

502502
// configure the Type locator
503-
var types = new List<Type>
503+
var types = new HashSet<Type>
504504
{
505505
functionWrapperType
506506
};

test/TestFunctions/Function1.cs renamed to test/TestFunctions/Functions.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace TestFunctions
1111
{
12-
public static class Function1
12+
public static class Functions
1313
{
1414
[FunctionName("Function1")]
1515
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
@@ -34,5 +34,29 @@ public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get",
3434
? (ActionResult)new OkObjectResult($"Hello, {name}!")
3535
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
3636
}
37+
38+
[FunctionName("Function2")]
39+
public static IActionResult Function2([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log)
40+
{
41+
log.LogInformation("C# HTTP trigger function processed a request.");
42+
43+
string action = req.Query["action"];
44+
if (action == "throw")
45+
{
46+
throw new InvalidOperationException("Kaboom!");
47+
}
48+
49+
string name = req.Query["name"];
50+
51+
// Explicitly read the body synchronously; this is used in the AllowSynchronousIOMiddleware tests
52+
string requestBody = new StreamReader(req.Body).ReadToEnd();
53+
54+
dynamic data = JsonConvert.DeserializeObject(requestBody);
55+
name = name ?? data?.name;
56+
57+
return name != null
58+
? (ActionResult)new OkObjectResult($"Hello, {name}!")
59+
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
60+
}
3761
}
3862
}

test/WebJobs.Script.Tests.Integration/ScriptHostEndToEnd/DirectLoadEndToEndTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public async Task Invoke_ExceptionThrown_DetailsLogged()
9191
var error = errorLogs[0];
9292
var invocationException = (FunctionInvocationException)error.Exception;
9393
Assert.Equal("Exception while executing function: Function1", invocationException.Message);
94-
Assert.Equal("TestFunctions.Function1.Run", invocationException.MethodName);
94+
Assert.Equal("TestFunctions.Functions.Run", invocationException.MethodName);
9595
Assert.Equal("Function1", error.Scope[ScopeKeys.FunctionName]);
9696
Assert.Equal(LogCategories.CreateFunctionCategory("Function1"), error.Category);
9797
}

test/WebJobs.Script.Tests.Integration/TestScripts/DirectLoad/Function1/function.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
],
1515
"disabled": false,
1616
"scriptFile": "..\\..\\..\\TestFunctions.dll",
17-
"entryPoint": "TestFunctions.Function1.Run"
17+
"entryPoint": "TestFunctions.Functions.Run"
1818
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"generatedBy": "Microsoft.NET.Sdk.Functions-1.0.13",
3+
"configurationSource": "attributes",
4+
"bindings": [
5+
{
6+
"type": "httpTrigger",
7+
"methods": [
8+
"get",
9+
"post"
10+
],
11+
"authLevel": "function",
12+
"name": "req"
13+
}
14+
],
15+
"disabled": false,
16+
"scriptFile": "..\\..\\..\\TestFunctions.dll",
17+
"entryPoint": "TestFunctions.Functions.Function2"
18+
}

0 commit comments

Comments
 (0)