public CosmosDbSearchParameterStatusInitializerTests()
        {
            ISearchParameterStatusDataStore searchParameterStatusDataStore = Substitute.For <ISearchParameterStatusDataStore>();

            _cosmosDocumentQueryFactory = Substitute.For <ICosmosQueryFactory>();

            _initializer = new CosmosDbSearchParameterStatusInitializer(
                () => searchParameterStatusDataStore,
                _cosmosDocumentQueryFactory,
                new CosmosDataStoreConfiguration());

            _testParameterUri = new Uri("/test", UriKind.Relative);
            searchParameterStatusDataStore
            .GetSearchParameterStatuses()
            .Returns(new[]
            {
                new ResourceSearchParameterStatus
                {
                    Uri                  = _testParameterUri,
                    Status               = SearchParameterStatus.Enabled,
                    LastUpdated          = Clock.UtcNow,
                    IsPartiallySupported = false,
                },
            });
        }
コード例 #2
0
        public SqlServerSearchParameterStatusDataStore(
            Func <IScoped <SqlConnectionWrapperFactory> > scopedSqlConnectionWrapperFactory,
            VLatest.UpsertSearchParamsTvpGenerator <List <ResourceSearchParameterStatus> > updateSearchParamsTvpGenerator,
            FilebasedSearchParameterStatusDataStore.Resolver filebasedRegistry,
            SchemaInformation schemaInformation,
            SqlServerSortingValidator sortingValidator,
            ISqlServerFhirModel fhirModel,
            ISearchParameterDefinitionManager searchParameterDefinitionManager)
        {
            EnsureArg.IsNotNull(scopedSqlConnectionWrapperFactory, nameof(scopedSqlConnectionWrapperFactory));
            EnsureArg.IsNotNull(updateSearchParamsTvpGenerator, nameof(updateSearchParamsTvpGenerator));
            EnsureArg.IsNotNull(filebasedRegistry, nameof(filebasedRegistry));
            EnsureArg.IsNotNull(schemaInformation, nameof(schemaInformation));
            EnsureArg.IsNotNull(sortingValidator, nameof(sortingValidator));
            EnsureArg.IsNotNull(fhirModel, nameof(fhirModel));
            EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager));

            _scopedSqlConnectionWrapperFactory       = scopedSqlConnectionWrapperFactory;
            _updateSearchParamsTvpGenerator          = updateSearchParamsTvpGenerator;
            _filebasedSearchParameterStatusDataStore = filebasedRegistry.Invoke();
            _schemaInformation = schemaInformation;
            _sortingValidator  = sortingValidator;
            _fhirModel         = fhirModel;
            _searchParameterDefinitionManager = searchParameterDefinitionManager;
        }
コード例 #3
0
        public async Task InitializeAsync()
        {
            _fhirOperationDataStore         = _fixture.OperationDataStore;
            _fhirStorageTestHelper          = _fixture.TestHelper;
            _scopedOperationDataStore       = _fixture.OperationDataStore.CreateMockScope();
            _scopedDataStore                = _fixture.DataStore.CreateMockScope();
            _searchParameterStatusDataStore = _fixture.SearchParameterStatusDataStore;

            _jobConfiguration = new ReindexJobConfiguration();
            IOptions <ReindexJobConfiguration> optionsReindexConfig = Substitute.For <IOptions <ReindexJobConfiguration> >();

            optionsReindexConfig.Value.Returns(_jobConfiguration);

            _searchParameterDefinitionManager = new SearchParameterDefinitionManager(ModelInfoProvider.Instance);
            await _searchParameterDefinitionManager.StartAsync(CancellationToken.None);

            _supportedSearchParameterDefinitionManager = new SupportedSearchParameterDefinitionManager(_searchParameterDefinitionManager);
            var fhirRequestContextAccessor = Substitute.For <IFhirRequestContextAccessor>();

            _searchableSearchParameterDefinitionManager = new SearchableSearchParameterDefinitionManager(_searchParameterDefinitionManager, fhirRequestContextAccessor);

            ResourceWrapperFactory wrapperFactory = Mock.TypeWithArguments <ResourceWrapperFactory>(
                new RawResourceFactory(new FhirJsonSerializer()),
                _searchIndexer,
                _searchableSearchParameterDefinitionManager,
                Deserializers.ResourceDeserializer);

            _searchParameterStatusManager = new SearchParameterStatusManager(
                _searchParameterStatusDataStore,
                _searchParameterDefinitionManager,
                _searchParameterSupportResolver,
                _mediator);

            _createReindexRequestHandler = new CreateReindexRequestHandler(
                _fhirOperationDataStore,
                DisabledFhirAuthorizationService.Instance,
                optionsReindexConfig,
                _searchParameterDefinitionManager);
            _reindexUtilities = new ReindexUtilities(
                () => _scopedDataStore,
                _searchIndexer,
                Deserializers.ResourceDeserializer,
                _supportedSearchParameterDefinitionManager,
                _searchParameterStatusManager,
                wrapperFactory);

            coreOptions.Value.Returns(new CoreFeatureConfiguration());

            var searchParameterExpressionParser = new SearchParameterExpressionParser(new ReferenceSearchValueParser(fhirRequestContextAccessor));
            var expressionParser     = new ExpressionParser(() => _searchableSearchParameterDefinitionManager, searchParameterExpressionParser);
            var searchOptionsFactory = new SearchOptionsFactory(expressionParser, () => _searchableSearchParameterDefinitionManager, coreOptions, fhirRequestContextAccessor, _sortingValidator, NullLogger <SearchOptionsFactory> .Instance);
            var cosmosSearchService  = new FhirCosmosSearchService(searchOptionsFactory, _fixture.DataStore as CosmosFhirDataStore, new QueryBuilder(), _searchParameterDefinitionManager, fhirRequestContextAccessor) as ISearchService;

            _searchService = cosmosSearchService.CreateMockScope();

            await _fhirStorageTestHelper.DeleteAllReindexJobRecordsAsync(CancellationToken.None);
        }
コード例 #4
0
        public CosmosDbSearchParameterStatusInitializer(
            FilebasedSearchParameterStatusDataStore.Resolver filebasedSearchParameterStatusDataStoreResolver,
            ICosmosQueryFactory queryFactory)
        {
            EnsureArg.IsNotNull(filebasedSearchParameterStatusDataStoreResolver, nameof(filebasedSearchParameterStatusDataStoreResolver));
            EnsureArg.IsNotNull(queryFactory, nameof(queryFactory));

            _filebasedSearchParameterStatusDataStore = filebasedSearchParameterStatusDataStoreResolver.Invoke();
            _queryFactory = queryFactory;
        }
コード例 #5
0
        public SearchParameterStatusManager(
            ISearchParameterStatusDataStore searchParameterStatusDataStore,
            ISearchParameterDefinitionManager searchParameterDefinitionManager,
            ISearchParameterSupportResolver searchParameterSupportResolver,
            IMediator mediator)
        {
            EnsureArg.IsNotNull(searchParameterStatusDataStore, nameof(searchParameterStatusDataStore));
            EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager));
            EnsureArg.IsNotNull(searchParameterSupportResolver, nameof(searchParameterSupportResolver));
            EnsureArg.IsNotNull(mediator, nameof(mediator));

            _searchParameterStatusDataStore   = searchParameterStatusDataStore;
            _searchParameterDefinitionManager = searchParameterDefinitionManager;
            _searchParameterSupportResolver   = searchParameterSupportResolver;
            _mediator = mediator;
        }
        public SqlServerSearchParameterStatusDataStore(
            Func <IScoped <SqlConnectionWrapperFactory> > scopedSqlConnectionWrapperFactory,
            VLatest.UpsertSearchParamsTvpGenerator <List <ResourceSearchParameterStatus> > updateSearchParamsTvpGenerator,
            FilebasedSearchParameterStatusDataStore.Resolver filebasedRegistry,
            SchemaInformation schemaInformation)
        {
            EnsureArg.IsNotNull(scopedSqlConnectionWrapperFactory, nameof(scopedSqlConnectionWrapperFactory));
            EnsureArg.IsNotNull(updateSearchParamsTvpGenerator, nameof(updateSearchParamsTvpGenerator));
            EnsureArg.IsNotNull(filebasedRegistry, nameof(filebasedRegistry));
            EnsureArg.IsNotNull(schemaInformation, nameof(schemaInformation));

            _scopedSqlConnectionWrapperFactory       = scopedSqlConnectionWrapperFactory;
            _updateSearchParamsTvpGenerator          = updateSearchParamsTvpGenerator;
            _filebasedSearchParameterStatusDataStore = filebasedRegistry.Invoke();
            _schemaInformation = schemaInformation;
        }
コード例 #7
0
        public async Task InitializeAsync()
        {
            _fhirOperationDataStore         = _fixture.OperationDataStore;
            _fhirStorageTestHelper          = _fixture.TestHelper;
            _scopedOperationDataStore       = _fhirOperationDataStore.CreateMockScope();
            _scopedDataStore                = _fixture.DataStore.CreateMockScope();
            _searchParameterStatusDataStore = _fixture.SearchParameterStatusDataStore;

            _jobConfiguration = new ReindexJobConfiguration();
            IOptions <ReindexJobConfiguration> optionsReindexConfig = Substitute.For <IOptions <ReindexJobConfiguration> >();

            optionsReindexConfig.Value.Returns(_jobConfiguration);

            _searchParameterDefinitionManager          = _fixture.SearchParameterDefinitionManager;
            _supportedSearchParameterDefinitionManager = _fixture.SupportedSearchParameterDefinitionManager;

            ResourceWrapperFactory wrapperFactory = Mock.TypeWithArguments <ResourceWrapperFactory>(
                new RawResourceFactory(new FhirJsonSerializer()),
                _searchIndexer,
                _searchParameterDefinitionManager,
                Deserializers.ResourceDeserializer);

            _searchParameterStatusManager = new SearchParameterStatusManager(
                _searchParameterStatusDataStore,
                _searchParameterDefinitionManager,
                _searchParameterSupportResolver,
                _mediator);

            _createReindexRequestHandler = new CreateReindexRequestHandler(
                _fhirOperationDataStore,
                DisabledFhirAuthorizationService.Instance,
                optionsReindexConfig,
                _searchParameterDefinitionManager);

            _reindexUtilities = new ReindexUtilities(
                () => _scopedDataStore,
                _searchIndexer,
                Deserializers.ResourceDeserializer,
                _supportedSearchParameterDefinitionManager,
                _searchParameterStatusManager,
                wrapperFactory);

            _searchService = _fixture.SearchService.CreateMockScope();

            await _fhirStorageTestHelper.DeleteAllReindexJobRecordsAsync(CancellationToken.None);
        }
コード例 #8
0
        public ReindexUtilities(
            Func <IScoped <IFhirDataStore> > fhirDataStoreFactory,
            ISearchIndexer searchIndexer,
            ResourceDeserializer deserializer,
            ISupportedSearchParameterDefinitionManager searchParameterDefinitionManager,
            ISearchParameterStatusDataStore searchParameterStatusDataStore)
        {
            EnsureArg.IsNotNull(fhirDataStoreFactory, nameof(fhirDataStoreFactory));
            EnsureArg.IsNotNull(searchIndexer, nameof(searchIndexer));
            EnsureArg.IsNotNull(deserializer, nameof(deserializer));
            EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager));
            EnsureArg.IsNotNull(searchParameterStatusDataStore, nameof(searchParameterStatusDataStore));

            _fhirDataStoreFactory             = fhirDataStoreFactory;
            _searchIndexer                    = searchIndexer;
            _deserializer                     = deserializer;
            _searchParameterDefinitionManager = searchParameterDefinitionManager;
            _searchParameterStatusDataStore   = searchParameterStatusDataStore;
        }
コード例 #9
0
        public SearchParameterStatusManager(
            ISearchParameterStatusDataStore searchParameterStatusDataStore,
            ISearchParameterDefinitionManager searchParameterDefinitionManager,
            ISearchParameterSupportResolver searchParameterSupportResolver,
            IMediator mediator,
            ILogger <SearchParameterStatusManager> logger)
        {
            EnsureArg.IsNotNull(searchParameterStatusDataStore, nameof(searchParameterStatusDataStore));
            EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager));
            EnsureArg.IsNotNull(searchParameterSupportResolver, nameof(searchParameterSupportResolver));
            EnsureArg.IsNotNull(mediator, nameof(mediator));
            EnsureArg.IsNotNull(logger, nameof(logger));

            _searchParameterStatusDataStore   = searchParameterStatusDataStore;
            _searchParameterDefinitionManager = searchParameterDefinitionManager;
            _searchParameterSupportResolver   = searchParameterSupportResolver;
            _mediator = mediator;
            _logger   = logger;

            _latestSearchParams = DateTimeOffset.MinValue;
        }
コード例 #10
0
        public SqlServerFhirModel(
            SchemaInformation schemaInformation,
            ISearchParameterDefinitionManager searchParameterDefinitionManager,
            FilebasedSearchParameterStatusDataStore.Resolver filebasedRegistry,
            IOptions <SecurityConfiguration> securityConfiguration,
            ISqlConnectionStringProvider sqlConnectionStringProvider,
            ILogger <SqlServerFhirModel> logger)
        {
            EnsureArg.IsNotNull(schemaInformation, nameof(schemaInformation));
            EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager));
            EnsureArg.IsNotNull(filebasedRegistry, nameof(filebasedRegistry));
            EnsureArg.IsNotNull(securityConfiguration?.Value, nameof(securityConfiguration));
            EnsureArg.IsNotNull(sqlConnectionStringProvider, nameof(sqlConnectionStringProvider));
            EnsureArg.IsNotNull(logger, nameof(logger));

            _schemaInformation = schemaInformation;
            _searchParameterDefinitionManager        = searchParameterDefinitionManager;
            _filebasedSearchParameterStatusDataStore = filebasedRegistry.Invoke();
            _securityConfiguration       = securityConfiguration.Value;
            _sqlConnectionStringProvider = sqlConnectionStringProvider;
            _logger = logger;
        }
コード例 #11
0
        public SearchParameterDefinitionManagerTests()
        {
            _searchParameterSupportResolver = Substitute.For <ISearchParameterSupportResolver>();
            _mediator = Substitute.For <IMediator>();
            _searchParameterStatusDataStore   = Substitute.For <ISearchParameterStatusDataStore>();
            _searchParameterDefinitionManager = new SearchParameterDefinitionManager(ModelInfoProvider.Instance);
            _fhirRequestContextAccessor       = Substitute.For <IFhirRequestContextAccessor>();
            _fhirRequestContextAccessor.FhirRequestContext.Returns(_fhirRequestContext);

            _manager = new SearchParameterStatusManager(
                _searchParameterStatusDataStore,
                _searchParameterDefinitionManager,
                _searchParameterSupportResolver,
                _mediator);

            _searchParameterStatusDataStore.GetSearchParameterStatuses()
            .Returns(new[]
            {
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Enabled,
                    Uri    = new Uri(ResourceId),
                },
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Enabled,
                    Uri    = new Uri(ResourceLastUpdated),
                    IsPartiallySupported = true,
                },
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Disabled,
                    Uri    = new Uri(ResourceProfile),
                },
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Supported,
                    Uri    = new Uri(ResourceSecurity),
                },
            });

            _queryParameter       = new SearchParameterInfo("_query", SearchParamType.Token, new Uri(ResourceQuery));
            _searchParameterInfos = new[]
            {
                new SearchParameterInfo("_id", SearchParamType.Token, new Uri(ResourceId)),
                new SearchParameterInfo("_lastUpdated", SearchParamType.Token, new Uri(ResourceLastUpdated)),
                new SearchParameterInfo("_profile", SearchParamType.Token, new Uri(ResourceProfile)),
                new SearchParameterInfo("_security", SearchParamType.Token, new Uri(ResourceSecurity)),
                _queryParameter,
            };

            _testSearchParamInfo = new SearchParameterInfo("_test", SearchParamType.Special, new Uri(ResourceTest));

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

            _searchParameterSupportResolver
            .IsSearchParameterSupported(Arg.Is(_searchParameterInfos[4]))
            .Returns((true, false));
        }
コード例 #12
0
        public async Task InitializeAsync()
        {
            var fhirStoredProcs = typeof(IStoredProcedure).Assembly
                                  .GetTypes()
                                  .Where(x => !x.IsAbstract && typeof(IStoredProcedure).IsAssignableFrom(x))
                                  .ToArray()
                                  .Select(type => (IStoredProcedure)Activator.CreateInstance(type));

            var optionsMonitor = Substitute.For <IOptionsMonitor <CosmosCollectionConfiguration> >();

            optionsMonitor.Get(CosmosDb.Constants.CollectionConfigurationName).Returns(_cosmosCollectionConfiguration);

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

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

            _supportedSearchParameterDefinitionManager = new SupportedSearchParameterDefinitionManager(_searchParameterDefinitionManager);
            var searchableSearchParameterDefinitionManager = new SearchableSearchParameterDefinitionManager(_searchParameterDefinitionManager, _fhirRequestContextAccessor);

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

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

            var updaters = new ICollectionUpdater[]
            {
                new FhirCollectionSettingsUpdater(_cosmosDataStoreConfiguration, optionsMonitor, NullLogger <FhirCollectionSettingsUpdater> .Instance),
                new StoredProcedureInstaller(fhirStoredProcs),
                new CosmosDbSearchParameterStatusInitializer(
                    () => _filebasedSearchParameterStatusDataStore,
                    new CosmosQueryFactory(
                        new CosmosResponseProcessor(_fhirRequestContextAccessor, mediator, Substitute.For <ICosmosQueryLogger>(), NullLogger <CosmosResponseProcessor> .Instance),
                        NullFhirCosmosQueryLogger.Instance),
                    _cosmosDataStoreConfiguration),
            };

            var dbLock = new CosmosDbDistributedLockFactory(Substitute.For <Func <IScoped <Container> > >(), NullLogger <CosmosDbDistributedLock> .Instance);

            var upgradeManager = new CollectionUpgradeManager(updaters, _cosmosDataStoreConfiguration, optionsMonitor, dbLock, NullLogger <CollectionUpgradeManager> .Instance);
            ICosmosClientTestProvider testProvider = new CosmosClientReadWriteTestProvider();

            var cosmosResponseProcessor = Substitute.For <ICosmosResponseProcessor>();

            var responseProcessor           = new CosmosResponseProcessor(_fhirRequestContextAccessor, mediator, Substitute.For <ICosmosQueryLogger>(), NullLogger <CosmosResponseProcessor> .Instance);
            var handler                     = new FhirCosmosResponseHandler(() => new NonDisposingScope(_container), _cosmosDataStoreConfiguration, _fhirRequestContextAccessor, responseProcessor);
            var retryExceptionPolicyFactory = new RetryExceptionPolicyFactory(_cosmosDataStoreConfiguration, _fhirRequestContextAccessor);
            var documentClientInitializer   = new FhirCosmosClientInitializer(testProvider, () => new[] { handler }, retryExceptionPolicyFactory, NullLogger <FhirCosmosClientInitializer> .Instance);

            _cosmosClient = documentClientInitializer.CreateCosmosClient(_cosmosDataStoreConfiguration);
            var fhirCollectionInitializer = new CollectionInitializer(_cosmosCollectionConfiguration, _cosmosDataStoreConfiguration, upgradeManager, retryExceptionPolicyFactory, testProvider, NullLogger <CollectionInitializer> .Instance);

            // Cosmos DB emulators throws errors when multiple collections are initialized concurrently.
            // Use the semaphore to only allow one initialization at a time.
            await CollectionInitializationSemaphore.WaitAsync();

            try
            {
                await documentClientInitializer.InitializeDataStore(_cosmosClient, _cosmosDataStoreConfiguration, new List <ICollectionInitializer> {
                    fhirCollectionInitializer
                });

                _container = documentClientInitializer.CreateFhirContainer(_cosmosClient, _cosmosDataStoreConfiguration.DatabaseId, _cosmosCollectionConfiguration.CollectionId);
            }
            finally
            {
                CollectionInitializationSemaphore.Release();
            }

            var cosmosDocumentQueryFactory = new CosmosQueryFactory(cosmosResponseProcessor, NullFhirCosmosQueryLogger.Instance);

            var documentClient = new NonDisposingScope(_container);

            _searchParameterStatusDataStore = new CosmosDbSearchParameterStatusDataStore(
                () => documentClient,
                _cosmosDataStoreConfiguration,
                cosmosDocumentQueryFactory);

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

            _fhirDataStore = new CosmosFhirDataStore(
                documentClient,
                _cosmosDataStoreConfiguration,
                optionsMonitor,
                cosmosDocumentQueryFactory,
                retryExceptionPolicyFactory,
                NullLogger <CosmosFhirDataStore> .Instance,
                options,
                new Lazy <ISupportedSearchParameterDefinitionManager>(_supportedSearchParameterDefinitionManager),
                ModelInfoProvider.Instance);

            _fhirOperationDataStore = new CosmosFhirOperationDataStore(
                documentClient,
                _cosmosDataStoreConfiguration,
                optionsMonitor,
                retryExceptionPolicyFactory,
                new CosmosQueryFactory(responseProcessor, new NullFhirCosmosQueryLogger()),
                NullLogger <CosmosFhirOperationDataStore> .Instance);

            var searchParameterExpressionParser = new SearchParameterExpressionParser(new ReferenceSearchValueParser(_fhirRequestContextAccessor));
            var expressionParser     = new ExpressionParser(() => searchableSearchParameterDefinitionManager, searchParameterExpressionParser);
            var searchOptionsFactory = new SearchOptionsFactory(expressionParser, () => searchableSearchParameterDefinitionManager, options, _fhirRequestContextAccessor, Substitute.For <ISortingValidator>(), NullLogger <SearchOptionsFactory> .Instance);

            ICosmosDbCollectionPhysicalPartitionInfo cosmosDbPhysicalPartitionInfo = Substitute.For <ICosmosDbCollectionPhysicalPartitionInfo>();

            cosmosDbPhysicalPartitionInfo.PhysicalPartitionCount.Returns(1);

            _searchService = new FhirCosmosSearchService(
                searchOptionsFactory,
                _fhirDataStore,
                new QueryBuilder(),
                _fhirRequestContextAccessor,
                _cosmosDataStoreConfiguration,
                cosmosDbPhysicalPartitionInfo,
                new QueryPartitionStatisticsCache(),
                Enumerable.Empty <ICosmosExpressionRewriter>(),
                NullLogger <FhirCosmosSearchService> .Instance);

            await _searchParameterDefinitionManager.EnsureInitializedAsync(CancellationToken.None);

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

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

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

            _fhirStorageTestHelper = new CosmosDbFhirStorageTestHelper(_container);
        }
コード例 #13
0
        public SearchParameterStatusManagerTests()
        {
            _searchParameterStatusDataStore   = Substitute.For <ISearchParameterStatusDataStore>();
            _searchParameterDefinitionManager = Substitute.For <ISearchParameterDefinitionManager>();
            _searchParameterSupportResolver   = Substitute.For <ISearchParameterSupportResolver>();
            _mediator = Substitute.For <IMediator>();

            _manager = new SearchParameterStatusManager(
                _searchParameterStatusDataStore,
                _searchParameterDefinitionManager,
                _searchParameterSupportResolver,
                _mediator);

            _resourceSearchParameterStatuses = new[]
            {
                new ResourceSearchParameterStatus
                {
                    Status      = SearchParameterStatus.Enabled,
                    Uri         = new Uri(ResourceId),
                    LastUpdated = Clock.UtcNow,
                },
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Enabled,
                    Uri    = new Uri(ResourceLastupdated),
                    IsPartiallySupported = true,
                    LastUpdated          = Clock.UtcNow,
                },
                new ResourceSearchParameterStatus
                {
                    Status      = SearchParameterStatus.Disabled,
                    Uri         = new Uri(ResourceProfile),
                    LastUpdated = Clock.UtcNow,
                },
                new ResourceSearchParameterStatus
                {
                    Status      = SearchParameterStatus.Supported,
                    Uri         = new Uri(ResourceSecurity),
                    LastUpdated = Clock.UtcNow,
                },
            };

            _searchParameterStatusDataStore.GetSearchParameterStatuses().Returns(_resourceSearchParameterStatuses);

            List <string> baseResourceTypes = new List <string>()
            {
                "Resource"
            };
            List <string> targetResourceTypes = new List <string>()
            {
                "Patient"
            };

            _queryParameter       = new SearchParameterInfo("_query", SearchParamType.Token, new Uri(ResourceQuery));
            _searchParameterInfos = new[]
            {
                new SearchParameterInfo("_id", SearchParamType.Token, new Uri(ResourceId), targetResourceTypes: targetResourceTypes, baseResourceTypes: baseResourceTypes),
                new SearchParameterInfo("_lastUpdated", SearchParamType.Token, new Uri(ResourceLastupdated), targetResourceTypes: targetResourceTypes, baseResourceTypes: baseResourceTypes),
                new SearchParameterInfo("_profile", SearchParamType.Token, new Uri(ResourceProfile), targetResourceTypes: targetResourceTypes),
                new SearchParameterInfo("_security", SearchParamType.Token, new Uri(ResourceSecurity), targetResourceTypes: targetResourceTypes),
                _queryParameter,
            };

            _searchParameterDefinitionManager.GetSearchParameters("Account")
            .Returns(_searchParameterInfos);

            _searchParameterDefinitionManager.AllSearchParameters
            .Returns(_searchParameterInfos);

            _searchParameterDefinitionManager.GetSearchParameter(new Uri(ResourceQuery))
            .Returns(_queryParameter);

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

            _searchParameterSupportResolver
            .IsSearchParameterSupported(Arg.Is(_searchParameterInfos[4]))
            .Returns((true, false));
        }
コード例 #14
0
        public SearchParameterDefinitionManagerTests()
        {
            _searchParameterSupportResolver = Substitute.For <ISearchParameterSupportResolver>();
            _mediator = Substitute.For <IMediator>();
            _searchParameterStatusDataStore   = Substitute.For <ISearchParameterStatusDataStore>();
            _searchParameterDefinitionManager = new SearchParameterDefinitionManager(ModelInfoProvider.Instance, _mediator);
            _fhirRequestContextAccessor       = Substitute.For <RequestContextAccessor <IFhirRequestContext> >();
            _fhirRequestContextAccessor.RequestContext.Returns(_fhirRequestContext);

            _manager = new SearchParameterStatusManager(
                _searchParameterStatusDataStore,
                _searchParameterDefinitionManager,
                _searchParameterSupportResolver,
                _mediator);

            _searchParameterStatusDataStore.GetSearchParameterStatuses()
            .Returns(new[]
            {
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Enabled,
                    Uri    = new Uri(ResourceId),
                },
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Enabled,
                    Uri    = new Uri(ResourceLastUpdated),
                    IsPartiallySupported = true,
                },
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Disabled,
                    Uri    = new Uri(ResourceProfile),
                },
                new ResourceSearchParameterStatus
                {
                    Status = SearchParameterStatus.Supported,
                    Uri    = new Uri(ResourceSecurity),
                },
            });

            _queryParameter = new SearchParameterInfo("_query", "_query", SearchParamType.Token, new Uri(ResourceQuery), baseResourceTypes: new List <string>()
            {
                "Patient"
            });
            _searchParameterInfos = new[]
            {
                new SearchParameterInfo("_id", "_id", SearchParamType.Token, new Uri(ResourceId)),
                new SearchParameterInfo("_lastUpdated", "_lastUpdated", SearchParamType.Token, new Uri(ResourceLastUpdated)),
                new SearchParameterInfo("_profile", "_profile", SearchParamType.Token, new Uri(ResourceProfile)),
                new SearchParameterInfo("_security", "_security", SearchParamType.Token, new Uri(ResourceSecurity)),
                _queryParameter,
            };

            _testSearchParamInfo = new SearchParameterInfo("_test", "_test", SearchParamType.Special, new Uri(ResourceTest));

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

            _searchParameterSupportResolver
            .IsSearchParameterSupported(Arg.Is(_searchParameterInfos[4]))
            .Returns((true, false));

            var searchParameterDataStoreValidator = Substitute.For <IDataStoreSearchParameterValidator>();

            searchParameterDataStoreValidator.ValidateSearchParameter(Arg.Any <SearchParameterInfo>(), out Arg.Any <string>()).Returns(true, null);

            var searchService = Substitute.For <ISearchService>();

            _searchParameterOperations = new SearchParameterOperations(
                _manager,
                _searchParameterDefinitionManager,
                ModelInfoProvider.Instance,
                _searchParameterSupportResolver,
                searchParameterDataStoreValidator,
                () => searchService.CreateMockScope(),
                NullLogger <SearchParameterOperations> .Instance);
        }
コード例 #15
0
        public async Task InitializeAsync()
        {
            var fhirStoredProcs = typeof(IStoredProcedure).Assembly
                                  .GetTypes()
                                  .Where(x => !x.IsAbstract && typeof(IStoredProcedure).IsAssignableFrom(x))
                                  .ToArray()
                                  .Select(type => (IStoredProcedure)Activator.CreateInstance(type));

            var optionsMonitor = Substitute.For <IOptionsMonitor <CosmosCollectionConfiguration> >();

            optionsMonitor.Get(CosmosDb.Constants.CollectionConfigurationName).Returns(_cosmosCollectionConfiguration);

            var searchParameterDefinitionManager = new SearchParameterDefinitionManager(ModelInfoProvider.Instance);
            await searchParameterDefinitionManager.StartAsync(CancellationToken.None);

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

            var updaters = new ICollectionUpdater[]
            {
                new FhirCollectionSettingsUpdater(_cosmosDataStoreConfiguration, optionsMonitor, NullLogger <FhirCollectionSettingsUpdater> .Instance),
                new StoredProcedureInstaller(fhirStoredProcs),
                new CosmosDbSearchParameterStatusInitializer(
                    () => _filebasedSearchParameterStatusDataStore,
                    new CosmosQueryFactory(
                        new CosmosResponseProcessor(Substitute.For <IFhirRequestContextAccessor>(), Substitute.For <IMediator>(), NullLogger <CosmosResponseProcessor> .Instance),
                        NullFhirCosmosQueryLogger.Instance)),
            };

            var dbLock = new CosmosDbDistributedLockFactory(Substitute.For <Func <IScoped <Container> > >(), NullLogger <CosmosDbDistributedLock> .Instance);

            var upgradeManager = new CollectionUpgradeManager(updaters, _cosmosDataStoreConfiguration, optionsMonitor, dbLock, NullLogger <CollectionUpgradeManager> .Instance);
            ICosmosClientTestProvider testProvider = new CosmosClientReadWriteTestProvider();

            var fhirRequestContextAccessor = new FhirRequestContextAccessor();
            var cosmosResponseProcessor    = Substitute.For <ICosmosResponseProcessor>();

            var responseProcessor         = new CosmosResponseProcessor(fhirRequestContextAccessor, Substitute.For <IMediator>(), NullLogger <CosmosResponseProcessor> .Instance);
            var handler                   = new FhirCosmosResponseHandler(() => new NonDisposingScope(_container), _cosmosDataStoreConfiguration, fhirRequestContextAccessor, responseProcessor);
            var documentClientInitializer = new FhirCosmosClientInitializer(testProvider, () => new[] { handler }, NullLogger <FhirCosmosClientInitializer> .Instance);

            _cosmosClient = documentClientInitializer.CreateCosmosClient(_cosmosDataStoreConfiguration);
            var fhirCollectionInitializer = new CollectionInitializer(_cosmosCollectionConfiguration.CollectionId, _cosmosDataStoreConfiguration, _cosmosCollectionConfiguration.InitialCollectionThroughput, upgradeManager, NullLogger <CollectionInitializer> .Instance);

            // Cosmos DB emulators throws errors when multiple collections are initialized concurrently.
            // Use the semaphore to only allow one initialization at a time.
            await CollectionInitializationSemaphore.WaitAsync();

            try
            {
                await documentClientInitializer.InitializeDataStore(_cosmosClient, _cosmosDataStoreConfiguration, new List <ICollectionInitializer> {
                    fhirCollectionInitializer
                });

                _container = documentClientInitializer.CreateFhirContainer(_cosmosClient, _cosmosDataStoreConfiguration.DatabaseId, _cosmosCollectionConfiguration.CollectionId);
            }
            finally
            {
                CollectionInitializationSemaphore.Release();
            }

            var cosmosDocumentQueryFactory = new CosmosQueryFactory(cosmosResponseProcessor, NullFhirCosmosQueryLogger.Instance);

            var documentClient = new NonDisposingScope(_container);

            _searchParameterStatusDataStore = new CosmosDbSearchParameterStatusDataStore(
                () => documentClient,
                _cosmosDataStoreConfiguration,
                cosmosDocumentQueryFactory);

            _fhirDataStore = new CosmosFhirDataStore(
                documentClient,
                _cosmosDataStoreConfiguration,
                optionsMonitor,
                cosmosDocumentQueryFactory,
                new RetryExceptionPolicyFactory(_cosmosDataStoreConfiguration),
                NullLogger <CosmosFhirDataStore> .Instance,
                Options.Create(new CoreFeatureConfiguration()));

            _fhirOperationDataStore = new CosmosFhirOperationDataStore(
                documentClient,
                _cosmosDataStoreConfiguration,
                optionsMonitor,
                new RetryExceptionPolicyFactory(_cosmosDataStoreConfiguration),
                new CosmosQueryFactory(responseProcessor, new NullFhirCosmosQueryLogger()),
                NullLogger <CosmosFhirOperationDataStore> .Instance);

            _fhirStorageTestHelper = new CosmosDbFhirStorageTestHelper(_container);
        }