Exemplo n.º 1
0
 public UpsertResourceHandler(
     IFhirDataStore fhirDataStore,
     Lazy <IConformanceProvider> conformanceProvider,
     IResourceWrapperFactory resourceWrapperFactory)
     : base(fhirDataStore, conformanceProvider, resourceWrapperFactory)
 {
 }
Exemplo n.º 2
0
        public FhirRepositoryTests()
        {
            _dataStore           = Substitute.For <IDataStore>();
            _conformanceProvider = Substitute.For <ConformanceProviderBase>();

            // TODO: FhirRepository instantiate ResourceDeserializer class directly
            // which will try to deserialize the raw resource. We should mock it as well.
            _rawResourceFactory     = Substitute.For <RawResourceFactory>(new FhirJsonSerializer());
            _resourceWrapperFactory = Substitute.For <IResourceWrapperFactory>();
            _resourceWrapperFactory
            .Create(Arg.Any <Resource>(), Arg.Any <bool>())
            .Returns(x => CreateResourceWrapper(x.ArgAt <Resource>(0), x.ArgAt <bool>(1)));

            _conformanceStatement = CapabilityStatementMock.GetMockedCapabilityStatement();
            CapabilityStatementMock.SetupMockResource(_conformanceStatement, ResourceType.Observation, null);
            var observationResource = _conformanceStatement.Rest.First().Resource.Find(x => x.Type == ResourceType.Observation);

            observationResource.ReadHistory  = false;
            observationResource.UpdateCreate = true;
            observationResource.Versioning   = CapabilityStatement.ResourceVersionPolicy.Versioned;

            CapabilityStatementMock.SetupMockResource(_conformanceStatement, ResourceType.Patient, null);
            var patientResource = _conformanceStatement.Rest.First().Resource.Find(x => x.Type == ResourceType.Patient);

            patientResource.ReadHistory  = true;
            patientResource.UpdateCreate = true;
            patientResource.Versioning   = CapabilityStatement.ResourceVersionPolicy.VersionedUpdate;

            _conformanceProvider.GetCapabilityStatementAsync().Returns(_conformanceStatement);
            _repository = new FhirRepository(_dataStore, new Lazy <IConformanceProvider>(() => _conformanceProvider), _resourceWrapperFactory);
        }
Exemplo n.º 3
0
 public CreateResourceHandler(
     IDataStore dataStore,
     Lazy <IConformanceProvider> conformanceProvider,
     IResourceWrapperFactory resourceWrapperFactory)
     : base(dataStore, conformanceProvider, resourceWrapperFactory)
 {
 }
Exemplo n.º 4
0
        public ResourceHandlerTests()
        {
            _fhirDataStore       = Substitute.For <IFhirDataStore>();
            _conformanceProvider = Substitute.For <ConformanceProviderBase>();
            _searchService       = Substitute.For <ISearchService>();

            // TODO: FhirRepository instantiate ResourceDeserializer class directly
            // which will try to deserialize the raw resource. We should mock it as well.
            _rawResourceFactory     = Substitute.For <RawResourceFactory>(new FhirJsonSerializer());
            _resourceWrapperFactory = Substitute.For <IResourceWrapperFactory>();
            _resourceWrapperFactory
            .Create(Arg.Any <ResourceElement>(), Arg.Any <bool>(), Arg.Any <bool>())
            .Returns(x => CreateResourceWrapper(x.ArgAt <ResourceElement>(0), x.ArgAt <bool>(1)));

            _conformanceStatement = CapabilityStatementMock.GetMockedCapabilityStatement();
            CapabilityStatementMock.SetupMockResource(_conformanceStatement, ResourceType.Observation, null);
            var observationResource = _conformanceStatement.Rest.First().Resource.Find(x => x.Type == ResourceType.Observation);

            observationResource.ReadHistory       = false;
            observationResource.UpdateCreate      = true;
            observationResource.ConditionalCreate = true;
            observationResource.ConditionalUpdate = true;
            observationResource.Versioning        = CapabilityStatement.ResourceVersionPolicy.Versioned;

            CapabilityStatementMock.SetupMockResource(_conformanceStatement, ResourceType.Patient, null);
            var patientResource = _conformanceStatement.Rest.First().Resource.Find(x => x.Type == ResourceType.Patient);

            patientResource.ReadHistory       = true;
            patientResource.UpdateCreate      = true;
            patientResource.ConditionalCreate = true;
            patientResource.ConditionalUpdate = true;
            patientResource.Versioning        = CapabilityStatement.ResourceVersionPolicy.VersionedUpdate;

            _conformanceProvider.GetCapabilityStatementOnStartup().Returns(_conformanceStatement.ToTypedElement().ToResourceElement());
            var lazyConformanceProvider = new Lazy <IConformanceProvider>(() => _conformanceProvider);

            var collection = new ServiceCollection();

            // an auth service that allows all.
            _authorizationService = Substitute.For <IAuthorizationService <DataActions> >();
            _authorizationService.CheckAccess(Arg.Any <DataActions>(), Arg.Any <CancellationToken>()).Returns(ci => ci.Arg <DataActions>());

            var referenceResolver = new ResourceReferenceResolver(_searchService, new TestQueryStringParser());

            _resourceIdProvider = new ResourceIdProvider();
            collection.Add(x => _mediator).Singleton().AsSelf();
            collection.Add(x => new CreateResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, _resourceIdProvider, referenceResolver, _authorizationService)).Singleton().AsSelf().AsImplementedInterfaces();
            collection.Add(x => new UpsertResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, _resourceIdProvider, _authorizationService, ModelInfoProvider.Instance)).Singleton().AsSelf().AsImplementedInterfaces();
            collection.Add(x => new ConditionalCreateResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, _searchService, x.GetService <IMediator>(), _resourceIdProvider, _authorizationService)).Singleton().AsSelf().AsImplementedInterfaces();
            collection.Add(x => new ConditionalUpsertResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, _searchService, x.GetService <IMediator>(), _resourceIdProvider, _authorizationService)).Singleton().AsSelf().AsImplementedInterfaces();
            collection.Add(x => new GetResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, _resourceIdProvider, _authorizationService)).Singleton().AsSelf().AsImplementedInterfaces();
            collection.Add(x => new DeleteResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, _resourceIdProvider, _authorizationService)).Singleton().AsSelf().AsImplementedInterfaces();

            ServiceProvider provider = collection.BuildServiceProvider();

            _mediator = new Mediator(type => provider.GetService(type));

            _deserializer = new ResourceDeserializer(
                (FhirResourceFormat.Json, new Func <string, string, DateTimeOffset, ResourceElement>((str, version, lastUpdated) => _fhirJsonParser.Parse(str).ToResourceElement())));
        }
 public CreateResourceHandler(
     IFhirDataStore fhirDataStore,
     Lazy <IConformanceProvider> conformanceProvider,
     IResourceWrapperFactory resourceWrapperFactory,
     ResourceIdProvider resourceIdProvider)
     : base(fhirDataStore, conformanceProvider, resourceWrapperFactory, resourceIdProvider)
 {
 }
 public DeleteResourceHandler(
     IFhirDataStore fhirDataStore,
     Lazy <IConformanceProvider> conformanceProvider,
     IResourceWrapperFactory resourceWrapperFactory,
     ResourceIdProvider resourceIdProvider,
     IFhirAuthorizationService authorizationService)
     : base(fhirDataStore, conformanceProvider, resourceWrapperFactory, resourceIdProvider, authorizationService)
 {
 }
        public BaseConditionalHandlerTests()
        {
            IFhirDataStore fhirDataStore = Substitute.For <IFhirDataStore>();
            Lazy <IConformanceProvider> conformanceProvider    = Substitute.For <Lazy <IConformanceProvider> >();
            IResourceWrapperFactory     resourceWrapperFactory = Substitute.For <IResourceWrapperFactory>();
            ResourceIdProvider          resourceIdProvider     = Substitute.For <ResourceIdProvider>();

            _testBaseConditionalHandler = new TestBaseConditionalHandler(fhirDataStore, _searchService, conformanceProvider, resourceWrapperFactory, resourceIdProvider, DisabledFhirAuthorizationService.Instance);
        }
 public TransactionBundleValidator(
     IFhirDataStore fhirDataStore,
     Lazy <IConformanceProvider> conformanceProvider,
     IResourceWrapperFactory resourceWrapperFactory,
     ISearchService searchService,
     ResourceIdProvider resourceIdProvider)
     : base(fhirDataStore, searchService, conformanceProvider, resourceWrapperFactory, resourceIdProvider)
 {
 }
Exemplo n.º 9
0
        public TransactionBundleValidatorTests()
        {
            IFhirDataStore fhirDataStore = Substitute.For <IFhirDataStore>();
            Lazy <IConformanceProvider> conformanceProvider    = Substitute.For <Lazy <IConformanceProvider> >();
            IResourceWrapperFactory     resourceWrapperFactory = Substitute.For <IResourceWrapperFactory>();
            ResourceIdProvider          resourceIdProvider     = Substitute.For <ResourceIdProvider>();

            _transactionBundleValidator = new TransactionBundleValidator(fhirDataStore, conformanceProvider, resourceWrapperFactory, _searchService, resourceIdProvider);
        }
 public TestBaseConditionalHandler(
     IFhirDataStore fhirDataStore,
     ISearchService searchService,
     Lazy <IConformanceProvider> conformanceProvider,
     IResourceWrapperFactory resourceWrapperFactory,
     ResourceIdProvider resourceIdProvider)
     : base(fhirDataStore, searchService, conformanceProvider, resourceWrapperFactory, resourceIdProvider)
 {
 }
Exemplo n.º 11
0
        public SearchParameterBehaviorTests()
        {
            _rawResourceFactory     = Substitute.For <RawResourceFactory>(new FhirJsonSerializer());
            _resourceWrapperFactory = Substitute.For <IResourceWrapperFactory>();
            _resourceWrapperFactory
            .Create(Arg.Any <ResourceElement>(), Arg.Any <bool>(), Arg.Any <bool>())
            .Returns(x => CreateResourceWrapper(x.ArgAt <ResourceElement>(0), x.ArgAt <bool>(1)));

            _fhirDataStore = Substitute.For <IFhirDataStore>();
        }
Exemplo n.º 12
0
        public GetResourceHandler(
            IFhirDataStore fhirDataStore,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory,
            ResourceDeserializer deserializer)
            : base(fhirDataStore, conformanceProvider, resourceWrapperFactory)
        {
            EnsureArg.IsNotNull(deserializer, nameof(deserializer));

            _deserializer = deserializer;
        }
Exemplo n.º 13
0
 public PatchResourceHandler(
     IMediator mediator,
     IFhirDataStore fhirDataStore,
     Lazy <IConformanceProvider> conformanceProvider,
     IResourceWrapperFactory resourceWrapperFactory,
     ResourceIdProvider resourceIdProvider,
     IAuthorizationService <DataActions> authorizationService)
     : base(fhirDataStore, conformanceProvider, resourceWrapperFactory, resourceIdProvider, authorizationService)
 {
     EnsureArg.IsNotNull(mediator, nameof(mediator));
     _mediator = mediator;
 }
Exemplo n.º 14
0
        public FhirRepository(
            IDataStore dataStore,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory)
        {
            EnsureArg.IsNotNull(dataStore, nameof(dataStore));
            EnsureArg.IsNotNull(resourceWrapperFactory, nameof(resourceWrapperFactory));

            _dataStore              = dataStore;
            _conformanceProvider    = conformanceProvider;
            _resourceWrapperFactory = resourceWrapperFactory;
        }
Exemplo n.º 15
0
        protected BaseConditionalHandler(
            IFhirDataStore fhirDataStore,
            ISearchService searchService,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory,
            ResourceIdProvider resourceIdProvider)
            : base(fhirDataStore, conformanceProvider, resourceWrapperFactory, resourceIdProvider)
        {
            EnsureArg.IsNotNull(searchService, nameof(searchService));

            _searchService = searchService;
        }
Exemplo n.º 16
0
        public ImportResourceParser(FhirJsonParser parser, IResourceWrapperFactory resourceFactory, IResourceMetaPopulator resourceMetaPopulator, ICompressedRawResourceConverter compressedRawResourceConverter)
        {
            EnsureArg.IsNotNull(parser, nameof(parser));
            EnsureArg.IsNotNull(resourceFactory, nameof(resourceFactory));
            EnsureArg.IsNotNull(compressedRawResourceConverter, nameof(compressedRawResourceConverter));

            _parser                         = parser;
            _resourceFactory                = resourceFactory;
            _resourceMetaPopulator          = resourceMetaPopulator;
            _compressedRawResourceConverter = compressedRawResourceConverter;
            _recyclableMemoryStreamManager  = new RecyclableMemoryStreamManager();
        }
        protected ConditionalResourceHandler(
            ISearchService searchService,
            IFhirDataStore fhirDataStore,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory,
            ResourceIdProvider resourceIdProvider,
            IAuthorizationService <DataActions> authorizationService)
            : base(fhirDataStore, conformanceProvider, resourceWrapperFactory, resourceIdProvider, authorizationService)
        {
            EnsureArg.IsNotNull(searchService, nameof(searchService));

            _searchService = searchService;
        }
Exemplo n.º 18
0
        protected BaseResourceHandler(
            IFhirDataStore fhirDataStore,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory)
        {
            EnsureArg.IsNotNull(fhirDataStore, nameof(fhirDataStore));
            EnsureArg.IsNotNull(conformanceProvider, nameof(conformanceProvider));
            EnsureArg.IsNotNull(resourceWrapperFactory, nameof(resourceWrapperFactory));

            ConformanceProvider     = conformanceProvider;
            FhirDataStore           = fhirDataStore;
            _resourceWrapperFactory = resourceWrapperFactory;
        }
        public ConditionalUpsertResourceHandler(
            IFhirDataStore fhirDataStore,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory,
            ISearchService searchService,
            IMediator mediator,
            ResourceIdProvider resourceIdProvider)
            : base(fhirDataStore, searchService, conformanceProvider, resourceWrapperFactory, resourceIdProvider)
        {
            EnsureArg.IsNotNull(mediator, nameof(mediator));

            _mediator = mediator;
        }
        public UpsertResourceHandler(
            IFhirDataStore fhirDataStore,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory,
            ResourceIdProvider resourceIdProvider,
            IFhirAuthorizationService authorizationService,
            IModelInfoProvider modelInfoProvider)
            : base(fhirDataStore, conformanceProvider, resourceWrapperFactory, resourceIdProvider, authorizationService)
        {
            EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider));

            _modelInfoProvider = modelInfoProvider;
        }
        public ResourceHandlerTests()
        {
            _fhirDataStore       = Substitute.For <IFhirDataStore>();
            _conformanceProvider = Substitute.For <ConformanceProviderBase>();
            _searchService       = Substitute.For <ISearchService>();

            // TODO: FhirRepository instantiate ResourceDeserializer class directly
            // which will try to deserialize the raw resource. We should mock it as well.
            _rawResourceFactory     = Substitute.For <RawResourceFactory>(new FhirJsonSerializer());
            _resourceWrapperFactory = Substitute.For <IResourceWrapperFactory>();
            _resourceWrapperFactory
            .Create(Arg.Any <ResourceElement>(), Arg.Any <bool>())
            .Returns(x => CreateResourceWrapper(x.ArgAt <ResourceElement>(0), x.ArgAt <bool>(1)));

            _conformanceStatement = CapabilityStatementMock.GetMockedCapabilityStatement();
            CapabilityStatementMock.SetupMockResource(_conformanceStatement, ResourceType.Observation, null);
            var observationResource = _conformanceStatement.Rest.First().Resource.Find(x => x.Type == ResourceType.Observation);

            observationResource.ReadHistory       = false;
            observationResource.UpdateCreate      = true;
            observationResource.ConditionalCreate = true;
            observationResource.ConditionalUpdate = true;
            observationResource.Versioning        = CapabilityStatement.ResourceVersionPolicy.Versioned;

            CapabilityStatementMock.SetupMockResource(_conformanceStatement, ResourceType.Patient, null);
            var patientResource = _conformanceStatement.Rest.First().Resource.Find(x => x.Type == ResourceType.Patient);

            patientResource.ReadHistory       = true;
            patientResource.UpdateCreate      = true;
            patientResource.ConditionalCreate = true;
            patientResource.ConditionalUpdate = true;
            patientResource.Versioning        = CapabilityStatement.ResourceVersionPolicy.VersionedUpdate;

            _conformanceProvider.GetCapabilityStatementAsync().Returns(_conformanceStatement.ToTypedElement().ToResourceElement());
            var lazyConformanceProvider = new Lazy <IConformanceProvider>(() => _conformanceProvider);

            var collection = new ServiceCollection();

            _resourceIdProvider = new ResourceIdProvider();
            collection.Add(x => _mediator).Singleton().AsSelf();
            collection.Add(x => new CreateResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, _resourceIdProvider)).Singleton().AsSelf().AsImplementedInterfaces();
            collection.Add(x => new UpsertResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, _resourceIdProvider)).Singleton().AsSelf().AsImplementedInterfaces();
            collection.Add(x => new ConditionalCreateResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, _searchService, x.GetService <IMediator>(), _resourceIdProvider)).Singleton().AsSelf().AsImplementedInterfaces();
            collection.Add(x => new ConditionalUpsertResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, _searchService, x.GetService <IMediator>(), _resourceIdProvider)).Singleton().AsSelf().AsImplementedInterfaces();
            collection.Add(x => new GetResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, Deserializers.ResourceDeserializer, _resourceIdProvider)).Singleton().AsSelf().AsImplementedInterfaces();
            collection.Add(x => new DeleteResourceHandler(_fhirDataStore, lazyConformanceProvider, _resourceWrapperFactory, _resourceIdProvider)).Singleton().AsSelf().AsImplementedInterfaces();

            ServiceProvider provider = collection.BuildServiceProvider();

            _mediator = new Mediator(type => provider.GetService(type));
        }
Exemplo n.º 22
0
        public ConditionalCreateResourceHandler(
            IFhirDataStore fhirDataStore,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory,
            ISearchService searchService,
            IMediator mediator)
            : base(fhirDataStore, conformanceProvider, resourceWrapperFactory)
        {
            EnsureArg.IsNotNull(searchService, nameof(searchService));
            EnsureArg.IsNotNull(mediator, nameof(mediator));

            _searchService = searchService;
            _mediator      = mediator;
        }
Exemplo n.º 23
0
        public ConditionalCreateResourceHandler(
            IFhirDataStore fhirDataStore,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory,
            ISearchService searchService,
            IMediator mediator,
            ResourceIdProvider resourceIdProvider,
            IAuthorizationService <DataActions> authorizationService)
            : base(searchService, fhirDataStore, conformanceProvider, resourceWrapperFactory, resourceIdProvider, authorizationService)
        {
            EnsureArg.IsNotNull(mediator, nameof(mediator));

            _mediator = mediator;
        }
Exemplo n.º 24
0
        public PatchResourceHandler(
            IFhirDataStore fhirDataStore,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory,
            ResourceIdProvider resourceIdProvider,
            IAuthorizationService <DataActions> authorizationService,
            IModelInfoProvider modelInfoProvider,
            ResourceDeserializer resourceDeserializer)
            : base(fhirDataStore, conformanceProvider, resourceWrapperFactory, resourceIdProvider, authorizationService)
        {
            EnsureArg.IsNotNull(modelInfoProvider, nameof(modelInfoProvider));

            _modelInfoProvider    = modelInfoProvider;
            _resourceDeserializer = resourceDeserializer;
        }
Exemplo n.º 25
0
        public BundleHandlerTests()
        {
            _router = Substitute.For <IRouter>();

            var fhirRequestContext = new DefaultFhirRequestContext();

            fhirRequestContext.BaseUri       = new Uri("https://localhost/");
            fhirRequestContext.CorrelationId = Guid.NewGuid().ToString();

            _fhirRequestContextAccessor = Substitute.For <IFhirRequestContextAccessor>();
            _fhirRequestContextAccessor.FhirRequestContext.Returns(fhirRequestContext);

            _httpContextAccessor = Substitute.For <IHttpContextAccessor>();

            _fhirJsonSerializer = new FhirJsonSerializer();
            _fhirJsonParser     = new FhirJsonParser();

            _searchService = Substitute.For <ISearchService>();

            IFhirDataStore fhirDataStore = Substitute.For <IFhirDataStore>();
            Lazy <IConformanceProvider> conformanceProvider    = Substitute.For <Lazy <IConformanceProvider> >();
            IResourceWrapperFactory     resourceWrapperFactory = Substitute.For <IResourceWrapperFactory>();
            ResourceIdProvider          resourceIdProvider     = Substitute.For <ResourceIdProvider>();
            var transactionBundleValidator = new TransactionBundleValidator(fhirDataStore, conformanceProvider, resourceWrapperFactory, _searchService, resourceIdProvider);

            _bundleHttpContextAccessor = new BundleHttpContextAccessor();

            IFeatureCollection featureCollection = CreateFeatureCollection();
            var httpContext = new DefaultHttpContext(featureCollection)
            {
                Request =
                {
                    Scheme   = "https",
                    Host     = new HostString("localhost"),
                    PathBase = new PathString("/"),
                },
            };

            _httpContextAccessor.HttpContext.Returns(httpContext);

            var transactionHandler = Substitute.For <ITransactionHandler>();

            _resourceIdProvider = new ResourceIdProvider();

            _bundleHandler = new BundleHandler(_httpContextAccessor, _fhirRequestContextAccessor, _fhirJsonSerializer, _fhirJsonParser, transactionHandler, _bundleHttpContextAccessor, _resourceIdProvider, transactionBundleValidator, NullLogger <BundleHandler> .Instance);
        }
Exemplo n.º 26
0
        public ConditionalUpsertResourceHandler(
            IFhirDataStore fhirDataStore,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory,
            ISearchService searchService,
            IMediator mediator,
            IsEnabled featureEnabled)
            : base(fhirDataStore, conformanceProvider, resourceWrapperFactory)
        {
            EnsureArg.IsNotNull(searchService, nameof(searchService));
            EnsureArg.IsNotNull(mediator, nameof(mediator));
            EnsureArg.IsNotNull(featureEnabled, nameof(featureEnabled));

            _searchService  = searchService;
            _mediator       = mediator;
            _featureEnabled = featureEnabled();
        }
Exemplo n.º 27
0
        public FhirStorageTestsBase(IDataStore dataStore)
        {
            _conformance = CapabilityStatementMock.GetMockedCapabilityStatement();

            CapabilityStatementMock.SetupMockResource(_conformance, ResourceType.Observation, null);
            var observationResource = _conformance.Rest[0].Resource.Find(r => r.Type == ResourceType.Observation);

            observationResource.UpdateCreate = true;
            observationResource.Versioning   = CapabilityStatement.ResourceVersionPolicy.Versioned;

            CapabilityStatementMock.SetupMockResource(_conformance, ResourceType.Organization, null);
            var organizationResource = _conformance.Rest[0].Resource.Find(r => r.Type == ResourceType.Organization);

            organizationResource.UpdateCreate = true;
            organizationResource.Versioning   = CapabilityStatement.ResourceVersionPolicy.NoVersion;

            var provider = Substitute.For <ConformanceProviderBase>();

            provider.GetCapabilityStatementAsync().Returns(_conformance);

            // TODO: FhirRepository instantiate ResourceDeserializer class directly
            // which will try to deserialize the raw resource. We should mock it as well.
            var rawResourceFactory = Substitute.For <RawResourceFactory>(new FhirJsonSerializer());

            _resourceWrapperFactory = Substitute.For <IResourceWrapperFactory>();
            _resourceWrapperFactory
            .Create(Arg.Any <Resource>(), Arg.Any <bool>())
            .Returns(x =>
            {
                Resource resource = x.ArgAt <Resource>(0);

                return(new ResourceWrapper(resource, rawResourceFactory.Create(resource), new ResourceRequest("http://fhir", HttpMethod.Post), x.ArgAt <bool>(1), null, null, null));
            });

            var collection = new ServiceCollection();

            collection.AddSingleton(typeof(IRequestHandler <CreateResourceRequest, UpsertResourceResponse>), new CreateResourceHandler(dataStore, new Lazy <IConformanceProvider>(() => provider), _resourceWrapperFactory));
            collection.AddSingleton(typeof(IRequestHandler <UpsertResourceRequest, UpsertResourceResponse>), new UpsertResourceHandler(dataStore, new Lazy <IConformanceProvider>(() => provider), _resourceWrapperFactory));
            collection.AddSingleton(typeof(IRequestHandler <GetResourceRequest, GetResourceResponse>), new GetResourceHandler(dataStore, new Lazy <IConformanceProvider>(() => provider), _resourceWrapperFactory));
            collection.AddSingleton(typeof(IRequestHandler <DeleteResourceRequest, DeleteResourceResponse>), new DeleteResourceHandler(dataStore, new Lazy <IConformanceProvider>(() => provider), _resourceWrapperFactory));

            ServiceProvider services = collection.BuildServiceProvider();

            Mediator = new Mediator(type => services.GetService(type));
        }
Exemplo n.º 28
0
        protected BaseResourceHandler(
            IFhirDataStore fhirDataStore,
            Lazy <IConformanceProvider> conformanceProvider,
            IResourceWrapperFactory resourceWrapperFactory,
            ResourceIdProvider resourceIdProvider,
            IAuthorizationService <DataActions> authorizationService)
        {
            EnsureArg.IsNotNull(fhirDataStore, nameof(fhirDataStore));
            EnsureArg.IsNotNull(conformanceProvider, nameof(conformanceProvider));
            EnsureArg.IsNotNull(resourceWrapperFactory, nameof(resourceWrapperFactory));
            EnsureArg.IsNotNull(resourceIdProvider, nameof(resourceIdProvider));
            EnsureArg.IsNotNull(authorizationService, nameof(authorizationService));

            ConformanceProvider     = conformanceProvider;
            AuthorizationService    = authorizationService;
            FhirDataStore           = fhirDataStore;
            _resourceWrapperFactory = resourceWrapperFactory;
            _resourceIdProvider     = resourceIdProvider;
        }
Exemplo n.º 29
0
        public ReindexUtilities(
            Func <IScoped <IFhirDataStore> > fhirDataStoreFactory,
            ISearchIndexer searchIndexer,
            ResourceDeserializer deserializer,
            ISupportedSearchParameterDefinitionManager searchParameterDefinitionManager,
            SearchParameterStatusManager searchParameterStatusManager,
            IResourceWrapperFactory resourceWrapperFactory)
        {
            EnsureArg.IsNotNull(fhirDataStoreFactory, nameof(fhirDataStoreFactory));
            EnsureArg.IsNotNull(searchIndexer, nameof(searchIndexer));
            EnsureArg.IsNotNull(deserializer, nameof(deserializer));
            EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager));
            EnsureArg.IsNotNull(searchParameterStatusManager, nameof(searchParameterStatusManager));
            EnsureArg.IsNotNull(resourceWrapperFactory, nameof(resourceWrapperFactory));

            _fhirDataStoreFactory             = fhirDataStoreFactory;
            _searchIndexer                    = searchIndexer;
            _deserializer                     = deserializer;
            _searchParameterDefinitionManager = searchParameterDefinitionManager;
            _searchParameterStatusManager     = searchParameterStatusManager;
            _resourceWrapperFactory           = resourceWrapperFactory;
        }