Exemple #1
0
        // Only 1 public constructor is allowed for test fixture.
        internal SqlDataStoreTestsFixture(string databaseName)
        {
            EnsureArg.IsNotNullOrEmpty(databaseName, nameof(databaseName));
            _databaseName = databaseName;
            string initialConnectionString = Environment.GetEnvironmentVariable("SqlServer:ConnectionString") ?? LocalConnectionString;

            _masterConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = "master"
            }.ToString();
            TestConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = _databaseName
            }.ToString();

            var config = new SqlServerDataStoreConfiguration
            {
                ConnectionString = TestConnectionString,
                Initialize       = true,
                SchemaOptions    = new SqlServerSchemaOptions
                {
                    AutomaticUpdatesEnabled = true,
                },
            };

            var scriptProvider = new ScriptProvider <SchemaVersion>();

            var baseScriptProvider = new BaseScriptProvider();

            var mediator = Substitute.For <IMediator>();

            var sqlConnectionStringProvider = new DefaultSqlConnectionStringProvider(config);

            var sqlConnectionFactory = new DefaultSqlConnectionFactory(sqlConnectionStringProvider);

            var schemaManagerDataStore = new SchemaManagerDataStore(sqlConnectionFactory);

            var schemaUpgradeRunner = new SchemaUpgradeRunner(scriptProvider, baseScriptProvider, mediator, NullLogger <SchemaUpgradeRunner> .Instance, sqlConnectionFactory, schemaManagerDataStore);

            var schemaInformation = new SchemaInformation(SchemaVersionConstants.Min, SchemaVersionConstants.Max);

            _schemaInitializer = new SchemaInitializer(config, schemaUpgradeRunner, schemaInformation, sqlConnectionFactory, sqlConnectionStringProvider, NullLogger <SchemaInitializer> .Instance);

            SqlTransactionHandler = new SqlTransactionHandler();

            SqlConnectionWrapperFactory = new SqlConnectionWrapperFactory(SqlTransactionHandler, new SqlCommandWrapperFactory(), sqlConnectionFactory);

            SqlIndexDataStoreFactory = new SqlIndexDataStoreFactory(
                schemaInformation,
                new[] { new SqlIndexDataStoreV1(SqlConnectionWrapperFactory), new SqlIndexDataStoreV2(SqlConnectionWrapperFactory) });

            InstanceStore = new SqlInstanceStore(SqlConnectionWrapperFactory);

            ExtendedQueryTagStore = new SqlExtendedQueryTagStore(SqlConnectionWrapperFactory, schemaInformation, NullLogger <SqlExtendedQueryTagStore> .Instance);

            TestHelper = new SqlIndexDataStoreTestHelper(TestConnectionString);
        }
        public SqlDataStoreTestsFixture()
        {
            string initialConnectionString = Environment.GetEnvironmentVariable("SqlServer:ConnectionString") ?? LocalConnectionString;

            _databaseName           = $"DICOMINTEGRATIONTEST_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}_{BigInteger.Abs(new BigInteger(Guid.NewGuid().ToByteArray()))}";
            _masterConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = "master"
            }.ToString();
            TestConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = _databaseName
            }.ToString();

            var config = new SqlServerDataStoreConfiguration
            {
                ConnectionString = TestConnectionString,
                Initialize       = true,
                SchemaOptions    = new SqlServerSchemaOptions
                {
                    AutomaticUpdatesEnabled = true,
                },
            };

            var scriptProvider = new ScriptProvider <SchemaVersion>();

            var baseScriptProvider = new BaseScriptProvider();

            var mediator = Substitute.For <IMediator>();

            var sqlConnectionStringProvider = new DefaultSqlConnectionStringProvider(config);

            var sqlConnectionFactory = new DefaultSqlConnectionFactory(sqlConnectionStringProvider);

            var schemaManagerDataStore = new SchemaManagerDataStore(sqlConnectionFactory);

            var schemaUpgradeRunner = new SchemaUpgradeRunner(scriptProvider, baseScriptProvider, mediator, NullLogger <SchemaUpgradeRunner> .Instance, sqlConnectionFactory, schemaManagerDataStore);

            var schemaInformation = new SchemaInformation((int)SchemaVersion.V1, (int)SchemaVersion.V1);

            _schemaInitializer = new SchemaInitializer(config, schemaUpgradeRunner, schemaInformation, sqlConnectionFactory, sqlConnectionStringProvider, NullLogger <SchemaInitializer> .Instance);

            var dicomSqlIndexSchema = new SqlIndexSchema(schemaInformation, NullLogger <SqlIndexSchema> .Instance);

            SqlTransactionHandler = new SqlTransactionHandler();

            SqlConnectionWrapperFactory = new SqlConnectionWrapperFactory(SqlTransactionHandler, new SqlCommandWrapperFactory(), sqlConnectionFactory);

            IndexDataStore = new SqlIndexDataStore(
                dicomSqlIndexSchema,
                SqlConnectionWrapperFactory);

            InstanceStore = new SqlInstanceStore(SqlConnectionWrapperFactory);

            TestHelper = new SqlIndexDataStoreTestHelper(TestConnectionString);
        }
        internal SqlDataStoreTestsFixture(string databaseName, SchemaInformation schemaInformation)
        {
            DatabaseName      = EnsureArg.IsNotNullOrEmpty(databaseName, nameof(databaseName));
            SchemaInformation = EnsureArg.IsNotNull(schemaInformation, nameof(schemaInformation));

            IConfiguration environment = new ConfigurationBuilder()
                                         .AddEnvironmentVariables()
                                         .Build();

            string initialConnectionString = environment["SqlServer:ConnectionString"] ?? LocalConnectionString;

            _masterConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = "master"
            }.ToString();
            TestConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = DatabaseName
            }.ToString();

            var config = new SqlServerDataStoreConfiguration
            {
                ConnectionString = TestConnectionString,
                Initialize       = true,
                SchemaOptions    = new SqlServerSchemaOptions
                {
                    AutomaticUpdatesEnabled = true,
                },
            };

            IOptions <SqlServerDataStoreConfiguration> configOptions = Options.Create(config);

            var scriptProvider = new ScriptProvider <SchemaVersion>();

            var baseScriptProvider = new BaseScriptProvider();

            var mediator = Substitute.For <IMediator>();

            var sqlConnectionStringProvider = new DefaultSqlConnectionStringProvider(configOptions);

            var sqlConnectionFactory = new DefaultSqlConnectionFactory(sqlConnectionStringProvider);

            var schemaManagerDataStore = new SchemaManagerDataStore(sqlConnectionFactory, configOptions, NullLogger <SchemaManagerDataStore> .Instance);

            SchemaUpgradeRunner = new SchemaUpgradeRunner(scriptProvider, baseScriptProvider, NullLogger <SchemaUpgradeRunner> .Instance, sqlConnectionFactory, schemaManagerDataStore);

            _schemaInitializer = new SchemaInitializer(configOptions, schemaManagerDataStore, SchemaUpgradeRunner, SchemaInformation, sqlConnectionFactory, sqlConnectionStringProvider, mediator, NullLogger <SchemaInitializer> .Instance);

            SqlTransactionHandler = new SqlTransactionHandler();

            SqlConnectionWrapperFactory = new SqlConnectionWrapperFactory(SqlTransactionHandler, new SqlCommandWrapperFactory(), sqlConnectionFactory);

            var schemaResolver = new PassthroughSchemaVersionResolver(SchemaInformation);

            IndexDataStore = new SqlIndexDataStore(new VersionedCache <ISqlIndexDataStore>(
                                                       schemaResolver,
                                                       new[]
            {
                new SqlIndexDataStoreV1(SqlConnectionWrapperFactory),
                new SqlIndexDataStoreV2(SqlConnectionWrapperFactory),
                new SqlIndexDataStoreV3(SqlConnectionWrapperFactory),
                new SqlIndexDataStoreV4(SqlConnectionWrapperFactory),
                new SqlIndexDataStoreV5(SqlConnectionWrapperFactory),
                new SqlIndexDataStoreV6(SqlConnectionWrapperFactory),
            }));

            InstanceStore = new SqlInstanceStore(new VersionedCache <ISqlInstanceStore>(
                                                     schemaResolver,
                                                     new[]
            {
                new SqlInstanceStoreV1(SqlConnectionWrapperFactory),
                new SqlInstanceStoreV4(SqlConnectionWrapperFactory),
                new SqlInstanceStoreV6(SqlConnectionWrapperFactory),
            }));

            PartitionStore = new SqlPartitionStore(new VersionedCache <ISqlPartitionStore>(
                                                       schemaResolver,
                                                       new[]
            {
                new SqlPartitionStoreV6(SqlConnectionWrapperFactory),
            }));

            ExtendedQueryTagStore = new SqlExtendedQueryTagStore(new VersionedCache <ISqlExtendedQueryTagStore>(
                                                                     schemaResolver,
                                                                     new[]
            {
                new SqlExtendedQueryTagStoreV1(),
                new SqlExtendedQueryTagStoreV2(SqlConnectionWrapperFactory, NullLogger <SqlExtendedQueryTagStoreV2> .Instance),
                new SqlExtendedQueryTagStoreV4(SqlConnectionWrapperFactory, NullLogger <SqlExtendedQueryTagStoreV4> .Instance),
                new SqlExtendedQueryTagStoreV8(SqlConnectionWrapperFactory, NullLogger <SqlExtendedQueryTagStoreV8> .Instance),
            }));

            ExtendedQueryTagErrorStore = new SqlExtendedQueryTagErrorStore(new VersionedCache <ISqlExtendedQueryTagErrorStore>(
                                                                               schemaResolver,
                                                                               new[]
            {
                new SqlExtendedQueryTagErrorStoreV1(),
                new SqlExtendedQueryTagErrorStoreV4(SqlConnectionWrapperFactory, NullLogger <SqlExtendedQueryTagErrorStoreV4> .Instance),
                new SqlExtendedQueryTagErrorStoreV6(SqlConnectionWrapperFactory, NullLogger <SqlExtendedQueryTagErrorStoreV6> .Instance),
            }));
            IndexDataStoreTestHelper             = new SqlIndexDataStoreTestHelper(TestConnectionString);
            ExtendedQueryTagStoreTestHelper      = new ExtendedQueryTagStoreTestHelper(TestConnectionString);
            ExtendedQueryTagErrorStoreTestHelper = new ExtendedQueryTagErrorStoreTestHelper(TestConnectionString);
        }