Skip to content

Commit

Permalink
A few missed unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoutkramer committed Nov 25, 2024
1 parent 493ff14 commit ce8c7b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
27 changes: 12 additions & 15 deletions src/Hl7.Fhir.Support.Poco.Tests/Model/PocoDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ public void DynamicResourceAcceptsEverything()
{
var dr = new DynamicResource()
{
["name"] = "John",
["age"] = 23,
["alive"] = true,
["dob"] = new Date(1972, 11, 30),
["name"] = new FhirString("John"),
#pragma warning disable CA2244
["weight"] = 75.5m,
["weight"] = new FhirDecimal(75.5m),
#pragma warning restore CA2244
["weight"] = 80.0m
["weight"] = new FhirDecimal(80.0m),
["someArray"] = new List<FhirString> { new("element") }
};

dr["name"].Should().Be("John");
dr["age"].Should().Be(23);
dr["alive"].Should().Be(true);
dr["dob"].Should().BeOfType<Date>().Which.Value.Should().Be("1972-11-30");
dr["weight"].Should().Be(80.0m);
dr["name"].Should().BeOfType<FhirString>().Which.Value.Should().Be("John");
dr["weight"].Should().BeOfType<FhirDecimal>().Which.Value.Should().Be(80.0m);
dr["someArray"].Should().BeAssignableTo<IReadOnlyList<FhirString>>()
.Which.Count.Should().Be(1);

dr["name"] = null!;
dr.TryGetValue("name", out _).Should().BeFalse();
Expand Down Expand Up @@ -69,11 +66,11 @@ public void CanReadSpecialProperties()

patient.AddExtension("http://nu.nl", new FhirBoolean(true));

patient["active"].Should().BeOfType<FhirBoolean>().And
.BeAssignableTo<Base>().Which["value"].Should().Be(true);
patient["active"].Should().BeOfType<FhirBoolean>().
Which.ObjectValue.Should().Be(true);
patient["text"].Should().BeOfType<Narrative>().And
.BeAssignableTo<Base>().Which["div"].Should().BeOfType<XHtml>().And
.BeAssignableTo<Base>().Which["value"].Should().Be("<div>hello</div>");
.BeAssignableTo<Base>().Which["div"].Should().BeOfType<XHtml>()
.Which.ObjectValue.Should().Be("<div>hello</div>");
patient["meta"].Should().BeOfType<Meta>().And
.BeAssignableTo<Base>().Which["id"].Should().Be("4");
var extension = patient["extension"].Should().BeOfType<List<Extension>>().Which.Should().ContainSingle().Subject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ public void SerializesInvalidData()
{
var options = new JsonSerializerOptions().ForFhir(typeof(Patient).Assembly);

FhirBoolean b = new() { ObjectValue = "treu" };
var jdoc = JsonDocument.Parse(JsonSerializer.Serialize(b, options));
Assert.AreEqual("treu", jdoc.RootElement.GetProperty("value").GetString());
var b = new FhirBoolean() { ObjectValue = "treu" };
var pInvalid = new Patient { ActiveElement = b };

Patient p = new() { Contact = new() { new Patient.ContactComponent() } };
var jdoc = JsonDocument.Parse(JsonSerializer.Serialize(pInvalid, options));
Assert.AreEqual("treu", jdoc.RootElement
.GetProperty("active").GetString());

Patient p = new() { Contact = [new Patient.ContactComponent()] };
jdoc = JsonDocument.Parse(JsonSerializer.Serialize(p, options));
var contactArray = jdoc.RootElement.GetProperty("contact");
contactArray.GetArrayLength().Should().Be(1);
Expand Down

0 comments on commit ce8c7b2

Please sign in to comment.