示例#1
0
        public void CreateWithConstructor_XPath_DoesNotThrow()
        {
            // Arrange

            XNodePathConverter body = null;
            XNodePathConverter item = null;

            // Act & Assert

            Assert.DoesNotThrow(() => body = new XNodePathConverter("root/body"));
            Assert.DoesNotThrow(() => item = new XNodePathConverter("item", body));
            Assert.DoesNotThrow(() => item = new XNodePathConverter("item", x => x.Get("root/body")));
        }
示例#2
0
        public void ConvertStatically_XDocument_ValuesAreEqual()
        {
            // Arrange

            var body = new XNodePathConverter("root/body");
            Func <XNode, XElement> func = x => x.Get("root/body");

            // Act & Assert

            Assert.AreEqual((string)XNodePathConverter.Convert(_doc, "root/body/item"), "Value");
            Assert.AreEqual((string)XNodePathConverter.Convert(_doc, "item", body), "Value");
            Assert.AreEqual((string)XNodePathConverter.Convert(_doc, "item", func), "Value");

            Assert.AreEqual((string)XNodePathConverter.Convert(_doc, "root/body/colors").GetMany("c").ElementAt(0), "red");
            Assert.AreEqual((string)XNodePathConverter.Convert(_doc, "colors", body).GetMany("c").ElementAt(1), "green");
            Assert.AreEqual((string)XNodePathConverter.Convert(_doc, "colors", func).GetMany("c").ElementAt(0), "red");
        }
示例#3
0
        public void AsFuncFromInstance_XDocument_ValuesAreEqual()
        {
            // Arrange

            var body = new XNodePathConverter("root/body");
            Func <XNode, XElement> func = x => x.Get("root/body");

            // Act & Assert

            Assert.AreEqual((string)new XNodePathConverter("root/body/item").AsFunc()(_doc), "Value");
            Assert.AreEqual((string)new XNodePathConverter("item", body).AsFunc()(_doc), "Value");
            Assert.AreEqual((string)new XNodePathConverter("item", func).AsFunc()(_doc), "Value");

            Assert.AreEqual((string)new XNodePathConverter("root/body/colors").AsFunc()(_doc).GetMany("c").ElementAt(1), "green");
            Assert.AreEqual((string)new XNodePathConverter("colors", body).AsFunc()(_doc).GetMany("c").ElementAt(0), "red");
            Assert.AreEqual((string)new XNodePathConverter("colors", func).AsFunc()(_doc).GetMany("c").ElementAt(0), "red");
        }