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 BundleHandlerTests() { _router = Substitute.For <IRouter>(); _fhirRequestContext = new DefaultFhirRequestContext { BaseUri = new Uri("https://localhost/"), CorrelationId = Guid.NewGuid().ToString(), ResponseHeaders = new HeaderDictionary(), }; var fhirRequestContextAccessor = Substitute.For <RequestContextAccessor <IFhirRequestContext> >(); fhirRequestContextAccessor.RequestContext.Returns(_fhirRequestContext); IHttpContextAccessor httpContextAccessor = Substitute.For <IHttpContextAccessor>(); var fhirJsonSerializer = new FhirJsonSerializer(); var fhirJsonParser = new FhirJsonParser(); ISearchService searchService = Substitute.For <ISearchService>(); var resourceReferenceResolver = new ResourceReferenceResolver(searchService, new QueryStringParser()); var transactionBundleValidator = new TransactionBundleValidator(resourceReferenceResolver); var 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>(); var resourceIdProvider = new ResourceIdProvider(); IAuditEventTypeMapping auditEventTypeMapping = Substitute.For <IAuditEventTypeMapping>(); _bundleConfiguration = new BundleConfiguration(); var bundleOptions = Substitute.For <IOptions <BundleConfiguration> >(); bundleOptions.Value.Returns(_bundleConfiguration); _mediator = Substitute.For <IMediator>(); _bundleHandler = new BundleHandler( httpContextAccessor, fhirRequestContextAccessor, fhirJsonSerializer, fhirJsonParser, transactionHandler, bundleHttpContextAccessor, resourceIdProvider, transactionBundleValidator, resourceReferenceResolver, auditEventTypeMapping, bundleOptions, DisabledFhirAuthorizationService.Instance, _mediator, NullLogger <BundleHandler> .Instance); }
public ResourceReferenceResolverTests() { _referenceResolver = new ResourceReferenceResolver(_searchService, new TestQueryStringParser()); }
public TransactionBundleValidator(ResourceReferenceResolver referenceResolver) { EnsureArg.IsNotNull(referenceResolver, nameof(referenceResolver)); _referenceResolver = referenceResolver; }