Skip to content

Commit

Permalink
Test cases update
Browse files Browse the repository at this point in the history
  • Loading branch information
Shashank Narang committed Oct 28, 2024
1 parent c5e5a4f commit 6ca9e03
Showing 1 changed file with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,32 @@ public async Task GivenATransactionBundleWithConditionalReferences_WhenNotResolv
var requestBundle = Samples.GetJsonSample("Bundle-TransactionWithConditionalReferenceInResourceBody");
var bundle = requestBundle.ToPoco<Hl7.Fhir.Model.Bundle>();

IEnumerable<SearchResultEntry> searchResultEntries = Enumerable.Empty<SearchResultEntry>();

var expectedMessage = "Given conditional reference 'Patient?identifier=12345' does not resolve to a resource.";

var searchResult = new SearchResult(searchResultEntries, null, null, new Tuple<string, string>[0]);
_searchService.SearchAsync("Patient", Arg.Any<IReadOnlyList<Tuple<string, string>>>(), CancellationToken.None).Returns(searchResult);

var referenceIdDictionary = new Dictionary<string, (string resourceId, string resourceType)>();
foreach (var entry in bundle.Entry)
{
var requestUrl = (entry.Request != null) ? entry.Request.Url : null;
var exception = await Assert.ThrowsAsync<RequestNotValidException>(() => _referenceResolver.ResolveReferencesAsync(entry.Resource, referenceIdDictionary, requestUrl, CancellationToken.None));
Assert.Equal(exception.Message, expectedMessage);
}
}

[Fact]
public async Task GivenATransactionBundleWithConditionalReferences_WhenResolvedToMultipleResources_ThenRequestNotValidExceptionShouldBeThrown()
{
var requestBundle = Samples.GetJsonSample("Bundle-TransactionWithConditionalReferenceInResourceBody");
var bundle = requestBundle.ToPoco<Hl7.Fhir.Model.Bundle>();

SearchResultEntry mockSearchEntry = GetMockSearchEntry("123", KnownResourceTypes.Patient);
SearchResultEntry mockSearchEntry1 = GetMockSearchEntry("123", KnownResourceTypes.Patient);

var expectedMessage = "Given conditional reference 'Patient?identifier=12345' does not resolve to a resource.";
var expectedMessage = "Given conditional reference 'Patient?identifier=12345' resolved to multiple resources.";

var searchResult = new SearchResult(new[] { mockSearchEntry, mockSearchEntry1 }, null, null, new Tuple<string, string>[0]);
_searchService.SearchAsync("Patient", Arg.Any<IReadOnlyList<Tuple<string, string>>>(), CancellationToken.None).Returns(searchResult);
Expand Down

0 comments on commit 6ca9e03

Please sign in to comment.