private static void convertResourcePoco(string inputFile, string outputFile) { //TODO: call validation after reading if (inputFile.Contains("expansions.") || inputFile.Contains("profiles-resources") || inputFile.Contains("profiles-others") || inputFile.Contains("valuesets.")) { return; } if (inputFile.EndsWith(".xml")) { var xml = File.ReadAllText(inputFile); var resource = new FhirXmlParser().Parse <Resource>(xml); var r2 = resource.DeepCopy(); Assert.IsTrue(resource.Matches(r2 as Resource), "Serialization of " + inputFile + " did not match output - Matches test"); Assert.IsTrue(resource.IsExactly(r2 as Resource), "Serialization of " + inputFile + " did not match output - IsExactly test"); Assert.IsFalse(resource.Matches(null), "Serialization of " + inputFile + " matched null - Matches test"); Assert.IsFalse(resource.IsExactly(null), "Serialization of " + inputFile + " matched null - IsExactly test"); var json = new FhirJsonSerializer().SerializeToString(resource); File.WriteAllText(outputFile, json); } else { var json = File.ReadAllText(inputFile); var resource = new FhirJsonParser().Parse <Resource>(json); var xml = new FhirXmlSerializer().SerializeToString(resource); File.WriteAllText(outputFile, xml); } }
private void convertResource(string inputFile, string outputFile) { //TODO: call validation after reading if (inputFile.EndsWith(".xml")) { var xml = File.ReadAllText(inputFile); var resource = new FhirXmlParser().Parse <Resource>(xml); var r2 = resource.DeepCopy(); Assert.IsTrue(resource.Matches(r2 as Resource), "Serialization of " + inputFile + " did not match output - Matches test"); Assert.IsTrue(resource.IsExactly(r2 as Resource), "Serialization of " + inputFile + " did not match output - IsExactly test"); Assert.IsFalse(resource.Matches(null), "Serialization of " + inputFile + " matched null - Matches test"); Assert.IsFalse(resource.IsExactly(null), "Serialization of " + inputFile + " matched null - IsExactly test"); var json = FhirSerializer.SerializeResourceToJson(resource); File.WriteAllText(outputFile, json); } else { var json = File.ReadAllText(inputFile); var resource = new FhirJsonParser().Parse <Resource>(json); var xml = FhirSerializer.SerializeResourceToXml(resource); File.WriteAllText(outputFile, xml); } }
private static void convertResourcePoco(string inputFile, string outputFile) { if (inputFile.EndsWith(".xml")) { var xml = File.ReadAllText(inputFile); var resource = new FhirXmlParser(new ParserSettings { PermissiveParsing = true }).Parse <Resource>(xml); var r2 = resource.DeepCopy(); Assert.IsTrue(resource.Matches(r2 as Resource), "Serialization of " + inputFile + " did not match output - Matches test"); Assert.IsTrue(resource.IsExactly(r2 as Resource), "Serialization of " + inputFile + " did not match output - IsExactly test"); Assert.IsFalse(resource.Matches(null), "Serialization of " + inputFile + " matched null - Matches test"); Assert.IsFalse(resource.IsExactly(null), "Serialization of " + inputFile + " matched null - IsExactly test"); var json = new FhirJsonSerializer().SerializeToString(resource); File.WriteAllText(outputFile, json); } else { var json = File.ReadAllText(inputFile); var resource = new FhirJsonParser(new ParserSettings { PermissiveParsing = true }).Parse <Resource>(json); var xml = new FhirXmlSerializer().SerializeToString(resource); File.WriteAllText(outputFile, xml); } }
public void RoundTripOneExample() { string testFileName = "testscript-example(example).xml"; var original = TestDataHelper.ReadTestData(testFileName); var t = new FhirXmlParser().Parse <TestScript>(original); var outputXml = FhirSerializer.SerializeResourceToXml(t); XmlAssert.AreSame(testFileName, original, outputXml); var outputJson = FhirSerializer.SerializeResourceToJson(t); var t2 = new FhirJsonParser().Parse <TestScript>(outputJson); Assert.IsTrue(t.IsExactly(t2)); var outputXml2 = FhirSerializer.SerializeResourceToXml(t2); XmlAssert.AreSame(testFileName, original, outputXml2); }
private void roundTripOneExample(string filename) { string testFileName = filename; var original = TestDataHelper.ReadTestData(testFileName); var t = new FhirXmlParser().Parse <Resource>(original); var outputXml = new FhirXmlSerializer().SerializeToString(t); XmlAssert.AreSame(testFileName, original, outputXml); var outputJson = new FhirJsonSerializer().SerializeToString(t); var t2 = new FhirJsonParser().Parse <Resource>(outputJson); Assert.IsTrue(t.IsExactly(t2)); var outputXml2 = new FhirXmlSerializer().SerializeToString(t2); XmlAssert.AreSame(testFileName, original, outputXml2); }