Exemplo n.º 1
0
        public DeleteSearchParameterBehavior(ISearchParameterUtilities searchParameterUtilities, IFhirDataStore fhirDataStore)
        {
            EnsureArg.IsNotNull(searchParameterUtilities, nameof(searchParameterUtilities));
            EnsureArg.IsNotNull(fhirDataStore, nameof(fhirDataStore));

            _searchParameterUtilities = searchParameterUtilities;
            _fhirDataStore            = fhirDataStore;
        }
Exemplo n.º 2
0
        public FhirStorageTests(FhirStorageTestsFixture fixture)
        {
            _fixture       = fixture;
            _searchService = Substitute.For <ISearchService>();
            _dataStore     = fixture.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.ToTypedElement().ToResourceElement());

            // 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());

            var resourceWrapperFactory = Substitute.For <IResourceWrapperFactory>();

            resourceWrapperFactory
            .Create(Arg.Any <ResourceElement>(), Arg.Any <bool>(), Arg.Any <bool>())
            .Returns(x =>
            {
                ResourceElement resource = x.ArgAt <ResourceElement>(0);

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

            var collection = new ServiceCollection();

            var resourceIdProvider = new ResourceIdProvider();

            _searchParameterUtilities = Substitute.For <ISearchParameterUtilities>();

            collection.AddSingleton(typeof(IRequestHandler <CreateResourceRequest, UpsertResourceResponse>), new CreateResourceHandler(_dataStore, new Lazy <IConformanceProvider>(() => provider), resourceWrapperFactory, resourceIdProvider, new ResourceReferenceResolver(_searchService, new TestQueryStringParser()), DisabledFhirAuthorizationService.Instance, _searchParameterUtilities));
            collection.AddSingleton(typeof(IRequestHandler <UpsertResourceRequest, UpsertResourceResponse>), new UpsertResourceHandler(_dataStore, new Lazy <IConformanceProvider>(() => provider), resourceWrapperFactory, resourceIdProvider, DisabledFhirAuthorizationService.Instance, ModelInfoProvider.Instance));
            collection.AddSingleton(typeof(IRequestHandler <GetResourceRequest, GetResourceResponse>), new GetResourceHandler(_dataStore, new Lazy <IConformanceProvider>(() => provider), resourceWrapperFactory, resourceIdProvider, DisabledFhirAuthorizationService.Instance));
            collection.AddSingleton(typeof(IRequestHandler <DeleteResourceRequest, DeleteResourceResponse>), new DeleteResourceHandler(_dataStore, new Lazy <IConformanceProvider>(() => provider), resourceWrapperFactory, resourceIdProvider, DisabledFhirAuthorizationService.Instance));

            ServiceProvider services = collection.BuildServiceProvider();

            Mediator = new Mediator(type => services.GetService(type));

            _deserializer = new ResourceDeserializer(
                (FhirResourceFormat.Json, new Func <string, string, DateTimeOffset, ResourceElement>((str, version, lastUpdated) => _fhirJsonParser.Parse(str).ToResourceElement())));
        }
        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), baseResourceTypes: new List <string>()
            {
                "Patient"
            });
            _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));

            _searchParameterUtilties = new SearchParameterUtilities(_manager, _searchParameterDefinitionManager, ModelInfoProvider.Instance);
        }
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.GetCapabilityStatementAsync().Returns(_conformanceStatement.ToTypedElement().ToResourceElement());
            var lazyConformanceProvider = new Lazy <IConformanceProvider>(() => _conformanceProvider);

            var collection = new ServiceCollection();

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

            _searchParameterUtilities = Substitute.For <ISearchParameterUtilities>();

            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, _searchParameterUtilities)).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 CreateSearchParameterBehavior(ISearchParameterUtilities searchParameterUtilities)
        {
            EnsureArg.IsNotNull(searchParameterUtilities, nameof(searchParameterUtilities));

            _searchParameterUtitliies = searchParameterUtilities;
        }