Skip to content

Commit

Permalink
fix: Multiple includes throws exception
Browse files Browse the repository at this point in the history
* Using IEnumerable<KeyValuePair<string, string>> instead of Dictionary
  in EntryToHttpExtensions.setBodyAndContentType
* Fixes #1206
  • Loading branch information
kennethmyhra committed Jan 10, 2020
1 parent 2cc5325 commit 5bc6864
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/Hl7.Fhir.Core.Tests/Rest/FhirClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,26 @@ private void verifyMeta(Meta meta, bool hasNew, int key)
}
}

[TestMethod]
[TestCategory("FhirClient"), TestCategory("IntegrationTest")]
public void TestSearchUsingPostMultipleIncludesShouldNotThrowArgumentException()
{
// This test case proves issue https://github.com/FirelyTeam/fhir-net-api/issues/1206 is fixed.
// Previoulsly EntryToHttpExtensions.setBodyAndContentType used a Dictionary which required the
// name part of the parameters to be unique.
// Fixed by using IEnumerable<KeyValuePair<string, string>> instead of Dictionary<string, string>
var client = new FhirClient(testEndpoint);

var sp = new SearchParams();
sp.Parameters.Add(new Tuple<string, string>("_id", "8465,8479"));
sp.Include.Add("subject");

// Add a further include
sp.Include.Add("encounter");

client.SearchUsingPost<Procedure>(sp);
}


[TestMethod]
[TestCategory("FhirClient"), TestCategory("IntegrationTest")]
Expand Down
6 changes: 3 additions & 3 deletions src/Hl7.Fhir.Core/Rest/EntryToHttpExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ private static void setBodyAndContentType(HttpWebRequest request, Resource data,
}
else if (searchUsingPost)
{
IDictionary<string, string> bodyParameters = new Dictionary<string, string>();
foreach(Parameters.ParameterComponent parameter in ((Parameters)data).Parameter)
var bodyParameters = new List<KeyValuePair<string, string>>();
foreach (Parameters.ParameterComponent parameter in ((Parameters)data).Parameter)
{
bodyParameters.Add(parameter.Name, parameter.Value.ToString());
bodyParameters.Add(new KeyValuePair<string, string>(parameter.Name, parameter.Value.ToString()));
}
if (bodyParameters.Count > 0)
{
Expand Down

0 comments on commit 5bc6864

Please sign in to comment.