Esempio n. 1
0
        public void CanReadThroughNavigator()
        {
            var tpXml = System.IO.File.ReadAllText("TestData\\fp-test-patient.xml");

            var nav = XmlDomFhirNavigator.Create(tpXml);

            Assert.Equal("Patient", nav.Name);
            Assert.Equal("Patient", nav.TypeName);

            Assert.True(nav.MoveToFirstChild());
            Assert.Equal("xmlns", nav.Name);        // Yep, even those come through

            Assert.True(nav.MoveToNext());
            Assert.Equal("id", nav.Name);
            Assert.Null(nav.TypeName);
            var id = nav.Clone();

            Assert.True(nav.MoveToFirstChild());
            Assert.Equal("value", nav.Name);
            Assert.Equal("pat1", nav.Text);
            Assert.False(nav.MoveToFirstChild());
            Assert.False(nav.MoveToNext());

            Assert.True(id.MoveToNext());
            Assert.Equal("text", id.Name);
            var text = id.Clone();

            Assert.True(id.MoveToFirstChild()); // status
            Assert.True(id.MoveToNext());
            Assert.Equal("div", id.Name);
            Assert.StartsWith("<div xmlns=", (string)id.Text); // special handling of xhtml
            Assert.False(id.MoveToFirstChild());               // cannot move into xhtml
            Assert.Equal("div", id.Name);                      // still on xhtml <div>
            Assert.False(id.MoveToNext());                     // nothing more in <text>

            Assert.True(text.MoveToNext());                    // contained
            Assert.Equal("contained", text.Name);
            Assert.Equal("Patient", text.TypeName);
            Assert.True(text.MoveToFirstChild()); // id
            Assert.True(text.MoveToNext());       // identifier
            var identifier = text.Clone();

            Assert.True(text.MoveToFirstChild()); // system
            Assert.True(text.MoveToNext());       // value
            Assert.False(text.MoveToNext());      // still value

            Assert.Equal("value", text.Name);
            Assert.True(text.MoveToFirstChild());
            Assert.Equal("value", text.Name); // value.value
            Assert.Equal("444222222", text.Text);
            Assert.False(text.MoveToNext());

            Assert.True(identifier.MoveToNext());       // active
            Assert.True(identifier.MoveToNext());       // name
            Assert.Equal("name", identifier.Name);
            Assert.True(identifier.MoveToFirstChild()); // id (attribute)
            Assert.Equal("id", identifier.Name);
            Assert.True(identifier.MoveToNext());       // use (element!)
            Assert.Equal("use", identifier.Name);
        }
Esempio n. 2
0
        public void ReadsFromNav()
        {
            var tpXml = File.ReadAllText(@"TestData\fp-test-patient.xml");
            var nav   = XmlDomFhirNavigator.Create(tpXml);
            var nodes = ElementNode.FromNavigator(nav);
            var nav2  = nodes.ToNavigator();

            Assert.True(nav.IsEqualTo(nav2).Success);
        }
Esempio n. 3
0
        public void ReadsAttributesAsElements()
        {
            var nav = XmlDomFhirNavigator.Create("<Patient xmlns='http://hl7.org/fhir' xmlns:q='http://somenamespace' q:myattr='dummy' />");

            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual("myattr", nav.Name);        // none-xmlns attributes will come through
            var xmldetails = (nav as IAnnotated).Annotation <XmlSerializationDetails>();

            Assert.AreEqual("http://somenamespace", xmldetails.Name.NamespaceName);

            Assert.AreEqual("Patient.myattr[0]", nav.Location);
        }
Esempio n. 4
0
        public void HasLineNumbersXml()
        {
            var tpXml = File.ReadAllText(@"TestData\fp-test-patient.xml");
            var nav   = XmlDomFhirNavigator.Create(tpXml);

            Assert.IsTrue(nav.MoveToFirstChild());

            var xmlDetails = (nav as IAnnotated)?.Annotation <XmlSerializationDetails>();

            Assert.IsNotNull(xmlDetails);
            Assert.AreNotEqual(-1, xmlDetails.LineNumber);
            Assert.AreNotEqual(-1, xmlDetails.LinePosition);
        }
Esempio n. 5
0
        public void CanReadThroughNavigator()
        {
            var tpXml = File.ReadAllText(@"TestData\fp-test-patient.xml");
            var nav   = XmlDomFhirNavigator.Create(tpXml);

            Assert.AreEqual("Patient", nav.Name);
            Assert.AreEqual("Patient", nav.Type);

            Assert.IsTrue(nav.MoveToFirstChild());
            Assert.AreEqual("id", nav.Name);
            Assert.AreEqual("pat1", nav.Value);

            Assert.IsFalse(nav.MoveToFirstChild());

            Assert.IsTrue(nav.MoveToNext());
            Assert.AreEqual("text", nav.Name);
            var text = nav.Clone();

            Assert.IsTrue(text.MoveToFirstChild("status")); // status
            Assert.IsTrue(text.MoveToNext());
            Assert.AreEqual("div", text.Name);
            Assert.IsTrue(((string)text.Value).StartsWith("<div xmlns=")); // special handling of xhtml
            Assert.IsFalse(text.MoveToFirstChild());                       // cannot move into xhtml
            Assert.AreEqual("div", text.Name);                             // still on xhtml <div>
            Assert.IsFalse(text.MoveToNext());                             // nothing more in <text>

            Assert.IsTrue(nav.MoveToNext());                               // contained
            Assert.AreEqual("contained", nav.Name);
            Assert.AreEqual("Patient", nav.Type);
            Assert.IsTrue(nav.MoveToFirstChild()); // id
            Assert.IsTrue(nav.MoveToNext());       // identifier
            var identifier = nav.Clone();

            Assert.IsTrue(identifier.MoveToFirstChild()); // system
            Assert.IsTrue(identifier.MoveToNext());       // value
            Assert.IsFalse(identifier.MoveToNext());      // still value

            Assert.AreEqual("value", identifier.Name);
            Assert.IsFalse(identifier.MoveToFirstChild());
            Assert.AreEqual("444222222", identifier.Value);

            Assert.IsTrue(nav.MoveToNext("name"));
            Assert.AreEqual("name", nav.Name);
            Assert.IsTrue(nav.MoveToFirstChild());  // id (attribute)
            Assert.AreEqual("id", nav.Name);
            Assert.AreEqual("firstname", nav.Value);
            Assert.IsTrue(nav.MoveToNext());  // use (element!)
            Assert.AreEqual("use", nav.Name);
        }
Esempio n. 6
0
        public void CompareXmlJsonParseOutcomes()
        {
            var tpXml   = File.ReadAllText(@"TestData\fp-test-patient.xml");
            var tpJson  = File.ReadAllText(@"TestData\fp-test-patient.json");
            var navXml  = XmlDomFhirNavigator.Create(tpXml);
            var navJson = JsonDomFhirNavigator.Create(tpJson);

            var compare = navXml.IsEqualTo(navJson);

            if (compare.Success == false)
            {
                Debug.WriteLine($"Difference in {compare.Details} at {compare.FailureLocation}");
                Assert.IsTrue(compare.Success);
            }
            Assert.IsTrue(compare.Success);
        }
        public void CompareJsonXmlParseOutcomes()
        {
            var tpJson = File.ReadAllText(@"TestData\json-edge-cases.json");
            var tpXml  = File.ReadAllText(@"TestData\json-edge-cases.xml");

            var navJson = JsonDomFhirNavigator.Create(tpJson);
            var navXml  = XmlDomFhirNavigator.Create(tpXml);

            var compare = navJson.IsEqualTo(navXml);

            if (compare.Success == false)
            {
                output.WriteLine($"Difference in {compare.Details} at {compare.FailureLocation}");
                Assert.True(compare.Success);
            }
            Assert.True(compare.Success);
        }
Esempio n. 8
0
        public void ProducesCorrectLocations()
        {
            var tpXml   = File.ReadAllText(@"TestData\fp-test-patient.xml");
            var patient = XmlDomFhirNavigator.Create(tpXml);

            Assert.AreEqual("Patient", patient.Location);

            patient.MoveToFirstChild();
            Assert.AreEqual("Patient.id[0]", patient.Location);

            patient.MoveToNext();   // text
            patient.MoveToNext();   // contained[0]
            patient.MoveToNext();   // contained[1]
            Assert.AreEqual("Patient.contained[1]", patient.Location);

            patient.MoveToFirstChild();
            Assert.AreEqual("Patient.contained[1].id[0]", patient.Location);
        }
Esempio n. 9
0
        public void ElementNavPerformance()
        {
            var tpXml = File.ReadAllText(@"TestData\fp-test-patient.xml");
            var nav   = XmlDomFhirNavigator.Create(tpXml);

            var sw = new Stopwatch();

            sw.Start();
            for (var i = 0; i < 10_000; i++)
            {
                var usual = nav.Children("identifier").First().Children("use").First().Value;
                var phone = nav.Children("telecom").First().Children("system").First().Value;
                var prefs = nav.Children("communication").Where(c => c.Children("preferred").Any(pr => pr.Value is string s && s == "true")).Count();
                var link  = nav.Children("link").Children("other").Children("reference");
            }
            sw.Stop();

            Debug.WriteLine($"Navigating took {sw.ElapsedMilliseconds / 10} micros");
        }