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);
        }
Exemplo n.º 2
0
        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.");
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        public IStorageQueue Convert(string input)
        {
            string queueName;

            // For convenience, treat an an empty string as a request for the default value.
            if (String.IsNullOrEmpty(input) && _defaultPath.IsBound)
            {
                queueName = _defaultPath.Bind(null);
            }
            else
            {
                queueName = BindableQueuePath.NormalizeAndValidate(input);
            }

            return(_client.GetQueueReference(queueName));
        }
Exemplo n.º 6
0
 public void Create_IfNullPattern_Throws()
 {
     ExceptionAssert.ThrowsArgumentNull(() => BindableQueuePath.Create(null), "queueNamePattern");
 }