Fix for Issue 159: Expression bindings for SignalRTrigger not functioning (#160)

Authored-by: Alan Holt <aholt@penlink.com>
This commit is contained in:
holtalanm 2021-03-01 00:55:49 -08:00 коммит произвёл GitHub
Родитель 10f3614d16
Коммит bb6f714e0e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 26 добавлений и 1 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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<IConfigurationProvider>()), 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