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(); }
public TestFixture() { RandomNameResolver nameResolver = new RandomNameResolver(); JobHostConfiguration hostConfiguration = new JobHostConfiguration() { NameResolver = nameResolver, TypeLocator = new FakeTypeLocator(typeof(MultipleStorageAccountsEndToEndTests)), }; Config = hostConfiguration; Account1 = CloudStorageAccount.Parse(hostConfiguration.StorageConnectionString); string secondaryConnectionString = AmbientConnectionStringProvider.Instance.GetConnectionString(Secondary); Account2 = CloudStorageAccount.Parse(secondaryConnectionString); CleanContainers(); CloudBlobClient blobClient1 = Account1.CreateCloudBlobClient(); string inputName = nameResolver.ResolveInString(Input); CloudBlobContainer inputContainer1 = blobClient1.GetContainerReference(inputName); inputContainer1.Create(); string outputName = nameResolver.ResolveWholeString(Output); OutputContainer1 = blobClient1.GetContainerReference(outputName); OutputContainer1.CreateIfNotExists(); CloudBlobClient blobClient2 = Account2.CreateCloudBlobClient(); CloudBlobContainer inputContainer2 = blobClient2.GetContainerReference(inputName); inputContainer2.Create(); OutputContainer2 = blobClient2.GetContainerReference(outputName); OutputContainer2.CreateIfNotExists(); CloudQueueClient queueClient1 = Account1.CreateCloudQueueClient(); CloudQueue inputQueue1 = queueClient1.GetQueueReference(inputName); inputQueue1.CreateIfNotExists(); OutputQueue1 = queueClient1.GetQueueReference(outputName); OutputQueue1.CreateIfNotExists(); CloudQueueClient queueClient2 = Account2.CreateCloudQueueClient(); CloudQueue inputQueue2 = queueClient2.GetQueueReference(inputName); inputQueue2.CreateIfNotExists(); OutputQueue2 = queueClient2.GetQueueReference(outputName); OutputQueue2.CreateIfNotExists(); 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"); blob.UploadText(TestData); blob = inputContainer2.GetBlockBlobReference("blob2"); blob.UploadText(TestData); // upload some test queue messages to the input queues of both storage accounts inputQueue1.AddMessage(new CloudQueueMessage(TestData)); inputQueue2.AddMessage(new CloudQueueMessage(TestData)); Host = new JobHost(hostConfiguration); Host.Start(); }