public async Task <IBinding> TryCreateAsync(BindingProviderContext context) { ParameterInfo parameter = context.Parameter; QueueAttribute queueAttribute = parameter.GetCustomAttribute <QueueAttribute>(inherit: false); if (queueAttribute == null) { return(null); } string queueName = Resolve(queueAttribute.QueueName); IBindableQueuePath path = BindableQueuePath.Create(queueName); path.ValidateContractCompatibility(context.BindingDataContract); IArgumentBinding <IStorageQueue> argumentBinding = _innerProvider.TryCreate(parameter); if (argumentBinding == null) { throw new InvalidOperationException("Can't bind Queue to type '" + parameter.ParameterType + "'."); } IStorageAccount account = await _accountProvider.GetStorageAccountAsync(context.Parameter, context.CancellationToken); StorageClientFactoryContext clientFactoryContext = new StorageClientFactoryContext { Parameter = parameter }; IStorageQueueClient client = account.CreateQueueClient(clientFactoryContext); IBinding binding = new QueueBinding(parameter.Name, argumentBinding, client, path); return(binding); }
public void Create_IfMalformedPattern_PropagatesThrownException() { const string queueNamePattern = "malformed-queue-{name%"; ExceptionAssert.ThrowsFormat( () => BindableQueuePath.Create(queueNamePattern), "Invalid template 'malformed-queue-{name%'. Missing closing bracket at position 17."); }
public void Create_IfParameterizedPattern_ReturnsNotBoundPath() { const string queueNamePattern = "queue-{name}-with-{parameter}"; IBindableQueuePath path = BindableQueuePath.Create(queueNamePattern); Assert.NotNull(path); Assert.Equal(queueNamePattern, path.QueueNamePattern); Assert.False(path.IsBound); }
public void Create_IfNonParameterizedPattern_ReturnsBoundPath() { const string queueNamePattern = "queue-name-with-no-parameters"; IBindableQueuePath path = BindableQueuePath.Create(queueNamePattern); Assert.NotNull(path); Assert.Equal(queueNamePattern, path.QueueNamePattern); Assert.True(path.IsBound); }
public void Create_IfNullPattern_Throws() { ExceptionAssert.ThrowsArgumentNull(() => BindableQueuePath.Create(null), "queueNamePattern"); }