public void ToParameterDescriptor_ReturnsExpectedDescriptor() { Mock<IArgumentBinding<IStorageBlobContainer>> mockArgumentBinding = new Mock<IArgumentBinding<IStorageBlobContainer>>(MockBehavior.Strict); Mock<IStorageBlobClient> mockStorageClient = new Mock<IStorageBlobClient>(MockBehavior.Strict); Mock<IBindableBlobPath> mockBlobPath = new Mock<IBindableBlobPath>(MockBehavior.Strict); BlobContainerBinding binding = new BlobContainerBinding("testparam", mockArgumentBinding.Object, mockStorageClient.Object, mockBlobPath.Object); ParameterDescriptor descriptor = binding.ToParameterDescriptor(); Assert.Equal(typeof(ParameterDescriptor), descriptor.GetType()); Assert.Equal("testparam", descriptor.Name); Assert.Equal("Enter the blob container name or blob path prefix", descriptor.DisplayHints.Prompt); }
public async Task <IBinding> TryCreateAsync(BindingProviderContext context) { ParameterInfo parameter = context.Parameter; BlobAttribute blobAttribute = parameter.GetCustomAttribute <BlobAttribute>(inherit: false); if (blobAttribute == null) { return(null); } string resolvedPath = Resolve(blobAttribute.BlobPath); IBindableBlobPath path = null; IStorageAccount account = await _accountProvider.GetStorageAccountAsync(context.Parameter, context.CancellationToken); StorageClientFactoryContext clientFactoryContext = new StorageClientFactoryContext { Parameter = context.Parameter }; IStorageBlobClient client = account.CreateBlobClient(clientFactoryContext); // first try to bind to the Container IArgumentBinding <IStorageBlobContainer> containerArgumentBinding = _blobContainerArgumentProvider.TryCreate(parameter); if (containerArgumentBinding == null) { // if this isn't a Container binding, try a Blob binding IBlobArgumentBinding blobArgumentBinding = _blobArgumentProvider.TryCreate(parameter, blobAttribute.Access); if (blobArgumentBinding == null) { throw new InvalidOperationException("Can't bind Blob to type '" + parameter.ParameterType + "'."); } path = BindableBlobPath.Create(resolvedPath); path.ValidateContractCompatibility(context.BindingDataContract); return(new BlobBinding(parameter.Name, blobArgumentBinding, client, path)); } path = BindableBlobPath.Create(resolvedPath, isContainerBinding: true); path.ValidateContractCompatibility(context.BindingDataContract); BlobContainerBinding.ValidateContainerBinding(blobAttribute, parameter.ParameterType, path); return(new BlobContainerBinding(parameter.Name, containerArgumentBinding, client, path)); }