Exemple #1
0
        public async Task ScriptProviderShouldReturnAllFiles()
        {
            ScriptProvider sp      = new ScriptProvider();
            var            scripts = await sp.GetScripts("C:\\Projects\\Testing\\Database\\Programmability", Depth.AllChilds);

            Debug.WriteLine($"Number of scripts: {scripts.Count()}");
        }
Exemple #2
0
        public ResponseModel <ScriptResponse> UpdateScript(AddScriptRequest objupdateRequest)
        {
            try
            {
                ScriptProvider       objScriptProvider = new ScriptProvider(_context);
                Script               updatedScript     = objScriptProvider.UpdateScript(objupdateRequest.ScriptDetails);
                List <ScriptContent> scriptContents    = objScriptProvider.UpdateScriptContents(objupdateRequest.ScriptContents, objupdateRequest.ScriptDetails.ScriptId);
                ScriptResponse       objScriptResponse = new ScriptResponse
                {
                    Script         = updatedScript,
                    ScriptContents = scriptContents
                };


                ResponseModel <ScriptResponse> objResponseModel = new ResponseModel <ScriptResponse>
                {
                    Message        = "Successfully Updated",
                    StatusCode     = 1,
                    ResponseObject = objScriptResponse
                };
                return(objResponseModel);
            }
            catch (Exception ex)
            {
                ResponseModel <ScriptResponse> objResponseModel = new ResponseModel <ScriptResponse>
                {
                    Message    = ex.Message,
                    StatusCode = 0
                };
                return(objResponseModel);
            }
        }
Exemple #3
0
        public ResponseModel <Script> GetScript(GetById objGetById)
        {
            try
            {
                ScriptProvider objScriptProvider = new ScriptProvider(_context);
                Script         objscript         = objScriptProvider.GetScriptById(objGetById.Id);


                ResponseModel <Script> objResponseModel = new ResponseModel <Script>
                {
                    Message        = "Successfully Retrieved",
                    StatusCode     = 1,
                    ResponseObject = objscript
                };
                return(objResponseModel);
            }
            catch (Exception ex)
            {
                ResponseModel <Script> objResponseModel = new ResponseModel <Script>
                {
                    Message    = ex.Message,
                    StatusCode = 0
                };
                return(objResponseModel);
            }
        }
Exemple #4
0
        public ResponseModel <Script> AddScript(Script objScript)
        {
            try
            {
                ScriptProvider objScriptProvider = new ScriptProvider(_context);
                Script         addedScript       = objScriptProvider.AddScript(objScript);
                //List<ScriptContent> objScriptContents = objScriptProvider.AddScriptContent(objAddScript.ScriptContents, addedScript.ScriptId);

                //ScriptResponse scriptResponse = new ScriptResponse
                //{
                //    Script = addedScript,
                //    ScriptContents = objScriptContents,
                //};
                ResponseModel <Script> objResponseModel = new ResponseModel <Script>
                {
                    Message        = "Successfully Added",
                    StatusCode     = 1,
                    ResponseObject = addedScript
                };
                return(objResponseModel);
            }
            catch (Exception ex)
            {
                ResponseModel <Script> objResponseModel = new ResponseModel <Script>
                {
                    Message    = ex.Message,
                    StatusCode = 0
                };
                return(objResponseModel);
            }
        }
Exemple #5
0
        public FileContentResult SqlScript(int id)
        {
            _logger.LogInformation($"Attempting to get script for schema version: {id}");
            string fileName = $"{id}.sql";

            return(File(ScriptProvider.GetMigrationScriptAsBytes(id), "application/json", fileName));
        }
Exemple #6
0
 public override void Load()
 {
     ContentList.Clear();
     if (ScriptProvider != null)
     {
         ScriptProvider.LoadData(this);
     }
 }
Exemple #7
0
        public void ShouldLogAnErrorWhenUpgradeFails()
        {
            var ex = new InvalidOperationException();

            ScriptProvider.GetScripts(Arg.Any <Func <IDbConnection> >()).Returns(provider => { throw ex; });
            DbUpgrader.PerformUpgrade();
            Log.Received().WriteError("Upgrade failed due to an unexpected exception:\r\n{0}", ex.ToString());
        }
Exemple #8
0
        public async Task Configure()
        {
            InitializeDatabase();
            CachedData.Initialize();
            await ScriptProvider.Initialize();

            await LootProvider.Initialize();
        }
Exemple #9
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);
        }
Exemple #10
0
        protected virtual async Task <OracleCommand> CreateWriteEventsCommand(IReadOnlyCollection <IUnpersistedRawStreamEvent> events)
        {
            var commandText = await ScriptProvider.GetInitializationScriptAsync(SchemaSettings);

            var command = new OracleCommand(commandText, CreateConnection());

            // TODO: Add parameters
            return(command);
        }
        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);
        }
        private SchemaInitializer CreateSchemaInitializer(string testConnectionString)
        {
            var config = new SqlServerDataStoreConfiguration {
                ConnectionString = testConnectionString, Initialize = true
            };
            var schemaInformation   = new SchemaInformation((int)SchemaVersion.V1, (int)SchemaVersion.V2);
            var scriptProvider      = new ScriptProvider <SchemaVersion>();
            var schemaUpgradeRunner = new SchemaUpgradeRunner(scriptProvider, config, NullLogger <SchemaUpgradeRunner> .Instance);

            return(new SchemaInitializer(config, schemaUpgradeRunner, schemaInformation, NullLogger <SchemaInitializer> .Instance));
        }
Exemple #13
0
        public void ShouldReturnFailedResult()
        {
            var ex = new InvalidOperationException();

            ScriptProvider.GetScripts(Arg.Any <Func <IDbConnection> >()).Returns(provider => { throw ex; });
            var result = DbUpgrader.PerformUpgrade();

            Assert.That(result.Successful == false);
            Assert.That(result.Scripts.Count() == 0);
            Assert.That(result.Error == ex);
        }
        public override void BeforeEach()
        {
            base.BeforeEach();

            AllScripts = new List <SqlScript>
            {
                new SqlScript("0001.sql", "CREATE TABLE $sometable$ (Id int)")
            };

            ScriptProvider.GetScripts(Arg.Any <Func <IDbConnection> >()).Returns(AllScripts);
            VersionTracker.GetExecutedScripts().Returns(new string[0]);
        }
Exemple #15
0
        public override void BeforeEach()
        {
            base.BeforeEach();
            AllScripts = new List <SqlScript>
            {
                new SqlScript("0001.southwind.sql", "--LITTLE BOBBY DROP TABLES WAS HERE."),
                new SqlScript("0002.southwind.sql", "CREATE TABLE USERS --AGAIN")
            };

            ScriptProvider.GetScripts(Arg.Any <Func <IDbConnection> >()).Returns(AllScripts);
            VersionTracker.GetExecutedScripts().Returns(new[] { "0001.southwind.sql" });
        }
Exemple #16
0
        public override void BeforeEach()
        {
            base.BeforeEach();

            AllScripts = new List <SqlScript>
            {
                new SqlScript("0001.sql", ""),
                new SqlScript("0004.sql", ""),
                new SqlScript("0002.sql", "")
            };

            ScriptProvider.GetScripts(Arg.Any <Func <IDbConnection> >()).Returns(AllScripts);
            VersionTracker.GetExecutedScripts().Returns(new string[] {});
        }
Exemple #17
0
        private SchemaInitializer CreateSchemaInitializer(string testConnectionString)
        {
            var schemaOptions = new SqlServerSchemaOptions {
                AutomaticUpdatesEnabled = true
            };
            var config = new SqlServerDataStoreConfiguration {
                ConnectionString = testConnectionString, Initialize = true, SchemaOptions = schemaOptions
            };
            var schemaInformation   = new SchemaInformation(SchemaVersionConstants.Min, SchemaVersionConstants.Max);
            var scriptProvider      = new ScriptProvider <SchemaVersion>();
            var baseScriptProvider  = new BaseScriptProvider();
            var mediator            = Substitute.For <IMediator>();
            var schemaUpgradeRunner = new SchemaUpgradeRunner(scriptProvider, baseScriptProvider, config, mediator, NullLogger <SchemaUpgradeRunner> .Instance);

            return(new SchemaInitializer(config, schemaUpgradeRunner, schemaInformation, NullLogger <SchemaInitializer> .Instance));
        }
Exemple #18
0
        public ResponseModel ApprovalRequest(ApprovalRequest objApprovalRequest)
        {
            try
            {
                switch (objApprovalRequest.Type)
                {
                case 0:
                    ScenarioProvider objScenarioProvider = new ScenarioProvider(_context);
                    objScenarioProvider.ApproveScenario(objApprovalRequest);
                    break;

                case 1:
                    ScriptProvider objScriptProvider = new ScriptProvider(_context);
                    objScriptProvider.ApproveScript(objApprovalRequest);
                    break;

                case 2:
                    DeliveryProvider objDeliveryProvider = new DeliveryProvider(_context);
                    objDeliveryProvider.ApproveDelivery(objApprovalRequest);
                    break;
                }
                ResponseModel objResponseModel = new ResponseModel
                {
                    StatusCode = 1,
                    Message    = "Action Performed Successfully"
                };
                return(objResponseModel);
            }
            catch (Exception ex)
            {
                ResponseModel objResponseModel = new ResponseModel
                {
                    StatusCode = 0,
                    Message    = ex.Message
                };
                return(objResponseModel);
            }
        }
Exemple #19
0
 public ResponseModel DeleteScript(Script objScript)
 {
     try
     {
         ScriptProvider objScriptProvider = new ScriptProvider(_context);
         objScriptProvider.DeleteScript(objScript);
         ResponseModel objResponseModel = new ResponseModel
         {
             Message    = "Successfully Deleted",
             StatusCode = 1
         };
         return(objResponseModel);
     }
     catch (Exception ex)
     {
         ResponseModel objResponseModel = new ResponseModel
         {
             Message    = ex.Message,
             StatusCode = 0
         };
         return(objResponseModel);
     }
 }
Exemple #20
0
 public ResponseModel <ScriptReview> GetScriptReview(GetById objGetById)
 {
     try
     {
         ScriptProvider objScriptProvider = new ScriptProvider(_context);
         ScriptReview   objScriptReview   = objScriptProvider.GetScriptReview(objGetById.Id);
         ResponseModel <ScriptReview> objResponseModel = new ResponseModel <ScriptReview>
         {
             StatusCode     = 1,
             Message        = "Success",
             ResponseObject = objScriptReview,
         };
         return(objResponseModel);
     }
     catch (Exception ex)
     {
         ResponseModel <ScriptReview> objResponseModel = new ResponseModel <ScriptReview>
         {
             StatusCode = 0,
             Message    = ex.Message,
         };
         return(objResponseModel);
     }
 }
Exemple #21
0
        public SqlServerFhirStorageTestsFixture()
        {
            var initialConnectionString = Environment.GetEnvironmentVariable("SqlServer:ConnectionString") ?? LocalConnectionString;

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

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

            var schemaInformation  = new SchemaInformation(SchemaVersionConstants.Min, SchemaVersionConstants.Max);
            var scriptProvider     = new ScriptProvider <SchemaVersion>();
            var baseScriptProvider = new BaseScriptProvider();
            var mediator           = Substitute.For <IMediator>();

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

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

            var searchParameterDefinitionManager = new SearchParameterDefinitionManager(ModelInfoProvider.Instance);

            _filebasedSearchParameterStatusDataStore = new FilebasedSearchParameterStatusDataStore(searchParameterDefinitionManager, ModelInfoProvider.Instance);

            var securityConfiguration = new SecurityConfiguration {
                PrincipalClaims = { "oid" }
            };

            var sqlServerFhirModel = new SqlServerFhirModel(
                config,
                schemaInformation,
                searchParameterDefinitionManager,
                () => _filebasedSearchParameterStatusDataStore,
                Options.Create(securityConfiguration),
                NullLogger <SqlServerFhirModel> .Instance);

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSqlServerTableRowParameterGenerators();
            serviceCollection.AddSingleton(sqlServerFhirModel);

            ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

            var upsertResourceTvpGenerator     = serviceProvider.GetRequiredService <VLatest.UpsertResourceTvpGenerator <ResourceMetadata> >();
            var upsertSearchParamsTvpGenerator = serviceProvider.GetRequiredService <VLatest.UpsertSearchParamsTvpGenerator <List <ResourceSearchParameterStatus> > >();

            var searchParameterToSearchValueTypeMap = new SearchParameterToSearchValueTypeMap(new SupportedSearchParameterDefinitionManager(searchParameterDefinitionManager));

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

            SqlServerSearchParameterStatusDataStore = new SqlServerSearchParameterStatusDataStore(
                () => SqlConnectionWrapperFactory.CreateMockScope(),
                upsertSearchParamsTvpGenerator,
                () => _filebasedSearchParameterStatusDataStore,
                schemaInformation);

            _fhirDataStore = new SqlServerFhirDataStore(config, sqlServerFhirModel, searchParameterToSearchValueTypeMap, upsertResourceTvpGenerator, Options.Create(new CoreFeatureConfiguration()), SqlConnectionWrapperFactory, NullLogger <SqlServerFhirDataStore> .Instance, schemaInformation);

            _fhirOperationDataStore = new SqlServerFhirOperationDataStore(SqlConnectionWrapperFactory, NullLogger <SqlServerFhirOperationDataStore> .Instance);

            _testHelper = new SqlServerFhirStorageTestHelper(initialConnectionString, MasterDatabaseName, searchParameterDefinitionManager, sqlServerFhirModel, sqlConnectionFactory);
        }
Exemple #22
0
        private async Task <(SqlServerFhirStorageTestHelper testHelper, SchemaUpgradeRunner upgradeRunner)> SetupTestHelperAndCreateDatabase(string databaseName, int maxSchemaVersion, bool forceIncrementalSchemaUpgrade)
        {
            var initialConnectionString = Environment.GetEnvironmentVariable("SqlServer:ConnectionString") ?? LocalConnectionString;

            var searchService = Substitute.For <ISearchService>();
            ISearchParameterDefinitionManager       defManager  = new SearchParameterDefinitionManager(ModelInfoProvider.Instance, Substitute.For <IMediator>(), () => searchService.CreateMockScope(), NullLogger <SearchParameterDefinitionManager> .Instance);
            FilebasedSearchParameterStatusDataStore statusStore = new FilebasedSearchParameterStatusDataStore(defManager, ModelInfoProvider.Instance);

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

            var connectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = databaseName
            }.ToString();

            var schemaOptions = new SqlServerSchemaOptions {
                AutomaticUpdatesEnabled = true
            };
            var config = new SqlServerDataStoreConfiguration {
                ConnectionString = connectionString, Initialize = true, SchemaOptions = schemaOptions
            };
            var sqlConnectionStringProvider = new DefaultSqlConnectionStringProvider(config);
            var securityConfiguration       = new SecurityConfiguration {
                PrincipalClaims = { "oid" }
            };

            SqlServerFhirModel sqlServerFhirModel = new SqlServerFhirModel(
                schemaInformation,
                defManager,
                () => statusStore,
                Options.Create(securityConfiguration),
                sqlConnectionStringProvider,
                Substitute.For <IMediator>(),
                NullLogger <SqlServerFhirModel> .Instance);

            var sqlConnectionFactory = new DefaultSqlConnectionFactory(sqlConnectionStringProvider);

            var testHelper = new SqlServerFhirStorageTestHelper(
                initialConnectionString,
                MasterDatabaseName,
                sqlServerFhirModel,
                sqlConnectionFactory);

            var scriptProvider     = new ScriptProvider <SchemaVersion>();
            var baseScriptProvider = new BaseScriptProvider();
            var mediator           = Substitute.For <IMediator>();

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

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

            await testHelper.CreateAndInitializeDatabase(
                databaseName,
                maxSchemaVersion,
                forceIncrementalSchemaUpgrade,
                schemaInitializer);

            return(testHelper, schemaUpgradeRunner);
        }
Exemple #23
0
        internal SqlServerFhirStorageTestsFixture(int maximumSupportedSchemaVersion, string databaseName, IOptions <CoreFeatureConfiguration> coreFeatures = null)
        {
            var initialConnectionString = Environment.GetEnvironmentVariable("SqlServer:ConnectionString") ?? LocalConnectionString;

            _maximumSupportedSchemaVersion = maximumSupportedSchemaVersion;
            _databaseName        = databaseName;
            TestConnectionString = new SqlConnectionStringBuilder(initialConnectionString)
            {
                InitialCatalog = _databaseName
            }.ToString();

            var schemaOptions = new SqlServerSchemaOptions {
                AutomaticUpdatesEnabled = true
            };
            var config = Options.Create(new SqlServerDataStoreConfiguration {
                ConnectionString = TestConnectionString, Initialize = true, SchemaOptions = schemaOptions, StatementTimeout = TimeSpan.FromMinutes(10)
            });

            SchemaInformation = new SchemaInformation(SchemaVersionConstants.Min, maximumSupportedSchemaVersion);
            var scriptProvider      = new ScriptProvider <SchemaVersion>();
            var baseScriptProvider  = new BaseScriptProvider();
            var mediator            = Substitute.For <IMediator>();
            var sqlSortingValidator = new SqlServerSortingValidator(SchemaInformation);

            var sqlConnectionStringProvider = new DefaultSqlConnectionStringProvider(config);

            SqlConnectionFactory = new DefaultSqlConnectionFactory(sqlConnectionStringProvider);
            var schemaManagerDataStore = new SchemaManagerDataStore(SqlConnectionFactory, config, NullLogger <SchemaManagerDataStore> .Instance);

            _schemaUpgradeRunner = new SchemaUpgradeRunner(scriptProvider, baseScriptProvider, NullLogger <SchemaUpgradeRunner> .Instance, SqlConnectionFactory, schemaManagerDataStore);
            _schemaInitializer   = new SchemaInitializer(config, schemaManagerDataStore, _schemaUpgradeRunner, SchemaInformation, SqlConnectionFactory, sqlConnectionStringProvider, mediator, NullLogger <SchemaInitializer> .Instance);

            _searchParameterDefinitionManager = new SearchParameterDefinitionManager(ModelInfoProvider.Instance, _mediator, () => _searchService.CreateMockScope(), NullLogger <SearchParameterDefinitionManager> .Instance);

            _searchParameterDefinitionManager.StartAsync(CancellationToken.None);

            _filebasedSearchParameterStatusDataStore = new FilebasedSearchParameterStatusDataStore(_searchParameterDefinitionManager, ModelInfoProvider.Instance);

            var securityConfiguration = new SecurityConfiguration {
                PrincipalClaims = { "oid" }
            };

            var sqlServerFhirModel = new SqlServerFhirModel(
                SchemaInformation,
                _searchParameterDefinitionManager,
                () => _filebasedSearchParameterStatusDataStore,
                Options.Create(securityConfiguration),
                SqlConnectionFactory,
                Substitute.For <IMediator>(),
                NullLogger <SqlServerFhirModel> .Instance);

            SqlServerFhirModel = sqlServerFhirModel;

            var searchParameterToSearchValueTypeMap = new SearchParameterToSearchValueTypeMap();

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSqlServerTableRowParameterGenerators();
            serviceCollection.AddSingleton(sqlServerFhirModel);
            serviceCollection.AddSingleton <ISqlServerFhirModel>(sqlServerFhirModel);
            serviceCollection.AddSingleton(searchParameterToSearchValueTypeMap);

            ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

            var upsertResourceTvpGeneratorV6           = serviceProvider.GetRequiredService <V6.UpsertResourceTvpGenerator <ResourceMetadata> >();
            var upsertResourceTvpGeneratorV7           = serviceProvider.GetRequiredService <V7.UpsertResourceTvpGenerator <ResourceMetadata> >();
            var upsertResourceTvpGeneratorV13          = serviceProvider.GetRequiredService <V13.UpsertResourceTvpGenerator <IReadOnlyList <ResourceWrapper> > >();
            var upsertResourceTvpGeneratorV17          = serviceProvider.GetRequiredService <V17.UpsertResourceTvpGenerator <IReadOnlyList <ResourceWrapper> > >();
            var upsertResourceTvpGeneratorVLatest      = serviceProvider.GetRequiredService <VLatest.UpsertResourceTvpGenerator <IReadOnlyList <ResourceWrapper> > >();
            var reindexResourceTvpGeneratorV17         = serviceProvider.GetRequiredService <V17.ReindexResourceTvpGenerator <IReadOnlyList <ResourceWrapper> > >();
            var bulkReindexResourceTvpGeneratorV17     = serviceProvider.GetRequiredService <V17.BulkReindexResourcesTvpGenerator <IReadOnlyList <ResourceWrapper> > >();
            var reindexResourceTvpGeneratorVLatest     = serviceProvider.GetRequiredService <VLatest.ReindexResourceTvpGenerator <IReadOnlyList <ResourceWrapper> > >();
            var bulkReindexResourceTvpGeneratorVLatest = serviceProvider.GetRequiredService <VLatest.BulkReindexResourcesTvpGenerator <IReadOnlyList <ResourceWrapper> > >();
            var upsertSearchParamsTvpGenerator         = serviceProvider.GetRequiredService <VLatest.UpsertSearchParamsTvpGenerator <List <ResourceSearchParameterStatus> > >();

            _supportedSearchParameterDefinitionManager = new SupportedSearchParameterDefinitionManager(_searchParameterDefinitionManager);

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

            SqlServerSearchParameterStatusDataStore = new SqlServerSearchParameterStatusDataStore(
                () => SqlConnectionWrapperFactory.CreateMockScope(),
                upsertSearchParamsTvpGenerator,
                () => _filebasedSearchParameterStatusDataStore,
                SchemaInformation,
                sqlSortingValidator,
                sqlServerFhirModel,
                _searchParameterDefinitionManager);

            IOptions <CoreFeatureConfiguration> options = coreFeatures ?? Options.Create(new CoreFeatureConfiguration());

            _fhirDataStore = new SqlServerFhirDataStore(
                sqlServerFhirModel,
                searchParameterToSearchValueTypeMap,
                upsertResourceTvpGeneratorV6,
                upsertResourceTvpGeneratorV7,
                upsertResourceTvpGeneratorV13,
                upsertResourceTvpGeneratorV17,
                upsertResourceTvpGeneratorVLatest,
                reindexResourceTvpGeneratorV17,
                reindexResourceTvpGeneratorVLatest,
                bulkReindexResourceTvpGeneratorV17,
                bulkReindexResourceTvpGeneratorVLatest,
                options,
                SqlConnectionWrapperFactory,
                new CompressedRawResourceConverter(),
                NullLogger <SqlServerFhirDataStore> .Instance,
                SchemaInformation);

            _fhirOperationDataStore = new SqlServerFhirOperationDataStore(SqlConnectionWrapperFactory, NullLogger <SqlServerFhirOperationDataStore> .Instance);

            _fhirRequestContextAccessor.RequestContext.CorrelationId.Returns(Guid.NewGuid().ToString());
            _fhirRequestContextAccessor.RequestContext.RouteName.Returns("routeName");

            var searchableSearchParameterDefinitionManager = new SearchableSearchParameterDefinitionManager(_searchParameterDefinitionManager, _fhirRequestContextAccessor);
            var searchParameterExpressionParser            = new SearchParameterExpressionParser(new ReferenceSearchValueParser(_fhirRequestContextAccessor));
            var expressionParser = new ExpressionParser(() => searchableSearchParameterDefinitionManager, searchParameterExpressionParser);

            var searchOptionsFactory = new SearchOptionsFactory(
                expressionParser,
                () => searchableSearchParameterDefinitionManager,
                options,
                _fhirRequestContextAccessor,
                sqlSortingValidator,
                NullLogger <SearchOptionsFactory> .Instance);

            var searchParamTableExpressionQueryGeneratorFactory = new SearchParamTableExpressionQueryGeneratorFactory(searchParameterToSearchValueTypeMap);
            var sqlRootExpressionRewriter = new SqlRootExpressionRewriter(searchParamTableExpressionQueryGeneratorFactory);
            var chainFlatteningRewriter   = new ChainFlatteningRewriter(searchParamTableExpressionQueryGeneratorFactory);
            var sortRewriter = new SortRewriter(searchParamTableExpressionQueryGeneratorFactory);
            var partitionEliminationRewriter = new PartitionEliminationRewriter(sqlServerFhirModel, SchemaInformation, () => searchableSearchParameterDefinitionManager);

            _searchService = new SqlServerSearchService(
                searchOptionsFactory,
                _fhirDataStore,
                sqlServerFhirModel,
                sqlRootExpressionRewriter,
                chainFlatteningRewriter,
                sortRewriter,
                partitionEliminationRewriter,
                SqlConnectionWrapperFactory,
                SchemaInformation,
                _fhirRequestContextAccessor,
                new CompressedRawResourceConverter(),
                NullLogger <SqlServerSearchService> .Instance);

            ISearchParameterSupportResolver searchParameterSupportResolver = Substitute.For <ISearchParameterSupportResolver>();

            searchParameterSupportResolver.IsSearchParameterSupported(Arg.Any <SearchParameterInfo>()).Returns((true, false));

            _searchParameterStatusManager = new SearchParameterStatusManager(
                SqlServerSearchParameterStatusDataStore,
                _searchParameterDefinitionManager,
                searchParameterSupportResolver,
                mediator,
                NullLogger <SearchParameterStatusManager> .Instance);

            _testHelper = new SqlServerFhirStorageTestHelper(initialConnectionString, MasterDatabaseName, sqlServerFhirModel, SqlConnectionFactory);
        }
Exemple #24
0
        public SqlServerFhirStorageTestsFixture()
        {
            var initialConnectionString = Environment.GetEnvironmentVariable("SqlServer:ConnectionString") ?? LocalConnectionString;

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

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

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

            var schemaInformation   = new SchemaInformation(SchemaVersionConstants.Min, SchemaVersionConstants.Max);
            var scriptProvider      = new ScriptProvider <SchemaVersion>();
            var schemaUpgradeRunner = new SchemaUpgradeRunner(scriptProvider, config, NullLogger <SchemaUpgradeRunner> .Instance);

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

            var searchParameterDefinitionManager = Substitute.For <ISearchParameterDefinitionManager>();

            searchParameterDefinitionManager.AllSearchParameters.Returns(new[]
            {
                new SearchParameter {
                    Name = SearchParameterNames.Id, Type = SearchParamType.Token, Url = SearchParameterNames.IdUri.ToString()
                }.ToInfo(),
                new SearchParameter {
                    Name = SearchParameterNames.LastUpdated, Type = SearchParamType.Date, Url = SearchParameterNames.LastUpdatedUri.ToString()
                }.ToInfo(),
            });

            var securityConfiguration = new SecurityConfiguration {
                PrincipalClaims = { "oid" }
            };

            var sqlServerFhirModel = new SqlServerFhirModel(config, _schemaInitializer, searchParameterDefinitionManager, Options.Create(securityConfiguration), NullLogger <SqlServerFhirModel> .Instance);

            var serviceCollection = new ServiceCollection();

            serviceCollection.AddSqlServerTableRowParameterGenerators();
            serviceCollection.AddSingleton(sqlServerFhirModel);

            ServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();

            var upsertResourceTvpGenerator = serviceProvider.GetRequiredService <VLatest.UpsertResourceTvpGenerator <ResourceMetadata> >();

            var searchParameterToSearchValueTypeMap = new SearchParameterToSearchValueTypeMap(new SupportedSearchParameterDefinitionManager(searchParameterDefinitionManager));

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

            _fhirDataStore = new SqlServerFhirDataStore(config, sqlServerFhirModel, searchParameterToSearchValueTypeMap, upsertResourceTvpGenerator, Options.Create(new CoreFeatureConfiguration()), SqlConnectionWrapperFactory, NullLogger <SqlServerFhirDataStore> .Instance, schemaInformation);

            _fhirOperationDataStore = new SqlServerFhirOperationDataStore(SqlConnectionWrapperFactory, NullLogger <SqlServerFhirOperationDataStore> .Instance);

            _testHelper = new SqlServerFhirStorageTestHelper(TestConnectionString, initialConnectionString, masterConnectionString, sqlServerFhirModel);
        }
Exemple #25
0
 public ScriptProviderTests()
 {
     _scriptProvider = new ScriptProvider <TestSchemaVersionEnum>();
 }
        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);
        }
Exemple #27
0
 protected Loader(ConnectionData connection, ScriptProvider provider)
 {
     Connection = connection;
     _provider  = provider;
 }
Exemple #28
0
 public IEnumerable <SqlScript> GetScripts(IConnectionManager connectionManager)
 {
     return(ScriptProvider.GetScripts(connectionManager).OrderBy(script => script.Name, Comparer));
 }