public ListSearchBehaviorTests()
        {
            _cancellationToken = _cancellationTokenSource.Token;

            var so = new SearchOptions();

            so.UnsupportedSearchParams = new Tuple <string, string> [0];

            _searchOptionsFactory = Substitute.For <ISearchOptionsFactory>();
            _searchOptionsFactory.Create(Arg.Any <string>(), Arg.Any <IReadOnlyList <Tuple <string, string> > >()).Returns(so);

            _fhirDataStore = Substitute.For <IFhirDataStore>();

            // for an 'existing list' return a list with Patients
            _fhirDataStore.GetAsync(Arg.Is <ResourceKey>(x => x.Id == "existing-list"), Arg.Any <CancellationToken>()).Returns(
                x =>
            {
                var longList           = Samples.GetDefaultList();
                var rawResourceFactory = new RawResourceFactory(new FhirJsonSerializer());
                return(new ResourceWrapper(
                           longList,
                           rawResourceFactory.Create(longList, keepMeta: true),
                           new ResourceRequest(HttpMethod.Post, "http://fhir"),
                           false,
                           null,
                           null,
                           null));
            });

            _scopedDataStore = Substitute.For <IScoped <IFhirDataStore> >();
            _scopedDataStore.Value.Returns(_fhirDataStore);

            _nonEmptyBundle = new Bundle
            {
                Type  = Bundle.BundleType.Batch,
                Entry = new List <Bundle.EntryComponent>
                {
                    new Bundle.EntryComponent
                    {
                        Resource = Samples.GetDefaultObservation().ToPoco(),
                        Request  = new Bundle.RequestComponent
                        {
                            Method = Bundle.HTTPVerb.POST,
                            Url    = "Observation",
                        },
                    },
                    new Bundle.EntryComponent
                    {
                        Request = new Bundle.RequestComponent
                        {
                            Method = Bundle.HTTPVerb.GET,
                            Url    = "Patient?name=peter",
                        },
                    },
                },
            }.ToResourceElement();

            _bundleFactory = Substitute.For <IBundleFactory>();
            _bundleFactory.CreateSearchBundle(Arg.Any <SearchResult>()).Returns(_nonEmptyBundle);
        }
Beispiel #2
0
        public SearchServiceTests()
        {
            _searchOptionsFactory.Create(Arg.Any <string>(), Arg.Any <IReadOnlyList <Tuple <string, string> > >())
            .Returns(x => new SearchOptions());

            _searchService      = new TestSearchService(_searchOptionsFactory, _fhirDataStore);
            _rawResourceFactory = new RawResourceFactory(new FhirJsonSerializer());
        }
        public SearchServiceTests()
        {
            _bundleFactory = new BundleFactory(_urlResolver, _fhirRequestContextAccessor, Deserializers.ResourceDeserializer);
            _fhirDataStore = Substitute.For <IFhirDataStore>();

            _searchOptionsFactory.Create(Arg.Any <string>(), Arg.Any <IReadOnlyList <Tuple <string, string> > >())
            .Returns(x => new SearchOptions());

            _searchService      = new TestSearchService(_searchOptionsFactory, _bundleFactory, _fhirDataStore);
            _rawResourceFactory = new RawResourceFactory(new FhirJsonSerializer());

            _urlResolver.ResolveRouteUrl(Arg.Any <IEnumerable <Tuple <string, string> > >()).Returns(SearchUrl);

            _correlationId = Guid.NewGuid().ToString();
            _fhirRequestContextAccessor.FhirRequestContext.CorrelationId.Returns(_correlationId);
        }
        public void GivenAResource_WhenCreatingARawResource_ThenTheObjectPassInIsNotModified()
        {
            var serializer         = new FhirJsonSerializer();
            var rawResourceFactory = new RawResourceFactory(serializer);

            string versionId   = Guid.NewGuid().ToString();
            var    observation = Samples.GetDefaultObservation()
                                 .UpdateVersion(versionId);

            Assert.NotNull(observation.VersionId);

            var raw = rawResourceFactory.Create(observation);

            Assert.NotNull(raw.Data);
            Assert.Equal(versionId, observation.VersionId);
        }
        public void GivenAResource_WhenCreateARawResourceWithKeepMetaFalse_ThenTheObjectPassedInIsModified()
        {
            var serializer         = new FhirJsonSerializer();
            var rawResourceFactory = new RawResourceFactory(serializer);

            string versionId   = Guid.NewGuid().ToString();
            var    observation = Samples.GetDefaultObservation()
                                 .UpdateVersion(versionId);

            Assert.NotNull(observation.VersionId);

            var raw = rawResourceFactory.Create(observation, keepMeta: false);

            Assert.NotNull(raw.Data);

            var parser = new FhirJsonParser(DefaultParserSettings.Settings);

            var deserialized = parser.Parse <Observation>(raw.Data);

            Assert.NotNull(deserialized);
            Assert.Null(deserialized.VersionId);
            Assert.Null(deserialized.Meta?.LastUpdated);
        }
Beispiel #6
0
 public ResourceWrapperTests()
 {
     _rawResourceFactory = new RawResourceFactory(new FhirJsonSerializer());
 }