Ejemplo n.º 1
0
        public string Evaluate(TagModel model)
        {
            try
            {
                XPathNodeIterator result = XmlHelper.GetAndEvaluate(Source, Select, model);
                var    escapeXml         = GetAutoValueAsBool("EscapeXml", model);
                string resultStr         = result != null?CollectionUtils.ToString(result, info) : String.Empty;

                return(escapeXml ? StringUtils.EscapeXml(resultStr) : resultStr);
            } catch (XPathException XPe)
            {
                throw TagException.IllegalXPath(XPe).Decorate(Context);
            }
        }
Ejemplo n.º 2
0
        public void CheckSelectWrongXpathSyntax()
        {
            var tag = new Out();

            tag.Select = new MockAttribute(new Constant("//note[@id=\"3\"/body"));
            tag.Source = new MockAttribute(new Constant("xml"));
            try
            {
                Assert.That(tag.Evaluate(_model), Is.EqualTo(String.Empty));
                Assert.Fail("Expected exception");
            }
            catch (TagException XPe)
            {
                Assert.That(XPe.Message.StartsWith(TagException.IllegalXPath(new Exception("")).Message), Is.True);
            }
        }
Ejemplo n.º 3
0
        public static bool GetAndEvaluateAsBool(ITagAttribute source, ITagAttribute xPath, TagModel model, bool fallBack)
        {
            bool result = fallBack;

            try
            {
                XPathNodeIterator nodes = GetAndEvaluate(source, xPath, model);
                if (nodes != null && nodes.Count > 0)
                {
                    XPathNavigator node = GuardSingleNode(model, nodes, xPath);
                    result = ParseBoolean(nodes.Current) ?? fallBack;
                }
            } catch (FormatException Fe)
            {
                throw TagException.IllegalXPath(Fe).Decorate(xPath.Context);
            }
            return(result);
        }
Ejemplo n.º 4
0
        public void IfShouldThrowExceptionWhenNoneBoolIsFound()
        {
            var tag = new If
            {
                Select = new MockAttribute(new Constant("/results/value[position()=3]")),
                Source = new MockAttribute(new Constant("xml")),
                Body   = new MockAttribute(new Constant("Show me"))
            };

            try
            {
                tag.Evaluate(_model);
                Assert.Fail("Expected exception");
            }
            catch (TagException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(TagException.IllegalXPath(new FormatException()).Message);
                Assert.That(e.Message.StartsWith(TagException.IllegalXPath(new FormatException("")).Message));
            }
        }