From 08b71759069b959c78ddb8f7108b53c861a7078e Mon Sep 17 00:00:00 2001 From: Kasdejong Date: Tue, 20 Feb 2024 15:05:27 +0100 Subject: [PATCH] Added test for duplicate choice type properties (eg deceasedBoolean and deceasedDateTime both set) --- .../FhirJsonDeserializationTests.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/Hl7.Fhir.Support.Poco.Tests/NewPocoSerializers/FhirJsonDeserializationTests.cs b/src/Hl7.Fhir.Support.Poco.Tests/NewPocoSerializers/FhirJsonDeserializationTests.cs index c260040a74..c0f074697d 100644 --- a/src/Hl7.Fhir.Support.Poco.Tests/NewPocoSerializers/FhirJsonDeserializationTests.cs +++ b/src/Hl7.Fhir.Support.Poco.Tests/NewPocoSerializers/FhirJsonDeserializationTests.cs @@ -1001,6 +1001,34 @@ public void TestDuplicateProperties(string testJson, string[] expectedErrs) assertErrors(dfe.Exceptions, expectedErrs); } } + + [TestMethod] + public void TestDuplicateChoiceTypeEntries() + { + var scenario = """ + { + "resourceType": "Patient", + "deceasedBoolean": true, + "deceasedDateTime": "2022" + } + """; + + string expected = ERR.DUPLICATE_PROPERTY_CODE; + + var jsonSerializerOptions = new JsonSerializerOptions().ForFhir(typeof(TestPatient).Assembly); + + try + { + _ = JsonSerializer.Deserialize(scenario, jsonSerializerOptions); + Assert.Fail("Should have encountered errors."); + } + catch (DeserializationFailedException dfe) + { + assertErrors(dfe.Exceptions, [expected]); + } + + + } } } #nullable restore \ No newline at end of file