예제 #1
0
        public async Task GivenResourcesWithUnchangedOrChangedIndices_WhenResultsProcessed_ThenCorrectResourcesHaveIndicesUpdated()
        {
            var searchIndexEntry1 = new SearchIndexEntry(new Core.Models.SearchParameterInfo("param1"), new StringSearchValue("value1"));
            var searchIndexEntry2 = new SearchIndexEntry(new Core.Models.SearchParameterInfo("param2"), new StringSearchValue("value2"));

            var searchIndices1 = new List <SearchIndexEntry>()
            {
                searchIndexEntry1
            };
            var searchIndices2 = new List <SearchIndexEntry>()
            {
                searchIndexEntry2
            };

            _searchIndexer.Extract(Arg.Any <Core.Models.ResourceElement>()).Returns(searchIndices1);

            var entry1 = CreateSearchResultEntry("Patient", searchIndices1);

            _output.WriteLine($"Loaded Patient with id: {entry1.Resource.ResourceId}");
            var entry2 = CreateSearchResultEntry("Observation-For-Patient-f001", searchIndices2);

            _output.WriteLine($"Loaded Observation with id: {entry2.Resource.ResourceId}");
            var resultList = new List <SearchResultEntry>();

            resultList.Add(entry1);
            resultList.Add(entry2);
            var result = new SearchResult(resultList, new List <Tuple <string, string> >(), new List <(string, string)>(), "token");

            await _reindexUtilities.ProcessSearchResultsAsync(result, _searchParameterHashMap, CancellationToken.None);

            await _fhirDataStore.Received().UpdateSearchParameterIndicesBatchAsync(
                Arg.Is <IReadOnlyCollection <ResourceWrapper> >(c => c.Count() == 2), Arg.Any <CancellationToken>());
        }
 private async Task ValidateUpdateCallBasedOnHttpMethodType(string httpMethodName)
 {
     if (httpMethodName == HttpPostName)
     {
         await _fhirDataStore.Received().UpdateSearchIndexForResourceAsync(Arg.Any <ResourceWrapper>(), Arg.Any <WeakETag>(), _cancellationToken);
     }
     else if (httpMethodName == HttpGetName)
     {
         await _fhirDataStore.DidNotReceive().UpdateSearchIndexForResourceAsync(Arg.Any <ResourceWrapper>(), Arg.Any <WeakETag>(), _cancellationToken);
     }
 }
예제 #3
0
        public async System.Threading.Tasks.Task GivenResourcesWithUnchangedOrChangedIndices_WhenResultsProcessed_ThenCorrectResourcesHaveIndicesUpdated()
        {
            Func <Health.Extensions.DependencyInjection.IScoped <IFhirDataStore> > fhirDataStoreScope = () => _fhirDataStore.CreateMockScope();
            var utilities = new ReindexUtilities(fhirDataStoreScope, _searchIndexer, _resourceDeserializer);

            var searchIndices1 = new List <SearchIndexEntry>()
            {
                new SearchIndexEntry(new Core.Models.SearchParameterInfo("param1"), new StringSearchValue("value1"))
            };
            var searchIndices2 = new List <SearchIndexEntry>()
            {
                new SearchIndexEntry(new Core.Models.SearchParameterInfo("param2"), new StringSearchValue("value2"))
            };

            _searchIndexer.Extract(Arg.Any <Core.Models.ResourceElement>()).Returns(searchIndices1);

            var entry1 = CreateSearchResultEntry("Patient", searchIndices1);

            _output.WriteLine($"Loaded Patient with id: {entry1.Resource.ResourceId}");
            var entry2 = CreateSearchResultEntry("Observation-For-Patient-f001", searchIndices2);

            _output.WriteLine($"Loaded Observation with id: {entry2.Resource.ResourceId}");
            var resultList = new List <SearchResultEntry>();

            resultList.Add(entry1);
            resultList.Add(entry2);
            var result = new SearchResult(resultList, new List <Tuple <string, string> >(), new List <(string, string)>(), "token");

            await utilities.ProcessSearchResultsAsync(result, "hash", CancellationToken.None);

            await _fhirDataStore.Received().UpdateSearchParameterHashBatchAsync(
                Arg.Is <IReadOnlyCollection <ResourceWrapper> >(
                    c => c.Where(r => r.SearchIndices == searchIndices1 && r.ResourceTypeName.Equals("Patient")).Count() == 1),
                Arg.Any <CancellationToken>());

            await _fhirDataStore.Received().UpdateSearchParameterIndicesBatchAsync(
                Arg.Is <IReadOnlyCollection <ResourceWrapper> >(
                    c => c.Where(r => r.SearchIndices == searchIndices1 && r.ResourceTypeName.Equals("Observation")).Count() == 1),
                Arg.Any <CancellationToken>());
        }
예제 #4
0
        public async Task GivenAFhirMediator_GettingAnResourceThatDoesntExist_ThenANotFoundExceptionIsThrown()
        {
            await Assert.ThrowsAsync <ResourceNotFoundException>(async() => await _mediator.GetResourceAsync(new ResourceKey <Observation>("id1")));

            await _fhirDataStore.Received().GetAsync(Arg.Any <ResourceKey>(), Arg.Any <CancellationToken>());
        }