Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsmits committed Nov 21, 2024
1 parent 413a374 commit cb9cd6a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ public Parameters Build()
{
var result = new Parameters();

if (Url is { }) result.Add(_urlAttribute, Url); //Either Url, ValueSet or Context is allowed. So try Url first.
if (ValueSet is { } && Url is not { }) result.Add(_valueSetAttribute, ValueSet);
if (Context is { } && ValueSet is not { } && Url is not { }) result.Add(_contextAttribute, Context); //And then context as last resort.
if (Url is { }) result.Add(_urlAttribute, Url);
if (ValueSet is { }) result.Add(_valueSetAttribute, ValueSet);
if (Context is { }) result.Add(_contextAttribute, Context);
if (ValueSetVersion is { }) result.Add(_valueSetVersionAttribute, ValueSetVersion);
if (Code is { }) result.Add(_codeAttribute, Code);
if (System is { }) result.Add(_systemAttribute, System);
Expand All @@ -176,7 +176,7 @@ public Parameters Build()
if (CodeableConcept is { }) result.Add(_codeableConceptAttribute, CodeableConcept);
if (Date is { }) result.Add(_dateAttribute, Date);
if (Abstract is { }) result.Add(_abstractAttribute, Abstract);
if (DisplayLanguage is { }) result.Add(_displayAttribute, DisplayLanguage);
if (DisplayLanguage is { }) result.Add(_displayLanguageAttribute, DisplayLanguage);
if (InferSystem is { }) result.Add(_inferSystemAttribute, InferSystem);
return result;
}
Expand Down
46 changes: 46 additions & 0 deletions src/Hl7.Fhir.Specification.Shared.Tests/Source/TerminologyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,52 @@ void expandAction(string url)
}
}

[Fact]
public void TestValidateCodeParametersCode()
{
var parameters = new ValidateCodeParameters()
.WithCode("bar", "http://foo.com", "1.0.4", "barDisplay", "nl-NL", "Patient.gender", true);

parameters.Code.Value.Should().Be("bar");
parameters.System.Value.Should().Be("http://foo.com");
parameters.SystemVersion.Value.Should().Be("1.0.4");
parameters.DisplayLanguage.Value.Should().Be("nl-NL");
parameters.Display.Value.Should().Be("barDisplay");
parameters.Context.Value.Should().Be("Patient.gender");
parameters.InferSystem.Value.Should().Be(true);

var paramResource = parameters.Build();

paramResource.Parameter.Should().HaveCount(7);
paramResource.Parameter.Should().ContainSingle(p => p.Name == "code" && ((Code)p.Value).Value == "bar");
paramResource.Parameter.Should().ContainSingle(p => p.Name == "system" && ((FhirUri)p.Value).Value == "http://foo.com");
paramResource.Parameter.Should().ContainSingle(p => p.Name == "systemVersion" && ((FhirString)p.Value).Value == "1.0.4");
paramResource.Parameter.Should().ContainSingle(p => p.Name == "display" && ((FhirString)p.Value).Value == "barDisplay");
paramResource.Parameter.Should().ContainSingle(p => p.Name == "displayLanguage" && ((Code)p.Value).Value == "nl-NL");
paramResource.Parameter.Should().ContainSingle(p => p.Name == "context" && ((FhirUri)p.Value).Value == "Patient.gender");
paramResource.Parameter.Should().ContainSingle(p => p.Name == "inferSystem" && ((FhirBoolean)p.Value).Value == true);
}

[Fact]
public void TestValidateCodeParametersValueSet()
{
var parameters = new ValidateCodeParameters()
.WithValueSet("http://foo.bar", "Patient.gender", new ValueSet(), "1.0.4");

parameters.Url.Value.Should().Be("http://foo.bar");
parameters.Context.Value.Should().Be("Patient.gender");
parameters.ValueSet.Should().NotBeNull();
parameters.ValueSetVersion.Value.Should().Be("1.0.4");

var paramResource = parameters.Build();

paramResource.Parameter.Should().HaveCount(4);
paramResource.Parameter.Should().ContainSingle(p => p.Name == "url" && ((FhirUri)p.Value).Value == "http://foo.bar");
paramResource.Parameter.Should().ContainSingle(p => p.Name == "context" && ((FhirUri)p.Value).Value == "Patient.gender");
paramResource.Parameter.Should().ContainSingle(p => p.Name == "valueSet" && ((ValueSet)p.Resource) != null);
paramResource.Parameter.Should().ContainSingle(p => p.Name == "valueSetVersion" && ((FhirString)p.Value).Value == "1.0.4");
}


#region helper functions
private static Tasks.Task<Parameters> validateCodedValue(ITerminologyService service, string url = null, string context = null, string code = null,
Expand Down

0 comments on commit cb9cd6a

Please sign in to comment.