public async Task ThenTheWorkflowInstanceWithIdShouldContainContextItems(string instanceId, Table expectedContextItems)
        {
            ITenantedWorkflowInstanceStoreFactory instanceStoreFactory = ContainerBindings.GetServiceProvider(this.featureContext)
                                                                         .GetService <ITenantedWorkflowInstanceStoreFactory>();

            ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(this.featureContext)
                                             .GetService <ITenantProvider>();

            IWorkflowInstanceStore instanceStore = await instanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false);

            WorkflowInstance instance = await WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync(
                () => instanceStore.GetWorkflowInstanceAsync(instanceId)).ConfigureAwait(false);

            Assert.AreEqual(
                expectedContextItems.Rows.Count,
                instance.Context.Count,
                "The number of context items in the workflow instance is different to the number of items in the specified list");

            foreach (TableRow current in expectedContextItems.Rows)
            {
                Assert.IsTrue(
                    instance.Context.TryGetValue(current[0], out string actualValue),
                    $"The instance context does not contain expected item with key '{current[0]}'");

                Assert.AreEqual(current[1], actualValue, $"The instance context does not contain the expected value for key '{current[0]}'");
            }
        }
        public static async Task ClearDownTransientTenantContentStore(FeatureContext context)
        {
            ITenant          transientTenant = TransientTenantManager.GetInstance(context).PrimaryTransientClient;
            IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(context);

            if (transientTenant != null && serviceProvider != null)
            {
                await context.RunAndStoreExceptionsAsync(async() =>
                {
                    ITenantedWorkflowStoreFactory workflowStoreFactory = serviceProvider.GetRequiredService <ITenantedWorkflowStoreFactory>();
                    IWorkflowStore workflowStore = await workflowStoreFactory.GetWorkflowStoreForTenantAsync(transientTenant).ConfigureAwait(false);
                    if (workflowStore is CosmosWorkflowStore cosmosWorkflowStore)
                    {
                        await cosmosWorkflowStore.Container.DeleteContainerAsync().ConfigureAwait(false);
                    }
                }).ConfigureAwait(false);

                await context.RunAndStoreExceptionsAsync(async() =>
                {
                    ITenantedWorkflowInstanceStoreFactory workflowInstanceStoreFactory = serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>();
                    var workflowInstanceStore = (CosmosWorkflowInstanceStore)await workflowInstanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(transientTenant).ConfigureAwait(false);
                    await workflowInstanceStore.Container.DeleteContainerAsync().ConfigureAwait(false);
                }).ConfigureAwait(false);
            }
        }
Beispiel #3
0
        public async Task ThenThereShouldBeANewWorkflowInstanceInTheWorkflowInstanceStore(int expected)
        {
            ITenantedWorkflowInstanceStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>();
            IWorkflowInstanceStore store = await storeFactory.GetWorkflowInstanceStoreForTenantAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false);

            IEnumerable <string> instances = await store.GetMatchingWorkflowInstanceIdsForSubjectsAsync(Array.Empty <string>(), int.MaxValue, 0).ConfigureAwait(false);

            Assert.AreEqual(expected, instances.Count());
        }
Beispiel #4
0
        public async Task TheWorkflowInstanceStoreIsEmpty()
        {
            ITenantedWorkflowInstanceStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>();
            IWorkflowInstanceStore store = await storeFactory.GetWorkflowInstanceStoreForTenantAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false);

            IEnumerable <string> instanceIds = await store.GetMatchingWorkflowInstanceIdsForSubjectsAsync(Array.Empty <string>(), int.MaxValue, 0).ConfigureAwait(false);

            foreach (string current in instanceIds)
            {
                await store.DeleteWorkflowInstanceAsync(current).ConfigureAwait(false);
            }
        }
        public async Task ThenTheWorkflowInstanceWithIdShouldHaveStatus(string instanceId, string expectedStatus)
        {
            ITenantedWorkflowInstanceStoreFactory instanceStoreFactory = ContainerBindings.GetServiceProvider(this.featureContext)
                                                                         .GetService <ITenantedWorkflowInstanceStoreFactory>();

            ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(this.featureContext)
                                             .GetService <ITenantProvider>();

            IWorkflowInstanceStore instanceStore = await instanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false);

            WorkflowInstance instance = await WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync(
                () => instanceStore.GetWorkflowInstanceAsync(instanceId)).ConfigureAwait(false);

            Assert.AreEqual(expectedStatus, instance.Status.ToString());
        }
Beispiel #6
0
        private async Task <WorkflowInstance> GetWorkflowInstance(string id, bool failTestOnException = true)
        {
            await this.EnsureWorkflowInstanceIsNotBeingModified(id).ConfigureAwait(false);

            ITenantedWorkflowInstanceStoreFactory storeFactory = this.serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>();
            IWorkflowInstanceStore store = await storeFactory.GetWorkflowInstanceStoreForTenantAsync(this.transientTenantManager.PrimaryTransientClient).ConfigureAwait(false);

            try
            {
                WorkflowInstance instance = await store.GetWorkflowInstanceAsync(id).ConfigureAwait(false);

                return(instance);
            }
            catch (Exception ex) when(failTestOnException)
            {
                Assert.Fail($"Couldn't find an instance with id {id}: {ex}");
            }

            return(null);
        }
        public static async Task TeardownCosmosDb(FeatureContext featureContext)
        {
            // Pretty nasty hack to get rid of the underlying containers for the stores.
            IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(featureContext);
            ITenantProvider  tenantProvider  = serviceProvider.GetRequiredService <ITenantProvider>();

            ITenantedWorkflowStoreFactory workflowStoreFactory = serviceProvider.GetRequiredService <ITenantedWorkflowStoreFactory>();
            var workflowStore = (CosmosWorkflowStore)await workflowStoreFactory.GetWorkflowStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false);

            await featureContext.RunAndStoreExceptionsAsync(
                () => workflowStore.Container.DeleteContainerAsync()).ConfigureAwait(false);

            ITenantedWorkflowInstanceStoreFactory workflowInstanceStoreFactory = serviceProvider.GetRequiredService <ITenantedWorkflowInstanceStoreFactory>();
            var workflowInstanceStore = (CosmosWorkflowInstanceStore)await workflowInstanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false);

            await featureContext.RunAndStoreExceptionsAsync(
                () => workflowInstanceStore.Container.DeleteContainerAsync()).ConfigureAwait(false);

            await featureContext.RunAndStoreExceptionsAsync(
                () => featureContext.Get <Container>(TestDocumentsRepository).DeleteContainerAsync()).ConfigureAwait(false);
        }
        public async Task ThenTheWorkflowInstanceWithIdShouldBeInTheStateCalled(string instanceId, string stateName)
        {
            ITenantedWorkflowStoreFactory storeFactory = ContainerBindings.GetServiceProvider(this.featureContext)
                                                         .GetService <ITenantedWorkflowStoreFactory>();
            ITenantedWorkflowInstanceStoreFactory instanceStoreFactory = ContainerBindings.GetServiceProvider(this.featureContext)
                                                                         .GetService <ITenantedWorkflowInstanceStoreFactory>();

            ITenantProvider tenantProvider = ContainerBindings.GetServiceProvider(this.featureContext)
                                             .GetService <ITenantProvider>();

            IWorkflowStore store = await storeFactory.GetWorkflowStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false);

            IWorkflowInstanceStore instanceStore = await instanceStoreFactory.GetWorkflowInstanceStoreForTenantAsync(tenantProvider.Root).ConfigureAwait(false);

            WorkflowInstance instance = await WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync(
                () => instanceStore.GetWorkflowInstanceAsync(instanceId)).ConfigureAwait(false);

            Workflow workflow = await WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync(
                () => store.GetWorkflowAsync(instance.WorkflowId)).ConfigureAwait(false);

            WorkflowState currentState = workflow.GetState(instance.StateId);

            Assert.AreEqual(stateName, currentState.DisplayName);
        }