Пример #1
0
        public void GivenAnEmptySearchResult_WhenCreateSearchBundle_ThenCorrectBundleShouldBeReturned()
        {
            _urlResolver.ResolveRouteUrl(_unsupportedSearchParameters).Returns(_selfUrl);

            ResourceElement actual = null;

            using (Mock.Property(() => ClockResolver.UtcNowFunc, () => _dateTime))
            {
                actual = _bundleFactory.CreateSearchBundle(new SearchResult(new SearchResultEntry[0], null, null, _unsupportedSearchParameters));
            }

            Assert.NotNull(actual);
            Assert.Equal(Bundle.BundleType.Searchset.ToString().ToLowerInvariant(), actual.Scalar <string>("Bundle.type"));
            Assert.Equal(_correlationId.ToString(), actual.Id);
            Assert.Equal(_dateTime, actual.LastUpdated);
            Assert.Equal(_selfUrl.OriginalString, actual.Scalar <string>("Bundle.link.where(relation='self').url"));
        }
Пример #2
0
        public void GivenASearchResult_WhenCreateSearchBundle_ThenCorrectBundleShouldBeReturned()
        {
            _urlResolver.ResolveResourceWrapperUrl(Arg.Any <ResourceWrapper>()).Returns(x => new Uri(string.Format(_resourceUrlFormat, x.ArgAt <ResourceWrapper>(0).ResourceId)));
            _urlResolver.ResolveRouteUrl(_unsupportedSearchParameters).Returns(_selfUrl);

            ResourceElement observation1 = Samples.GetDefaultObservation().UpdateId("123");
            ResourceElement observation2 = Samples.GetDefaultObservation().UpdateId("abc");

            var resourceWrappers = new SearchResultEntry[]
            {
                new SearchResultEntry(CreateResourceWrapper(observation1, HttpMethod.Post)),
                new SearchResultEntry(CreateResourceWrapper(observation2, HttpMethod.Post)),
            };

            var searchResult = new SearchResult(resourceWrappers, continuationToken: null, sortOrder: null, unsupportedSearchParameters: _unsupportedSearchParameters);

            ResourceElement actual = null;

            using (Mock.Property(() => ClockResolver.UtcNowFunc, () => _dateTime))
            {
                actual = _bundleFactory.CreateSearchBundle(searchResult);
            }

            // Since there is no continuation token, there should not be next link.
            Assert.Null(actual.Scalar <string>("Bundle.link.where(relation='next').url"));
            Assert.Collection(
                actual.ToPoco <Bundle>().Entry,
                async e => await ValidateEntry(observation1.ToPoco <Observation>(), e),
                async e => await ValidateEntry(observation2.ToPoco <Observation>(), e));

            async Task ValidateEntry(Observation expected, Bundle.EntryComponent actualEntry)
            {
                Assert.NotNull(actualEntry);

                var raw = actualEntry as RawBundleEntryComponent;

                using (var ms = new MemoryStream())
                    using (var sr = new StreamReader(ms))
                    {
                        await raw?.ResourceElement?.SerializeToStreamAsUtf8Json(ms);

                        ms.Seek(0, SeekOrigin.Begin);
                        var resourceData = await sr.ReadToEndAsync();

                        Assert.NotNull(resourceData);

                        Resource resource;
                        resource = new FhirJsonParser().Parse(resourceData) as Resource;

                        Assert.Equal(expected.Id, resource.Id);
                        Assert.Equal(string.Format(_resourceUrlFormat, expected.Id), raw.FullUrl);
                        Assert.NotNull(raw.Search);
                        Assert.Equal(Bundle.SearchEntryMode.Match, raw.Search.Mode);
                    }
            }
        }
Пример #3
0
        public async Task GivenAFhirMediator_WhenConfiguredWithoutReadHistory_ThenReturnsPatientWithLatestVersion()
        {
            var birthDateProp  = "Patient.BirthDate";
            var genderDateProp = "Patient.Gender";

            var patient = Samples.GetDefaultPatient();

            var latest = CreateMockResourceWrapper(patient, false);

            latest.IsHistory.Returns(false);

            _fhirDataStore.GetAsync(Arg.Is <ResourceKey>(x => x.Id == "readDataPatient"), Arg.Any <CancellationToken>()).Returns(latest);

            ResourceElement result = await _mediator.GetResourceAsync(new ResourceKey("Patient", "readDataPatient", "latest"));

            Assert.NotNull(result);
            Assert.Equal(patient.Scalar <string>(birthDateProp), result.Scalar <string>(birthDateProp));
            Assert.Equal(patient.Scalar <string>(genderDateProp), result.Scalar <string>(genderDateProp));
        }
Пример #4
0
        public void GivenASearchResultWithContinuationToken_WhenCreateSearchBundle_ThenCorrectBundleShouldBeReturned()
        {
            _urlResolver.ResolveRouteUrl(_unsupportedSearchParameters, _continuationToken).Returns(_nextUrl);
            _urlResolver.ResolveRouteUrl(_unsupportedSearchParameters).Returns(_selfUrl);

            var searchResult = new SearchResult(new ResourceWrapper[0], _unsupportedSearchParameters, _continuationToken);

            ResourceElement actual = _bundleFactory.CreateSearchBundle(searchResult);

            // Since there is no continuation token, there should not be next link.
            Assert.Equal(_nextUrl.OriginalString, actual.Scalar <string>("Bundle.link.where(relation='next').url"));
        }
Пример #5
0
        public void GivenASearchResult_WhenCreateSearchBundle_ThenCorrectBundleShouldBeReturned()
        {
            _urlResolver.ResolveResourceUrl(Arg.Any <ResourceElement>()).Returns(x => new Uri(string.Format(_resourceUrlFormat, x.ArgAt <ResourceElement>(0).Id)));
            _urlResolver.ResolveRouteUrl(_unsupportedSearchParameters).Returns(_selfUrl);

            ResourceElement observation1 = Samples.GetDefaultObservation().UpdateId("123");
            ResourceElement observation2 = Samples.GetDefaultObservation().UpdateId("abc");

            var resourceWrappers = new ResourceWrapper[]
            {
                CreateResourceWrapper(observation1),
                CreateResourceWrapper(observation2),
            };

            var searchResult = new SearchResult(resourceWrappers, _unsupportedSearchParameters, continuationToken: null);

            ResourceElement actual = null;

            using (Mock.Property(() => Clock.UtcNowFunc, () => _dateTime))
            {
                actual = _bundleFactory.CreateSearchBundle(searchResult);
            }

            // Since there is no continuation token, there should not be next link.
            Assert.Null(actual.Scalar <string>("Bundle.link.where(relation='next').url"));
            Assert.Collection(
                actual.ToPoco <Bundle>().Entry,
                e => ValidateEntry(observation1.ToPoco <Observation>(), e),
                e => ValidateEntry(observation2.ToPoco <Observation>(), e));

            ResourceWrapper CreateResourceWrapper(ResourceElement resourceElement)
            {
                return(new ResourceWrapper(
                           resourceElement,
                           new RawResource(_fhirJsonSerializer.SerializeToString(resourceElement.ToPoco <Observation>()), FhirResourceFormat.Json),
                           null,
                           false,
                           null,
                           null,
                           null));
            }

            void ValidateEntry(Observation expected, Bundle.EntryComponent actualEntry)
            {
                Assert.NotNull(actualEntry);
                Assert.NotNull(actualEntry.Resource);
                Assert.Equal(expected.Id, actualEntry.Resource.Id);
                Assert.Equal(string.Format(_resourceUrlFormat, expected.Id), actualEntry.FullUrl);
                Assert.NotNull(actualEntry.Search);
                Assert.Equal(Bundle.SearchEntryMode.Match, actualEntry.Search.Mode);
            }
        }
Пример #6
0
        public void GivenASearchResultWithContinuationToken_WhenCreateSearchBundle_ThenCorrectBundleShouldBeReturned()
        {
            string encodedContinuationToken = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(_continuationToken));

            _urlResolver.ResolveRouteUrl(_unsupportedSearchParameters, null, encodedContinuationToken, true).Returns(_nextUrl);
            _urlResolver.ResolveRouteUrl(_unsupportedSearchParameters).Returns(_selfUrl);

            var searchResult = new SearchResult(new SearchResultEntry[0], _continuationToken, null, _unsupportedSearchParameters);

            ResourceElement actual = _bundleFactory.CreateSearchBundle(searchResult);

            Assert.Equal(_nextUrl.OriginalString, actual.Scalar <string>("Bundle.link.where(relation='next').url"));
        }