66 * available at https://raw.githubusercontent.com/FirelyTeam/firely-net-sdk/master/LICENSE
77 */
88
9- using Microsoft . VisualStudio . TestTools . UnitTesting ;
9+ using Hl7 . Fhir . Introspection ;
1010using Hl7 . Fhir . Model ;
1111using Hl7 . Fhir . Serialization ;
1212using Hl7 . Fhir . Utility ;
13- using Hl7 . Fhir . Introspection ;
13+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
1414using Newtonsoft . Json . Linq ;
1515using System ;
1616using System . Collections . Generic ;
1717using System . Globalization ;
1818using System . Linq ;
1919using System . Text ;
20- using Hl7 . Fhir . ElementModel ;
2120
2221namespace Hl7 . Fhir . Tests . Serialization
2322{
@@ -57,9 +56,9 @@ public void ParseMetaXml()
5756 public void ParsePatientXmlNullType ( )
5857 {
5958 string xmlPacientTest = TestDataHelper . ReadTestData ( "TestPatient.xml" ) ;
60-
59+
6160 var poco = new FhirXmlParser ( ) . Parse ( xmlPacientTest ) ;
62-
61+
6362 Assert . AreEqual ( ( ( Patient ) poco ) . Id , "pat1" ) ;
6463 Assert . AreEqual ( ( ( Patient ) poco ) . Contained . First ( ) . Id , "1" ) ;
6564 Assert . AreEqual ( ( ( Patient ) poco ) . Name . First ( ) . Family , "Donald" ) ;
@@ -195,7 +194,7 @@ public void TestDecimalPrecisionSerializationInJson()
195194 var ext = new FhirDecimal ( dec6 ) ;
196195 var obs = new Observation ( ) ;
197196 obs . AddExtension ( "http://example.org/DecimalPrecision" , ext ) ;
198-
197+
199198 var json = FhirJsonSerializer . SerializeToString ( obs ) ;
200199 var obs2 = FhirJsonParser . Parse < Observation > ( json ) ;
201200
@@ -230,7 +229,7 @@ public void TestParseUnkownPolymorphPropertyInJson()
230229 {
231230 var dec6 = 6m ;
232231 var ext = new FhirDecimal ( dec6 ) ;
233- var obs = new Observation { Value = new FhirDecimal ( dec6 ) } ;
232+ var obs = new Observation { Value = new FhirDecimal ( dec6 ) } ;
234233 var json = FhirJsonSerializer . SerializeToString ( obs ) ;
235234 try
236235 {
@@ -275,7 +274,7 @@ public void TryScriptInject()
275274
276275 var xml = FhirXmlSerializer . SerializeToString ( x ) ;
277276 Assert . IsFalse ( xml . Contains ( "<script" ) ) ;
278- }
277+ }
279278
280279
281280 [ TestMethod ]
@@ -368,7 +367,7 @@ public void SerializeJsonWithPlainDiv()
368367
369368 string json = TestDataHelper . ReadTestData ( @"valueset-v2-0717.json" ) ;
370369 Assert . IsNotNull ( json ) ;
371- var parser = new FhirJsonParser { Settings = { PermissiveParsing = true } } ;
370+ var parser = new FhirJsonParser { Settings = { PermissiveParsing = true } } ;
372371 var vs = parser . Parse < ValueSet > ( json ) ;
373372 Assert . IsNotNull ( vs ) ;
374373
@@ -556,7 +555,7 @@ public void DateTimeOffsetAccuracyTest()
556555 Assert . IsTrue ( patient . IsExactly ( res ) , "1" ) ;
557556
558557 // Is the parsing still correct without milliseconds?
559- patient = new Patient { Meta = new Meta { LastUpdated = new DateTimeOffset ( 2018 , 8 , 13 , 13 , 41 , 56 , TimeSpan . Zero ) } } ;
558+ patient = new Patient { Meta = new Meta { LastUpdated = new DateTimeOffset ( 2018 , 8 , 13 , 13 , 41 , 56 , TimeSpan . Zero ) } } ;
560559 json = "{\" resourceType\" :\" Patient\" ,\" meta\" :{\" lastUpdated\" :\" 2018-08-13T13:41:56+00:00\" }}" ;
561560 res = new FhirJsonParser ( ) . Parse < Patient > ( json ) ;
562561 Assert . IsTrue ( patient . IsExactly ( res ) , "2" ) ;
@@ -594,5 +593,28 @@ public void SerializerHandlesEmptyChildObjects()
594593
595594 Assert . AreEqual ( 1 , newPoco . Name . Count ) ;
596595 }
596+
597+ [ TestMethod ]
598+ public void IncludeMandatoryInElementsSummaryTest ( )
599+ {
600+ Observation obs = new ( )
601+ {
602+ Status = ObservationStatus . Final ,
603+ Issued = DateTimeOffset . Now
604+ } ;
605+
606+ // default behavior
607+ var json = new FhirJsonSerializer ( ) . SerializeToDocument ( obs , elements : new [ ] { "issued" } ) ;
608+
609+ Assert . IsTrue ( json . ContainsKey ( "issued" ) ) ;
610+ Assert . IsFalse ( json . ContainsKey ( "status" ) ) ;
611+
612+ // Adding mandatory elements to the set of elements
613+ json = new FhirJsonSerializer ( new SerializerSettings ( ) { IncludeMandatoryInElementsSummary = true } )
614+ . SerializeToDocument ( obs , elements : new [ ] { "issued" } ) ;
615+
616+ Assert . IsTrue ( json . ContainsKey ( "issued" ) ) ;
617+ Assert . IsTrue ( json . ContainsKey ( "status" ) ) ;
618+ }
597619 }
598620}
0 commit comments