Ejemplo n.º 1
0
        private async Task <bool> IsFormatSupportedAsync(ResourceFormat resourceFormat)
        {
            if (_supportedFormats.TryGetValue(resourceFormat, out var isSupported))
            {
                return(isSupported);
            }

            ResourceElement typedStatement = await _conformanceProvider.GetCapabilityStatementOnStartup();

            IEnumerable <string> formats = typedStatement.Select("CapabilityStatement.format").Select(x => (string)x.Value);

            return(_supportedFormats.GetOrAdd(resourceFormat, format =>
            {
                switch (resourceFormat)
                {
                case ResourceFormat.Json:
                    return formats.Any(f => f.Contains("json", StringComparison.Ordinal));

                case ResourceFormat.Xml:
                    return formats.Any(f => f.Contains("xml", StringComparison.Ordinal));

                default:
                    return false;
                }
            }));
        }
Ejemplo n.º 2
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 ValidateCapabilityPreProcessorTests()
        {
            var statement = CapabilityStatementMock.GetMockedCapabilityStatement();
            CapabilityStatementMock.SetupMockResource(statement, ResourceType.Observation, interactions: new[] { TypeRestfulInteraction.Read });

            _conformanceProvider = Substitute.For<ConformanceProviderBase>();
            _conformanceProvider.GetCapabilityStatementOnStartup().Returns(statement.ToTypedElement().ToResourceElement());
        }
        public ValidateContentTypeFilterAttributeTests()
        {
            _statement = new CapabilityStatement
            {
                Format = new List <string> {
                    "json"
                },
            };

            _conformanceProvider = Substitute.For <IConformanceProvider>();
            _conformanceProvider.GetCapabilityStatementOnStartup().Returns(_statement.ToTypedElement().ToResourceElement());
        }
Ejemplo n.º 5
0
        public async void GivenCoreConfigWithVersioningPolicy_WhenCheckingIfKeepHistory_ThenCorrectValueIsReturned(ResourceVersionPolicy versioningPolicy, bool expectedKeepHistory)
        {
            const ResourceType resourceType = ResourceType.Patient;

            CapabilityStatement statement = CapabilityStatementMock.GetMockedCapabilityStatement();

            CapabilityStatementMock.SetupMockResource(statement, resourceType, null, null, versioningPolicy);

            _conformanceProvider.GetCapabilityStatementOnStartup().Returns(statement.ToResourceElement());

            bool actualKeepHistory = await _conformanceProvider.CanKeepHistory(resourceType.ToString(), CancellationToken.None);

            Assert.Equal(expectedKeepHistory, actualKeepHistory);
        }