public async Task BindToBlobViaPOCO(string storageProviderType) { using (ITestHost host = TestHelpers.GetJobHost(this.loggerProvider, nameof(this.BindToBlobViaPOCO), false, storageProviderType)) { await host.StartAsync(); string connectionString = TestHelpers.GetStorageConnectionString(); CloudStorageAccount account = CloudStorageAccount.Parse(connectionString); this.output.WriteLine($"Using storage account: {account.Credentials.AccountName}"); // Blob and container names need to be kept in sync with the activity code. var data = new { InputPrefix = "Input", OutputPrefix = "Output", Suffix = 42, }; const string ContainerName = "test"; string inputBlobName = $"{data.InputPrefix}-{data.Suffix}"; string outputBlobName = $"{data.OutputPrefix}-{data.Suffix}"; CloudBlobClient blobClient = account.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference(ContainerName); if (await container.CreateIfNotExistsAsync()) { this.output.WriteLine($"Created container '{container.Name}'."); } string randomData = Guid.NewGuid().ToString("N"); this.output.WriteLine($"Creating blob named {outputBlobName}..."); CloudBlockBlob blob = container.GetBlockBlobReference(inputBlobName); await blob.UploadTextAsync(randomData); this.output.WriteLine($"Uploaded text '{randomData}' to {blob.Name}."); // Using StartOrchestrationArgs to start an activity function because it's easier than creating a new type. var startArgs = new StartOrchestrationArgs(); startArgs.FunctionName = nameof(TestActivities.BindToBlobViaJsonPayload); startArgs.Input = data; var client = await host.StartOrchestratorAsync(nameof(TestOrchestrations.CallActivity), startArgs, this.output); var status = await client.WaitForCompletionAsync(this.output); Assert.Equal(OrchestrationRuntimeStatus.Completed, status?.RuntimeStatus); this.output.WriteLine($"Searching for blob named {outputBlobName}..."); CloudBlockBlob newBlob = container.GetBlockBlobReference(outputBlobName); string copiedData = await newBlob.DownloadTextAsync(); this.output.WriteLine($"Downloaded text '{copiedData}' from {newBlob.Name}."); Assert.Equal(randomData, copiedData); await host.StopAsync(); } }
public async Task TimerLengthLessThanMaxTime(bool extendedSessions) { using (ITestHost host = TestHelpers.GetJobHost( this.loggerProvider, nameof(this.TimerLengthLessThanMaxTime), extendedSessions, storageProviderType: "azure_storage", durabilityProviderFactoryType: typeof(AzureStorageShortenedTimerDurabilityProviderFactory))) { await host.StartAsync(); var fireAt = DateTime.UtcNow.AddSeconds(30); var client = await host.StartOrchestratorAsync(nameof(TestOrchestrations.Timer), fireAt, this.output); var status = await client.WaitForCompletionAsync(this.output, timeout : TimeSpan.FromMinutes(2)); Assert.Equal(OrchestrationRuntimeStatus.Completed, status.RuntimeStatus); await host.StopAsync(); } }
public async Task ActivityTriggerAsNumber(string storageProviderType) { using (ITestHost host = TestHelpers.GetJobHost(this.loggerProvider, nameof(this.ActivityTriggerAsNumber), false, storageProviderType)) { await host.StartAsync(); // Using StartOrchestrationArgs to start an activity function because it's easier than creating a new type. var startArgs = new StartOrchestrationArgs(); startArgs.FunctionName = nameof(TestActivities.BindToDouble); startArgs.Input = 3.14; var client = await host.StartOrchestratorAsync(nameof(TestOrchestrations.CallActivity), startArgs, this.output); var status = await client.WaitForCompletionAsync(this.output); // The function echos back the input value Assert.Equal(OrchestrationRuntimeStatus.Completed, status?.RuntimeStatus); Assert.Equal((double)startArgs.Input, status?.Output); await host.StopAsync(); } }
public async Task WaitForExternalEventAboveMaximumTimerLength() { using (ITestHost host = TestHelpers.GetJobHost( this.loggerProvider, nameof(this.WaitForExternalEventAboveMaximumTimerLength), enableExtendedSessions: false, storageProviderType: "azure_storage", durabilityProviderFactoryType: typeof(AzureStorageShortenedTimerDurabilityProviderFactory))) { await host.StartAsync(); var fireAt = TimeSpan.FromSeconds(90); var client = await host.StartOrchestratorAsync(nameof(TestOrchestrations.ApprovalWithTimeout), (fireAt, "throw"), this.output); var status = await client.WaitForCompletionAsync(this.output, timeout : TimeSpan.FromMinutes(2)); Assert.Equal(OrchestrationRuntimeStatus.Completed, status?.RuntimeStatus); Assert.Equal("TimeoutException", status?.Output); await host.StopAsync(); } }
private async Task ActivityTriggerAsJObject(string storageProviderType) { using (ITestHost host = TestHelpers.GetJobHost(this.loggerProvider, nameof(this.ActivityTriggerAsJObject), false, storageProviderType)) { await host.StartAsync(); // Using StartOrchestrationArgs to start an activity function because it's easier than creating a new type. var startArgs = new StartOrchestrationArgs(); startArgs.FunctionName = nameof(TestActivities.BindToJObject); startArgs.Input = new { Foo = "Bar" }; var client = await host.StartOrchestratorAsync(nameof(TestOrchestrations.CallActivity), startArgs, this.output); var status = await client.WaitForCompletionAsync(this.output); // The function checks to see if there is a property called "Foo" which is set to a value // called "Bar" and returns true if this is the case. Otherwise returns false. Assert.Equal(OrchestrationRuntimeStatus.Completed, status?.RuntimeStatus); Assert.True((bool)status?.Output); await host.StopAsync(); } }