Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sdk/Sdk/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal static class Constants
internal const string ReadOnlyMemoryOfBytes = "System.ReadOnlyMemory`1<System.Byte>";

internal const string ReturnBindingName = "$return";
internal const string HttpTriggerBindingType = "HttpTrigger";
internal const string HttpTriggerBindingType = "httpTrigger";
internal const string IsBatchedKey = "IsBatched";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.Cecil;

namespace Microsoft.Azure.Functions.Worker.Sdk
Copy link
Copy Markdown
Member Author

@kshyju kshyju Aug 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved 2 existing extension method classes under the new "Extensions" directory. They were in the root of the project earlier.

Expand Down
26 changes: 26 additions & 0 deletions sdk/Sdk/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using System.Linq;
using System;

namespace Microsoft.Azure.Functions.Worker.Sdk
{
internal static class StringExtensions
{
/// <summary>
/// Returns a copy of the string where the first character is in lower case.
/// </summary>
public static string ToLowerFirstCharacter(this string str)
{
if (!string.IsNullOrEmpty(str))
{
return Char.ToLowerInvariant(str.First()) + str.Substring(1);
}
else
{
return str;
}
}
}
}
15 changes: 10 additions & 5 deletions sdk/Sdk/FunctionMetadataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,16 @@ private static string GetBindingType(CustomAttribute attribute)
var attributeType = attribute.AttributeType.Name;

// TODO: Should "webjob type" be a property of the "worker types" and come from there?
return attributeType
.Replace("TriggerAttribute", "Trigger")
.Replace("InputAttribute", string.Empty)
.Replace("OutputAttribute", string.Empty)
.Replace("Attribute", string.Empty);
var bindingType = attributeType
.Replace("TriggerAttribute", "Trigger")
.Replace("InputAttribute", string.Empty)
.Replace("OutputAttribute", string.Empty)
.Replace("Attribute", string.Empty);

// The first character of "Type" property value must be lower case for the scaling infrastructure to work correctly
bindingType = bindingType.ToLowerFirstCharacter();

return bindingType;
}

private static void AddHttpOutputBinding(IList<ExpandoObject> bindingMetadata, string name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void ValidateTrigger(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "myReq" },
{ "Type", "HttpTrigger" },
{ "Type", "httpTrigger" },
{ "Direction", "In" },
{ "authLevel", "Admin" },
{ "methods", new[] { "get", "Post" } },
Expand Down Expand Up @@ -86,7 +86,7 @@ void ValidateTrigger(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "myReq" },
{ "Type", "HttpTrigger" },
{ "Type", "httpTrigger" },
{ "Direction", "In" },
{ "authLevel", "Admin" },
{ "methods", new[] { "get", "Post" } },
Expand Down Expand Up @@ -119,7 +119,7 @@ void ValidateTrigger(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "myReq" },
{ "Type", "HttpTrigger" },
{ "Type", "httpTrigger" },
{ "Direction", "In" },
{ "authLevel", "Admin" },
{ "methods", new[] { "get", "Post" } },
Expand Down Expand Up @@ -169,7 +169,7 @@ void ValidateQueueTrigger(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "queuePayload" },
{ "Type", "QueueTrigger" },
{ "Type", "queueTrigger" },
{ "Direction", "In" },
{ "Connection", "MyConnection" },
{ "queueName", "queueName" },
Expand All @@ -182,7 +182,7 @@ void ValidateBlobOutput(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "$return" },
{ "Type", "Blob" },
{ "Type", "blob" },
{ "Direction", "Out" },
{ "blobPath", "container1/hello.txt" },
{ "Connection", "MyOtherConnection" }
Expand All @@ -198,7 +198,7 @@ void ValidateBlobTrigger(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "blob" },
{ "Type", "BlobTrigger" },
{ "Type", "blobTrigger" },
{ "Direction", "In" },
{ "blobPath", "container2/%file%" },
{ "DataType", "String" }
Expand All @@ -210,7 +210,7 @@ void ValidateQueueOutput(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "$return" },
{ "Type", "Queue" },
{ "Type", "queue" },
{ "Direction", "Out" },
{ "queueName", "queue2" },
});
Expand All @@ -236,7 +236,7 @@ void ValidateTrigger(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "timer" },
{ "Type", "TimerTrigger" },
{ "Type", "timerTrigger" },
{ "Direction", "In" },
{ "schedule", "0 0 0 * * *" },
{ "RunOnStartup", false }
Expand Down Expand Up @@ -273,7 +273,7 @@ void ValidateQueueTrigger(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "queuePayload" },
{ "Type", "QueueTrigger" },
{ "Type", "queueTrigger" },
{ "Direction", "In" },
{ "Connection", "MyConnection" },
{ "queueName", "queueName" },
Expand All @@ -286,7 +286,7 @@ void ValidateBlobOutput(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "blobOutput" },
{ "Type", "Blob" },
{ "Type", "blob" },
{ "Direction", "Out" },
{ "blobPath", "container1/hello.txt" },
{ "Connection", "MyOtherConnection" },
Expand All @@ -299,7 +299,7 @@ void ValidateQueueOutput(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "queueOutput" },
{ "Type", "Queue" },
{ "Type", "queue" },
{ "Direction", "Out" },
{ "queueName", "queue2" },
{ "DataType", "String" }
Expand Down Expand Up @@ -335,7 +335,7 @@ void ValidateHttpTrigger(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "req" },
{ "Type", "HttpTrigger" },
{ "Type", "httpTrigger" },
{ "Direction", "In" },
{ "methods", new[] { "get" } },
{ "DataType", "String" }
Expand All @@ -357,7 +357,7 @@ void ValidateQueueOutput(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "queueOutput" },
{ "Type", "Queue" },
{ "Type", "queue" },
{ "Direction", "Out" },
{ "queueName", "queue2" },
{ "DataType", "String" }
Expand Down Expand Up @@ -389,7 +389,7 @@ void ValidateHttpTrigger(ExpandoObject b)
AssertExpandoObject(b, new Dictionary<string, object>
{
{ "Name", "req" },
{ "Type", "HttpTrigger" },
{ "Type", "httpTrigger" },
{ "Direction", "In" },
{ "methods", new[] { "get" } },
{ "DataType", "String" }
Expand Down Expand Up @@ -468,7 +468,7 @@ void ValidateTrigger(ExpandoObject b, bool many)
var expected = new Dictionary<string, object>()
{
{ "Name", "input" },
{ "Type", "EventHubTrigger" },
{ "Type", "eventHubTrigger" },
{ "Direction", "In" },
{ "eventHubName", "test" },
{ "Connection", "EventHubConnectionAppSetting" }
Expand Down
24 changes: 24 additions & 0 deletions test/FunctionMetadataGeneratorTests/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

using Microsoft.Azure.Functions.Worker.Sdk;
using Xunit;

namespace Microsoft.Azure.Functions.SdkTests
{
public class StringExtensionsTests
{
[Theory]
[InlineData("HttpTrigger", "httpTrigger")]
[InlineData("Blob", "blob")]
[InlineData("http", "http")]
[InlineData("", "")]
[InlineData(null, null)]
public void ToLowerFirstCharacterWorks(string input, string expectedOutput)
{
var actual = input.ToLowerFirstCharacter();

Assert.Equal(expectedOutput, actual);
}
}
}
18 changes: 9 additions & 9 deletions test/SdkE2ETests/Contents/functions.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"bindings": [
{
"name": "req",
"type": "HttpTrigger",
"type": "httpTrigger",
"direction": "In",
"authLevel": "Anonymous",
"methods": [
Expand All @@ -20,15 +20,15 @@
},
{
"name": "myBlob",
"type": "Blob",
"type": "blob",
"direction": "In",
"dataType": "String",
"blobPath": "test-samples/sample1.txt",
"connection": "AzureWebJobsStorage"
},
{
"name": "Book",
"type": "Queue",
"type": "queue",
"direction": "Out",
"queueName": "functionstesting2",
"connection": "AzureWebJobsStorage"
Expand All @@ -51,14 +51,14 @@
"bindings": [
{
"name": "myQueueItem",
"type": "QueueTrigger",
"type": "queueTrigger",
"direction": "In",
"queueName": "functionstesting2",
"connection": "AzureWebJobsStorage"
},
{
"name": "myBlob",
"type": "Blob",
"type": "blob",
"direction": "In",
"dataType": "String",
"blobPath": "test-samples/sample1.txt",
Expand All @@ -77,7 +77,7 @@
"bindings": [
{
"name": "req",
"type": "HttpTrigger",
"type": "httpTrigger",
"direction": "In",
"authLevel": "Anonymous",
"methods": [
Expand All @@ -87,7 +87,7 @@
},
{
"name": "Name",
"type": "Queue",
"type": "queue",
"direction": "Out",
"dataType": "String",
"queueName": "functionstesting2",
Expand All @@ -111,7 +111,7 @@
"bindings": [
{
"name": "req",
"type": "HttpTrigger",
"type": "httpTrigger",
"direction": "In",
"authLevel": "Anonymous",
"methods": [
Expand All @@ -137,7 +137,7 @@
"bindings": [
{
"name": "req",
"type": "HttpTrigger",
"type": "httpTrigger",
"direction": "In",
"authLevel": "Anonymous",
"methods": [
Expand Down