public async Task InitializeAsync()
            {
                // TODO (kasobol-msft) find better way
                string connectionString = Environment.GetEnvironmentVariable("AzureWebJobsStorage");

                if (!string.IsNullOrWhiteSpace(connectionString))
                {
                    RandomNameResolver nameResolver = new TestNameResolver();

                    Host = new HostBuilder()
                           .ConfigureDefaultTestHost <MultipleStorageAccountsEndToEndTests>(b =>
                    {
                        b.AddAzureStorageBlobs().AddAzureStorageQueues();
                    })
                           .ConfigureServices(services =>
                    {
                        services.AddSingleton <INameResolver>(nameResolver);
                    })
                           .Build();

                    Account1 = Host.GetStorageAccount();
                    var    config = Host.Services.GetService <IConfiguration>();
                    string secondaryConnectionString = config[$"AzureWebJobs{Secondary}"];
                    Account2 = StorageAccount.NewFromConnectionString(secondaryConnectionString);

                    await CleanContainersAsync();

                    var    blobClient1     = Account1.CreateBlobServiceClient();
                    string inputName       = nameResolver.ResolveInString(Input);
                    var    inputContainer1 = blobClient1.GetBlobContainerClient(inputName);
                    await inputContainer1.CreateIfNotExistsAsync();

                    string outputName = nameResolver.ResolveWholeString(Output);
                    OutputContainer1 = blobClient1.GetBlobContainerClient(outputName);
                    await OutputContainer1.CreateIfNotExistsAsync();

                    var blobClient2     = Account2.CreateBlobServiceClient();
                    var inputContainer2 = blobClient2.GetBlobContainerClient(inputName);
                    await inputContainer2.CreateIfNotExistsAsync();

                    OutputContainer2 = blobClient2.GetBlobContainerClient(outputName);
                    await OutputContainer2.CreateIfNotExistsAsync();

                    var queueClient1 = Account1.CreateQueueServiceClient();
                    var inputQueue1  = queueClient1.GetQueueClient(inputName);
                    await inputQueue1.CreateIfNotExistsAsync();

                    OutputQueue1 = queueClient1.GetQueueClient(outputName);
                    await OutputQueue1.CreateIfNotExistsAsync();

                    var queueClient2 = Account2.CreateQueueServiceClient();
                    var inputQueue2  = queueClient2.GetQueueClient(inputName);
                    await inputQueue2.CreateIfNotExistsAsync();

                    OutputQueue2 = queueClient2.GetQueueClient(outputName);
                    await OutputQueue2.CreateIfNotExistsAsync();

                    string outputTableName = nameResolver.ResolveWholeString(OutputTableName);

                    // upload some test blobs to the input containers of both storage accounts
                    BlockBlobClient blob = inputContainer1.GetBlockBlobClient("blob1");
                    await blob.UploadTextAsync(TestData);

                    blob = inputContainer2.GetBlockBlobClient("blob2");
                    await blob.UploadTextAsync(TestData);

                    // upload some test queue messages to the input queues of both storage accounts
                    await inputQueue1.SendMessageAsync(TestData);

                    await inputQueue2.SendMessageAsync(TestData);

                    Host.Start();
                }
            }
Exemple #2
0
            public async Task InitializeAsync(WebJobsTestEnvironment testEnvironment)
            {
                RandomNameResolver nameResolver = new TestNameResolver();

                Host = new HostBuilder()
                       .ConfigureDefaultTestHost <MultipleStorageAccountsEndToEndTests>(b =>
                {
                    b.AddAzureStorageBlobs().AddAzureStorageQueues();
                })
                       .ConfigureServices(services =>
                {
                    services.AddSingleton <INameResolver>(nameResolver);
                })
                       .Build();

                BlobServiceClient1  = new BlobServiceClient(testEnvironment.PrimaryStorageAccountConnectionString);
                BlobServiceClient2  = new BlobServiceClient(testEnvironment.SecondaryStorageAccountConnectionString);
                QueueServiceClient1 = new QueueServiceClient(testEnvironment.PrimaryStorageAccountConnectionString);
                QueueServiceClient2 = new QueueServiceClient(testEnvironment.SecondaryStorageAccountConnectionString);

                await CleanContainersAsync();

                string inputName       = nameResolver.ResolveInString(Input);
                var    inputContainer1 = BlobServiceClient1.GetBlobContainerClient(inputName);
                await inputContainer1.CreateIfNotExistsAsync();

                string outputName = nameResolver.ResolveWholeString(Output);

                OutputContainer1 = BlobServiceClient1.GetBlobContainerClient(outputName);
                await OutputContainer1.CreateIfNotExistsAsync();

                var inputContainer2 = BlobServiceClient2.GetBlobContainerClient(inputName);
                await inputContainer2.CreateIfNotExistsAsync();

                OutputContainer2 = BlobServiceClient2.GetBlobContainerClient(outputName);
                await OutputContainer2.CreateIfNotExistsAsync();

                var inputQueue1 = QueueServiceClient1.GetQueueClient(inputName);
                await inputQueue1.CreateIfNotExistsAsync();

                OutputQueue1 = QueueServiceClient1.GetQueueClient(outputName);
                await OutputQueue1.CreateIfNotExistsAsync();

                var inputQueue2 = QueueServiceClient2.GetQueueClient(inputName);
                await inputQueue2.CreateIfNotExistsAsync();

                OutputQueue2 = QueueServiceClient2.GetQueueClient(outputName);
                await OutputQueue2.CreateIfNotExistsAsync();

                string outputTableName = nameResolver.ResolveWholeString(OutputTableName);

                // upload some test blobs to the input containers of both storage accounts
                BlockBlobClient blob = inputContainer1.GetBlockBlobClient("blob1");
                await blob.UploadTextAsync(TestData);

                blob = inputContainer2.GetBlockBlobClient("blob2");
                await blob.UploadTextAsync(TestData);

                // upload some test queue messages to the input queues of both storage accounts
                await inputQueue1.SendMessageAsync(TestData);

                await inputQueue2.SendMessageAsync(TestData);

                Host.Start();
            }
            public async Task InitializeAsync()
            {
                RandomNameResolver nameResolver = new TestNameResolver();

                Host = new HostBuilder()
                       .ConfigureDefaultTestHost <MultipleStorageAccountsEndToEndTests>(b =>
                {
                    b.AddAzureStorage();
                })
                       .ConfigureServices(services =>
                {
                    services.AddSingleton <INameResolver>(nameResolver);
                })
                       .Build();

                Account1 = Host.GetStorageAccount();
                var    config = Host.Services.GetService <IConfiguration>();
                string secondaryConnectionString = config[$"AzureWebJobs{Secondary}"];

                Account2 = StorageAccount.NewFromConnectionString(secondaryConnectionString);

                await CleanContainersAsync();

                CloudBlobClient    blobClient1     = Account1.CreateCloudBlobClient();
                string             inputName       = nameResolver.ResolveInString(Input);
                CloudBlobContainer inputContainer1 = blobClient1.GetContainerReference(inputName);
                await inputContainer1.CreateIfNotExistsAsync();

                string outputName = nameResolver.ResolveWholeString(Output);

                OutputContainer1 = blobClient1.GetContainerReference(outputName);
                await OutputContainer1.CreateIfNotExistsAsync();

                CloudBlobClient    blobClient2     = Account2.CreateCloudBlobClient();
                CloudBlobContainer inputContainer2 = blobClient2.GetContainerReference(inputName);
                await inputContainer2.CreateIfNotExistsAsync();

                OutputContainer2 = blobClient2.GetContainerReference(outputName);
                await OutputContainer2.CreateIfNotExistsAsync();

                CloudQueueClient queueClient1 = Account1.CreateCloudQueueClient();
                CloudQueue       inputQueue1  = queueClient1.GetQueueReference(inputName);
                await inputQueue1.CreateIfNotExistsAsync();

                OutputQueue1 = queueClient1.GetQueueReference(outputName);
                await OutputQueue1.CreateIfNotExistsAsync();

                CloudQueueClient queueClient2 = Account2.CreateCloudQueueClient();
                CloudQueue       inputQueue2  = queueClient2.GetQueueReference(inputName);
                await inputQueue2.CreateIfNotExistsAsync();

                OutputQueue2 = queueClient2.GetQueueReference(outputName);
                await OutputQueue2.CreateIfNotExistsAsync();

                CloudTableClient tableClient1    = Account1.CreateCloudTableClient();
                string           outputTableName = nameResolver.ResolveWholeString(OutputTableName);

                OutputTable1 = tableClient1.GetTableReference(outputTableName);
                OutputTable2 = Account2.CreateCloudTableClient().GetTableReference(outputTableName);

                // upload some test blobs to the input containers of both storage accounts
                CloudBlockBlob blob = inputContainer1.GetBlockBlobReference("blob1");
                await blob.UploadTextAsync(TestData);

                blob = inputContainer2.GetBlockBlobReference("blob2");
                await blob.UploadTextAsync(TestData);

                // upload some test queue messages to the input queues of both storage accounts
                await inputQueue1.AddMessageAsync(new CloudQueueMessage(TestData));

                await inputQueue2.AddMessageAsync(new CloudQueueMessage(TestData));

                Host.Start();
            }
            private async Task Initialize()
            {
                RandomNameResolver   nameResolver      = new TestNameResolver();
                JobHostConfiguration hostConfiguration = new JobHostConfiguration()
                {
                    NameResolver = nameResolver,
                    TypeLocator  = new FakeTypeLocator(typeof(MultipleStorageAccountsEndToEndTests)),
                };

                hostConfiguration.AddService <IWebJobsExceptionHandler>(new TestExceptionHandler());

                Config = hostConfiguration;

                Account1 = CloudStorageAccount.Parse(hostConfiguration.StorageConnectionString);
                string secondaryConnectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(Secondary);

                Account2 = CloudStorageAccount.Parse(secondaryConnectionString);

                await CleanContainers();

                CloudBlobClient    blobClient1     = Account1.CreateCloudBlobClient();
                string             inputName       = nameResolver.ResolveInString(Input);
                CloudBlobContainer inputContainer1 = blobClient1.GetContainerReference(inputName);
                await inputContainer1.CreateIfNotExistsAsync();

                string outputName = nameResolver.ResolveWholeString(Output);

                OutputContainer1 = blobClient1.GetContainerReference(outputName);
                await OutputContainer1.CreateIfNotExistsAsync();

                CloudBlobClient    blobClient2     = Account2.CreateCloudBlobClient();
                CloudBlobContainer inputContainer2 = blobClient2.GetContainerReference(inputName);
                await inputContainer2.CreateIfNotExistsAsync();

                OutputContainer2 = blobClient2.GetContainerReference(outputName);
                await OutputContainer2.CreateIfNotExistsAsync();

                CloudQueueClient queueClient1 = Account1.CreateCloudQueueClient();
                CloudQueue       inputQueue1  = queueClient1.GetQueueReference(inputName);
                await inputQueue1.CreateIfNotExistsAsync();

                OutputQueue1 = queueClient1.GetQueueReference(outputName);
                await OutputQueue1.CreateIfNotExistsAsync();

                CloudQueueClient queueClient2 = Account2.CreateCloudQueueClient();
                CloudQueue       inputQueue2  = queueClient2.GetQueueReference(inputName);
                await inputQueue2.CreateIfNotExistsAsync();

                OutputQueue2 = queueClient2.GetQueueReference(outputName);
                await OutputQueue2.CreateIfNotExistsAsync();

                CloudTableClient tableClient1    = Account1.CreateCloudTableClient();
                string           outputTableName = nameResolver.ResolveWholeString(OutputTableName);

                OutputTable1 = tableClient1.GetTableReference(outputTableName);
                OutputTable2 = Account2.CreateCloudTableClient().GetTableReference(outputTableName);

                // upload some test blobs to the input containers of both storage accounts
                CloudBlockBlob blob = inputContainer1.GetBlockBlobReference("blob1");
                await blob.UploadTextAsync(TestData);

                blob = inputContainer2.GetBlockBlobReference("blob2");
                await blob.UploadTextAsync(TestData);

                // upload some test queue messages to the input queues of both storage accounts
                await inputQueue1.AddMessageAsync(new CloudQueueMessage(TestData));

                await inputQueue2.AddMessageAsync(new CloudQueueMessage(TestData));

                Host = new JobHost(hostConfiguration);
                Host.Start();
            }