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 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); }
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 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 void GivenACapabilityStatement_WhenSupportingAcceptUnknown_ThenThrowsNotSupportedException() { var supported = GetMockedListedCapabilityStatement(); supported.AcceptUnknown = new[] { UnknownContentCode.Extensions }; var configured = CapabilityStatementMock.GetMockedCapabilityStatement(); configured.AcceptUnknown = UnknownContentCode.Both; Assert.Throws <UnsupportedConfigurationException>(() => supported.Intersect(configured, strictConfig: true)); }
public void GivenACapabilityStatement_WhenSupportingNoSearchParamConfiguringSearchParam_ThenNotSupportedExceptionIsThrown() { var supported = GetMockedListedCapabilityStatement(); supported.TryAddSearchParams(ResourceType.Account, new List <SearchParamComponent>()); var configured = CapabilityStatementMock.GetMockedCapabilityStatement(); CapabilityStatementMock.SetupMockResource(configured, ResourceType.Account, null, GetSearchParamCollection()); Assert.Throws <UnsupportedConfigurationException>(() => supported.Intersect(configured, strictConfig: true)); }
public void GivenACapabilityStatement_WhenSupportingCreateConfiguringCreateAndDelete_ThenNotSupportedExceptionIsThrown() { var supported = GetMockedListedCapabilityStatement(); supported.TryAddRestInteraction(ResourceType.Account, TypeRestfulInteraction.Create); var configured = CapabilityStatementMock.GetMockedCapabilityStatement(); CapabilityStatementMock.SetupMockResource(configured, ResourceType.Account, new[] { TypeRestfulInteraction.Create, TypeRestfulInteraction.Delete }); Assert.Throws <UnsupportedConfigurationException>(() => supported.Intersect(configured, strictConfig: true)); }
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)); }
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); }
public void GivenACapabilityStatement_WhenSupportingSearchParamConfiguringNone_ThenResultIsCorrectlyIntersected() { var supported = GetMockedListedCapabilityStatement(); supported.TryAddSearchParams(ResourceType.Account, GetSearchParamCollection()); var configured = CapabilityStatementMock.GetMockedCapabilityStatement(); CapabilityStatementMock.SetupMockResource(configured, ResourceType.Account, null); var result = supported.Intersect(configured, strictConfig: true); Assert.Empty(result.Rest.Single().Resource.First().SearchParam); }
public void GivenACapabilityStatement_WhenDatesArePresent_ThenLatestDateIsSelected() { var supported = GetMockedListedCapabilityStatement(); var date = DateTimeOffset.Parse("2000-01-01").ToString("o", CultureInfo.InvariantCulture); var configured = CapabilityStatementMock.GetMockedCapabilityStatement(); configured.Date = date; var result = supported.Intersect(configured, strictConfig: true); Assert.NotNull(result.Date); Assert.Equal(date, result.Date); }
public FhirStorageTests(FhirStorageTestsFixture fixture) { IFhirDataStore 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); // 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 <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, Deserializers.ResourceDeserializer)); collection.AddSingleton(typeof(IRequestHandler <DeleteResourceRequest, DeleteResourceResponse>), new DeleteResourceHandler(dataStore, new Lazy <IConformanceProvider>(() => provider), resourceWrapperFactory)); collection.AddSingleton(typeof(IRequestHandler <CreateExportRequest, CreateExportResponse>), new CreateExportRequestHandler(dataStore)); collection.AddSingleton(typeof(IRequestHandler <GetExportRequest, GetExportResponse>), new GetExportRequestHandler(dataStore)); ServiceProvider services = collection.BuildServiceProvider(); Mediator = new Mediator(type => services.GetService(type)); }
public void GivenACapabilityStatement_WhenSupportingXmlJsonAndConfiguringJson_ThenResultIsCorrectlyIntersected() { var supported = GetMockedListedCapabilityStatement(); supported.Format = new[] { "json", "xml" }.ToList(); var configured = CapabilityStatementMock.GetMockedCapabilityStatement(); configured.Format = new[] { "json" }.ToList(); var result = supported.Intersect(configured, strictConfig: true); Assert.Equal("json", result.Format.Single()); }
public void GivenACapabilityStatement_WhenSupportingAcceptUnknownExtensionsAndBothButNotBothStrict_ThenReturnsExtensions() { var supported = GetMockedListedCapabilityStatement(); supported.AcceptUnknown = new[] { UnknownContentCode.Extensions, UnknownContentCode.Both }; var configured = CapabilityStatementMock.GetMockedCapabilityStatement(); configured.AcceptUnknown = UnknownContentCode.Extensions; var result = supported.Intersect(configured, strictConfig: true); Assert.NotNull(result); Assert.Equal(UnknownContentCode.Extensions, result.AcceptUnknown); }
public void GivenACapabilityStatement_WhenSupportingAccountObservationAndConfiguringObservation_ThenResultIsCorrectlyIntersected() { var supported = GetMockedListedCapabilityStatement(); supported.TryAddRestInteraction(ResourceType.Account, TypeRestfulInteraction.Create); supported.TryAddRestInteraction(ResourceType.Observation, TypeRestfulInteraction.Create); var configured = CapabilityStatementMock.GetMockedCapabilityStatement(); CapabilityStatementMock.SetupMockResource(configured, ResourceType.Account, new[] { TypeRestfulInteraction.Create }); var result = supported.Intersect(configured, strictConfig: true); Assert.Single(result.Rest.Single().Resource); Assert.Single(result.Rest.Single().Resource.Single().Interaction); Assert.Equal(TypeRestfulInteraction.Create, result.Rest.Single().Resource.Single().Interaction.Single().Code); }
public void GivenACapabilityStatement_WhenSupportingCreateConfiguringCreateAndDeleteWithNotStrictIntersect_ThenOnlyCreateIsReturned() { var supported = GetMockedListedCapabilityStatement(); supported.TryAddRestInteraction(ResourceType.Account, TypeRestfulInteraction.Create); var configured = CapabilityStatementMock.GetMockedCapabilityStatement(); CapabilityStatementMock.SetupMockResource(configured, ResourceType.Account, new[] { TypeRestfulInteraction.Create, TypeRestfulInteraction.Delete }); var result = supported.Intersect(configured, strictConfig: false); Assert.NotNull(result); Assert.Single(result.Rest.Single().Resource); Assert.Single(result.Rest.Single().Resource.Single().Interaction); Assert.Equal(TypeRestfulInteraction.Create, result.Rest.Single().Resource.Single().Interaction.Single().Code); }
public void GivenACapabilityStatement_WhenIntersectingResourceProfiles_ThenConfiguredInteractionDocoOverridesDefault() { var doco = "Make stuff"; var supported = GetMockedListedCapabilityStatement(); supported.TryAddRestInteraction(ResourceType.Observation, TypeRestfulInteraction.Create); var configured = CapabilityStatementMock.GetMockedCapabilityStatement(); CapabilityStatementMock.SetupMockResource(configured, ResourceType.Observation, new[] { TypeRestfulInteraction.Create }); configured.Rest.Single().Resource.Single().Interaction.Single().Documentation = "Make stuff"; var result = supported.Intersect(configured, strictConfig: true); Assert.Equal(doco, result.Rest.Single().Resource.Single().Interaction.Single().Documentation); }
public void GivenACapabilityStatement_WhenIntersectingResourceProfiles_ThenConfiguredOverridesDefault() { var referenceUrl = "https://bing.com/"; var supported = GetMockedListedCapabilityStatement(); supported.TryAddRestInteraction(ResourceType.Observation, TypeRestfulInteraction.Create); var configured = CapabilityStatementMock.GetMockedCapabilityStatement(); CapabilityStatementMock.SetupMockResource(configured, ResourceType.Observation, new[] { TypeRestfulInteraction.Create }); configured.Rest.Single().Resource.Single().Profile = new ResourceReference("https://bing.com/"); var result = supported.Intersect(configured, strictConfig: true); Assert.Equal(referenceUrl, result.Rest.Single().Resource.Single().Profile.Url.ToString()); }
public async Task GivenMultipleProviders_WhenRequestingAMergedCapabilitiesDocument_ThenGetsAValidCapabilityStatement() { SystemConformanceProvider systemCapabilities = CreateSystemConformanceProvider(); var mockedCapabilities = CapabilityStatementMock.GetMockedCapabilityStatement(); CapabilityStatementMock.SetupMockResource(mockedCapabilities, ResourceType.Account, new[] { CapabilityStatement.TypeRestfulInteraction.Create, CapabilityStatement.TypeRestfulInteraction.Read }); var configured = Substitute.For <IConfiguredConformanceProvider>(); configured .GetCapabilityStatementAsync() .Returns(mockedCapabilities.ToResourceElement()); var urlResolver = Substitute.For <IUrlResolver>(); urlResolver.ResolveMetadataUrl(Arg.Any <bool>()).Returns(new Uri("http://localhost/metadata")); var config = new ConformanceConfiguration() { UseStrictConformance = true, }; var provider = new ConformanceProvider( systemCapabilities, configured, urlResolver, Options.Create(config)); var typedCapabilityStatement = await provider.GetCapabilityStatementAsync(); var capabilityStatement = typedCapabilityStatement.ToPoco <CapabilityStatement>(); Assert.NotNull(capabilityStatement.Software); Assert.Equal("Microsoft FHIR Server", capabilityStatement.Software.Name); Assert.Equal("Microsoft Corporation", capabilityStatement.Publisher); Assert.NotNull(capabilityStatement.Rest.Single().Resource.Single().Interaction.FirstOrDefault(x => x.Code == CapabilityStatement.TypeRestfulInteraction.Create)); Assert.NotNull(capabilityStatement.Rest.Single().Resource.Single().Interaction.FirstOrDefault(x => x.Code == CapabilityStatement.TypeRestfulInteraction.Read)); }
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)); }); FhirRepository = new FhirRepository(dataStore, new Lazy <IConformanceProvider>(() => provider), _resourceWrapperFactory); }