Example #1
0
        public void WitsmlParser_Parse_Invalid_Xml_Using_Standard_DevKit_Throws_WitsmlException()
        {
            var xdoc = WitsmlParser.Parse(_wellXml);

            Assert.IsNotNull(xdoc.Root);

            Should.Throw <WitsmlException>(() =>
            {
                xdoc.Root?.Elements().FirstOrDefault()?.Elements().Where(e => e.Name.LocalName == "pcInterest").Attributes().Remove();
                WitsmlParser.Parse <WellList>(xdoc.Root);
            });
        }
Example #2
0
        public void WitsmlParser_Parse_Invalid_Xml_Returns_409_InputTemplateNonConforming()
        {
            Should.Throw <WitsmlException>(() =>
            {
                WitsmlParser.Parse(string.Empty);
            }).ErrorCode.ShouldBe(ErrorCodes.InputTemplateNonConforming);

            Should.Throw <WitsmlException>(() =>
            {
                WitsmlParser.Parse(null);
            }).ErrorCode.ShouldBe(ErrorCodes.InputTemplateNonConforming);
        }
Example #3
0
        public void WitsmlParser_Parse_Xml_With_Type_Returns_object()
        {
            var xdoc = WitsmlParser.Parse(_wellXml);

            Assert.IsNotNull(xdoc.Root);

            var result = WitsmlParser.Parse(typeof(WellList), xdoc.Root, false) as WellList;

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Well.Count);
            Assert.AreEqual("Test Full Well", result.Well[0].Name);
        }
Example #4
0
        /// <summary>
        /// Removes elements that are numeric type and have NaN value.
        /// </summary>
        /// <param name="element">The XML element.</param>
        /// <returns>The xml with NaN removed.</returns>
        public static string RemoveNaNElements <T>(XElement element)
        {
            _log.Debug("Removing NaN elements.");

            var context = new WitsmlParserContext <T>(element);
            var parser  = new WitsmlParser(context);

            context.IgnoreUnknownElements = true;
            context.RemoveNaNElements     = true;
            parser.Navigate(context.Element);

            return(context.Element.ToString());
        }
Example #5
0
        public void WitsmlParser_RemoveNaNElements_Removes_NaN_Elements()
        {
            string wellXml = "<wells xmlns=\"http://www.witsml.org/schemas/1series\" version=\"1.4.1.1\">" + Environment.NewLine +
                             "<well>" + Environment.NewLine +
                             "<name>Test Full Well</name>" + Environment.NewLine +
                             "<pcInterest uom=\"%\">NaN</pcInterest>" + Environment.NewLine +
                             "</well>" + Environment.NewLine +
                             "</wells>";

            var document = WitsmlParser.Parse(wellXml);
            var result   = WitsmlParser.RemoveNaNElements <WellList>(document.Root);
            var welllist = EnergisticsConverter.XmlToObject <WellList>(result);

            Assert.IsNull(welllist.Well[0].PercentInterest);
        }
Example #6
0
        public void WitsmlParser_Parse_Invalid_Xml_With_Type_Throws_409_InputTemplateNonConforming()
        {
            var xdoc = WitsmlParser.Parse(_wellXml);

            Assert.IsNotNull(xdoc.Root);

            Should.Throw <WitsmlException>(() =>
            {
                WitsmlParser.Parse(typeof(Log), xdoc.Root, false);
            }).ErrorCode.ShouldBe(ErrorCodes.InputTemplateNonConforming);

            Should.Throw <WitsmlException>(() =>
            {
                WitsmlParser.Parse(typeof(WellList), null, false);
            }).ErrorCode.ShouldBe(ErrorCodes.InputTemplateNonConforming);
        }
Example #7
0
        public void WitsmlParser_RemoveNaNElements_Removes_Nested_NaN_Elements()
        {
            string wellXml = "<wells xmlns=\"http://www.witsml.org/schemas/1series\" version=\"1.4.1.1\">" + Environment.NewLine +
                             "<well>" + Environment.NewLine +
                             "<name>Test Full Well</name>" + Environment.NewLine +
                             "<wellDatum uid=\"KB\">" + Environment.NewLine +
                             "    <name>Kelly Bushing</name>" + Environment.NewLine +
                             "    <code>KB</code>" + Environment.NewLine +
                             "    <elevation uom=\"ft\" datum=\"SL\">NaN</elevation>" + Environment.NewLine +
                             "</wellDatum>" + Environment.NewLine +
                             "</well>" + Environment.NewLine +
                             "</wells>";

            var document = WitsmlParser.Parse(wellXml);
            var result   = WitsmlParser.RemoveNaNElements <WellList>(document.Root);
            var welllist = EnergisticsConverter.XmlToObject <WellList>(result);

            Assert.IsNull(welllist.Well[0].WellDatum[0].Elevation);
        }
Example #8
0
        public void WitsmlParser_RemoveEmptyElements_Removes_Empty_Elements_From_Elements()
        {
            var xdoc = WitsmlParser.Parse(_wellXml);

            Assert.IsNotNull(xdoc.Root);

            var elemPurposeWell     = new XElement(xdoc.Root.GetDefaultNamespace() + "purposeWell");
            var elemStatusWell      = new XElement(xdoc.Root.GetDefaultNamespace() + "statusWell", "plugged and abandoned");
            var elemGroundElevation = new XElement(xdoc.Root.GetDefaultNamespace() + "groundElevation");
            var nil = XNamespace.Get("http://www.w3.org/2001/XMLSchema-instance").GetName("nil");

            elemGroundElevation.Add(new XAttribute(nil, true));

            xdoc.Root.Elements().FirstOrDefault()?.Add(elemPurposeWell);
            xdoc.Root.Elements().FirstOrDefault()?.Add(elemStatusWell);
            xdoc.Root.Elements().FirstOrDefault()?.Add(elemGroundElevation);

            WitsmlParser.RemoveEmptyElements(xdoc.Root);
            var welllist = EnergisticsConverter.XmlToObject <WellList>(xdoc.Root.ToString());

            Assert.IsNotNull(welllist.Well[0].StatusWell);
            Assert.IsNull(welllist.Well[0].PurposeWell);
            Assert.IsNull(welllist.Well[0].GroundElevation);
        }
Example #9
0
 public void WitsmlParser_ToXml_Returns_Empty_String_For_Null_Object()
 {
     Assert.AreEqual(string.Empty, WitsmlParser.ToXml(null));
 }