/// <summary> /// Creates the workflow. /// </summary> /// <param name="id">Id to use for this workflow.</param> /// <param name="externalServiceUrl">External URL to invoke.</param> /// <param name="serviceIdentityTokenSource">The token source to use when authenticating to external services.</param> /// <param name="serializerSettingsProvider">The serialization settings provider.</param> /// <returns>The workflow definition.</returns> public static Workflow Create( string id, string externalServiceUrl, IServiceIdentityAccessTokenSource serviceIdentityTokenSource, IJsonSerializerSettingsProvider serializerSettingsProvider) { var workflow = new Workflow( id, "External Condition workflow", "Simple workflow using an external condition"); WorkflowState waitingToRun = workflow.CreateState(displayName: "Waiting to run"); WorkflowState done = workflow.CreateState(displayName: "Done"); workflow.SetInitialState(waitingToRun); WorkflowTransition transition = waitingToRun.CreateTransition(done); var condition = new InvokeExternalServiceCondition(serviceIdentityTokenSource, serializerSettingsProvider) { Id = Guid.NewGuid().ToString(), HttpMethod = HttpMethod.Post, AuthenticateWithManagedServiceIdentity = true, MsiAuthenticationResource = "foobar", ExternalUrl = externalServiceUrl, ContextItemsToInclude = new[] { "include1", "include2" }, }; transition.Conditions.Add(condition); return(workflow); }
public async Task GivenGivenIHaveCreatedAndPersistedAWorkflowContainingAnExternalConditionWithIdAsync(string workflowId) { ExternalServiceBindings.ExternalService externalService = ExternalServiceBindings.GetService(this.scenarioContext); IServiceIdentityAccessTokenSource serviceIdentityTokenSource = ContainerBindings.GetServiceProvider(this.featureContext).GetRequiredService <IServiceIdentityAccessTokenSource>(); IJsonSerializerSettingsProvider serializerSettingsProvider = ContainerBindings.GetServiceProvider(this.featureContext).GetRequiredService <IJsonSerializerSettingsProvider>(); Workflow workflow = ExternalConditionWorkflowFactory.Create( workflowId, externalService.TestUrl.ToString(), serviceIdentityTokenSource, serializerSettingsProvider); this.condition = workflow.GetInitialState().Transitions .Single() .Conditions .OfType <InvokeExternalServiceCondition>() .Single(); ITenantedWorkflowStoreFactory storeFactory = ContainerBindings.GetServiceProvider(this.featureContext) .GetService <ITenantedWorkflowStoreFactory>(); ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(this.featureContext).GetRequiredService <ITenantProvider>(); IWorkflowStore store = await storeFactory.GetWorkflowStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false); await WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync(async() => { try { Workflow oldWorkflow = await store.GetWorkflowAsync(workflowId).ConfigureAwait(false); workflow.ETag = oldWorkflow.ETag; } catch (WorkflowNotFoundException) { // Don't care if there is no old workflow. } await store.UpsertWorkflowAsync(workflow).ConfigureAwait(false); }).ConfigureAwait(false); }