diff --git a/src/SignalRServiceExtension/TriggerBindings/SignalRTriggerBindingProvider.cs b/src/SignalRServiceExtension/TriggerBindings/SignalRTriggerBindingProvider.cs index ab92fb3..9d6912d 100644 --- a/src/SignalRServiceExtension/TriggerBindings/SignalRTriggerBindingProvider.cs +++ b/src/SignalRServiceExtension/TriggerBindings/SignalRTriggerBindingProvider.cs @@ -8,6 +8,7 @@ using System.Reflection; using System.Threading; using System.Threading.Tasks; using Microsoft.Azure.WebJobs.Description; +using Microsoft.Azure.WebJobs.Host; using Microsoft.Azure.WebJobs.Host.Triggers; using Microsoft.Extensions.Logging; @@ -95,6 +96,11 @@ namespace Microsoft.Azure.WebJobs.Extensions.SignalRService throw new InvalidOperationException( $"{nameof(SignalRTriggerAttribute)}.{nameof(SignalRTriggerAttribute.ParameterNames)} and {nameof(SignalRParameterAttribute)} can not be set in the same Function."); } + + // If we aren't using the class-based model, make sure we resolve binding expressions for attribute properties here. + hubName = _nameResolver.ResolveWholeString(hubName); + category = _nameResolver.ResolveWholeString(category); + @event = _nameResolver.ResolveWholeString(@event); } parameterNames = parameterNamesFromAttribute.Length != 0 diff --git a/test/SignalRServiceExtension.Tests/Trigger/SignalRTriggerBindingProviderTests.cs b/test/SignalRServiceExtension.Tests/Trigger/SignalRTriggerBindingProviderTests.cs index 7abdf37..a21977b 100644 --- a/test/SignalRServiceExtension.Tests/Trigger/SignalRTriggerBindingProviderTests.cs +++ b/test/SignalRServiceExtension.Tests/Trigger/SignalRTriggerBindingProviderTests.cs @@ -71,6 +71,22 @@ namespace SignalRServiceExtension.Tests Assert.Equal(new string[] { "arg0", "arg1" }, resolvedAttribute.ParameterNames); } + [Fact] + public void ResolveNonServerlessHubAttributeExpressionBindingParameterTest() + { + var bindingProvider = CreateBindingProvider(); + var attribute = new SignalRTriggerAttribute( + "%Serverless_ExpressionBindings_HubName%", + "%Serverless_ExpressionBindings_HubCategory%", + "%Serverless_ExpressionBindings_HubEvent%"); + var parameter = typeof(TestNonServerlessHub).GetMethod(nameof(TestNonServerlessHub.TestFunction), BindingFlags.Instance | BindingFlags.NonPublic).GetParameters()[0]; + var resolvedAttribute = bindingProvider.GetParameterResolvedAttribute(attribute, parameter); + Assert.Equal("test_hub", resolvedAttribute.HubName); + Assert.Equal("connections", resolvedAttribute.Category); + Assert.Equal("connected", resolvedAttribute.Event); + Assert.Equal(new string[] { "arg0", "arg1" }, resolvedAttribute.ParameterNames); + } + [Fact] public void ResolveAttributeParameterConflictTest() { @@ -93,8 +109,11 @@ namespace SignalRServiceExtension.Tests { var configuration = new ConfigurationBuilder().AddInMemoryCollection().Build(); configuration[Constants.AzureSignalRConnectionStringName]= "Endpoint=http://localhost;AccessKey=ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789;Version=1.0;"; + configuration["Serverless_ExpressionBindings_HubName"] = "test_hub"; + configuration["Serverless_ExpressionBindings_HubCategory"] = "connections"; + configuration["Serverless_ExpressionBindings_HubEvent"] = "connected"; var dispatcher = new TestTriggerDispatcher(); - return new SignalRTriggerBindingProvider(dispatcher, new DefaultNameResolver(new ConfigurationSection(new ConfigurationRoot(new List()), String.Empty)), new ServiceManagerStore(configuration, NullLoggerFactory.Instance, null), exception); + return new SignalRTriggerBindingProvider(dispatcher, new DefaultNameResolver(configuration), new ServiceManagerStore(configuration, NullLoggerFactory.Instance, null), exception); } public class TestServerlessHub : ServerlessHub