public static void SetupCosmosDbRepository(FeatureContext featureContext)
        {
            IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(featureContext);
            ICosmosContainerSourceWithTenantLegacyTransition factory = serviceProvider.GetRequiredService <ICosmosContainerSourceWithTenantLegacyTransition>();
            ICosmosOptionsFactory optionsFactory = serviceProvider.GetRequiredService <ICosmosOptionsFactory>();
            ITenantProvider       tenantProvider = serviceProvider.GetRequiredService <ITenantProvider>();
            IConfiguration        configuration  = serviceProvider.GetRequiredService <IConfiguration>();

            ITenant rootTenant = tenantProvider.Root;

            LegacyV2CosmosContainerConfiguration cosmosConfig =
                configuration.GetSection("TestCosmosConfiguration").Get <LegacyV2CosmosContainerConfiguration>()
                ?? new LegacyV2CosmosContainerConfiguration();

            cosmosConfig.DatabaseName          = "endjinspecssharedthroughput";
            cosmosConfig.DisableTenantIdPrefix = true;

            tenantProvider.Root.UpdateProperties(data => data.Append(new KeyValuePair <string, object>(
                                                                         $"StorageConfiguration__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowStoreLogicalDatabaseName}__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowDefinitionStoreLogicalContainerName}",
                                                                         cosmosConfig)));

            tenantProvider.Root.UpdateProperties(data => data.Append(new KeyValuePair <string, object>(
                                                                         $"StorageConfiguration__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowStoreLogicalDatabaseName}__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowInstanceStoreLogicalContainerName}",
                                                                         cosmosConfig)));

            tenantProvider.Root.UpdateProperties(data => data.Append(new KeyValuePair <string, object>(
                                                                         "StorageConfiguration__workflow__testdocuments",
                                                                         cosmosConfig)));

            Newtonsoft.Json.JsonSerializerSettings jsonSettings = serviceProvider.GetRequiredService <IJsonSerializerSettingsProvider>().Instance;
            Container testDocumentsRepository = WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync(
                async() => await factory.GetContainerForTenantAsync(
                    rootTenant,
                    "StorageConfiguration__workflow__testdocuments",
                    "NotUsed",
                    "workflow",
                    "testdocuments",
                    "/id",
                    cosmosClientOptions: optionsFactory.CreateCosmosClientOptions())).Result;

            featureContext.Set(testDocumentsRepository, TestDocumentsRepository);
        }
        public static void SetupDatabases(FeatureContext featureContext)
        {
            IServiceProvider serviceProvider = ContainerBindings.GetServiceProvider(featureContext);
            ISqlConnectionFromDynamicConfiguration           sqlConnectionFactory = serviceProvider.GetRequiredService <ISqlConnectionFromDynamicConfiguration>();
            ICosmosContainerSourceWithTenantLegacyTransition factory = serviceProvider.GetRequiredService <ICosmosContainerSourceWithTenantLegacyTransition>();
            ICosmosOptionsFactory optionsFactory = serviceProvider.GetRequiredService <ICosmosOptionsFactory>();
            ITenantProvider       tenantProvider = serviceProvider.GetRequiredService <ITenantProvider>();
            IConfiguration        configuration  = serviceProvider.GetRequiredService <IConfiguration>();

            string containerBase = Guid.NewGuid().ToString();
            string databaseName  = $"workflow-{containerBase}";

            SqlDatabaseConfiguration sqlConfig = new()
            {
                ConnectionStringPlainText = $"Server=(localdb)\\mssqllocaldb;Initial Catalog={databaseName};Trusted_Connection=True;MultipleActiveResultSets=true",
            };

            tenantProvider.Root.UpdateProperties(data => data.AddSqlDatabaseConfiguration(
                                                     TenantedSqlWorkflowStoreServiceCollectionExtensions.WorkflowConnectionKey,
                                                     sqlConfig));

            LegacyV2CosmosContainerConfiguration cosmosConfig =
                configuration.GetSection("TestCosmosConfiguration").Get <LegacyV2CosmosContainerConfiguration>()
                ?? new LegacyV2CosmosContainerConfiguration();

            cosmosConfig.DatabaseName          = "endjinspecssharedthroughput";
            cosmosConfig.DisableTenantIdPrefix = true;

            // Configuring with V2-style configuration because for now, the application uses the
            // ICosmosContainerSourceWithTenantLegacyTransition in the mode where all the tenant
            // configuration remains in V2 mode.
            tenantProvider.Root.UpdateProperties(data => data.Append(new KeyValuePair <string, object>(
                                                                         $"StorageConfiguration__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowStoreLogicalDatabaseName}__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowDefinitionStoreLogicalContainerName}",
                                                                         cosmosConfig)));

            tenantProvider.Root.UpdateProperties(data => data.Append(new KeyValuePair <string, object>(
                                                                         $"StorageConfiguration__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowStoreLogicalDatabaseName}__{TenantedCosmosWorkflowStoreServiceCollectionExtensions.WorkflowInstanceStoreLogicalContainerName}",
                                                                         cosmosConfig)));

            tenantProvider.Root.UpdateProperties(data => data.Append(new KeyValuePair <string, object>(
                                                                         "StorageConfiguration__workflow__testdocuments",
                                                                         cosmosConfig)));

            // This is required by the various bits of the test that work with the "data catalog".
            Container testDocumentsRepository = WorkflowRetryHelper.ExecuteWithStandardTestRetryRulesAsync(
                async() => await factory.GetContainerForTenantAsync(
                    tenantProvider.Root,
                    "StorageConfiguration__workflow__testdocuments",
                    "NotUsed",
                    "workflow",
                    "testdocuments",
                    "/id",
                    cosmosClientOptions: optionsFactory.CreateCosmosClientOptions())).Result;

            featureContext.Set(testDocumentsRepository, TestDocumentsRepository);

            // And now, deploy the sql server for this instance.
#if DEBUG
            const string BUILD = "debug";
#else
            const string BUILD = "release";
#endif

            SqlHelpers.SetupDatabaseFromDacPac(sqlConfig.ConnectionStringPlainText, databaseName, @$ "..\..\..\..\Marain.Workflow.Storage.Sql.Database\bin\{BUILD}\Marain.Workflow.Storage.Sql.Database.dacpac");