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 Bind_IfNullBindingData_Throws() { const string queueNamePattern = "queue-{name}-with-{parameter}"; IBindableQueuePath path = CreateProductUnderTest(queueNamePattern); ExceptionAssert.ThrowsArgumentNull(() => path.Bind(null), "bindingData"); }
private static IObjectToTypeConverter <IStorageQueue> CreateConverter(IStorageQueueClient client, IBindableQueuePath path) { return(new CompositeObjectToTypeConverter <IStorageQueue>( new OutputConverter <IStorageQueue>(new IdentityConverter <IStorageQueue>()), new OutputConverter <CloudQueue>(new CloudQueueToStorageQueueConverter()), new OutputConverter <string>(new StringToStorageQueueConverter(client, path)))); }
private static IObjectToTypeConverter<IStorageQueue> CreateConverter(IStorageQueueClient client, IBindableQueuePath path) { return new CompositeObjectToTypeConverter<IStorageQueue>( new OutputConverter<IStorageQueue>(new IdentityConverter<IStorageQueue>()), new OutputConverter<CloudQueue>(new CloudQueueToStorageQueueConverter()), new OutputConverter<string>(new StringToStorageQueueConverter(client, path))); }
public QueueBinding(string parameterName, IArgumentBinding <IStorageQueue> argumentBinding, IStorageQueueClient client, IBindableQueuePath path) { _parameterName = parameterName; _argumentBinding = argumentBinding; _client = client; _accountName = QueueClient.GetAccountName(client); _path = path; _converter = CreateConverter(client, path); }
public QueueBinding(string parameterName, IArgumentBinding<IStorageQueue> argumentBinding, IStorageQueueClient client, IBindableQueuePath path) { _parameterName = parameterName; _argumentBinding = argumentBinding; _client = client; _accountName = QueueClient.GetAccountName(client); _path = path; _converter = CreateConverter(client, path); }
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 Bind_IfNotNullBindingData_ReturnsResolvedQueueName() { const string queueNamePattern = "queue-{name}-with-{parameter}"; var bindingData = new Dictionary <string, object> { { "name", "name" }, { "parameter", "parameter" } }; IBindableQueuePath path = CreateProductUnderTest(queueNamePattern); string result = path.Bind(bindingData); Assert.Equal("queue-name-with-parameter", result); }
public StringToStorageQueueConverter(IStorageQueueClient client, IBindableQueuePath defaultPath) { _client = client; _defaultPath = defaultPath; }