Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TenantedSqlWorkflowInstanceStoreFactory"/> class.
 /// </summary>
 /// <param name="serializerSettingsProvider">The JSON serializer settings provider.</param>
 /// <param name="connectionSource">
 /// The <see cref="ISqlConnectionFromDynamicConfiguration"/> that will be used to create
 /// underlying <see cref="SqlConnection"/> instances for the content stores.
 /// </param>
 /// <param name="configurationKey">
 /// The tenant properties configuration key in which to find settings.
 /// </param>
 public TenantedSqlWorkflowInstanceStoreFactory(
     IJsonSerializerSettingsProvider serializerSettingsProvider,
     ISqlConnectionFromDynamicConfiguration connectionSource,
     string configurationKey)
 {
     this.serializerSettingsProvider = serializerSettingsProvider;
     this.connectionSource           = connectionSource;
     this.configurationKey           = configurationKey;
 }
        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");