Example #1
0
 protected void AppendSourceEvalation(string origParentName, XmlNode attach, XmlNode childNode)
 {
     {
         {
             {
                 string ts      = "<template>" + ToXmlValue(childNode) + "</template>";
                 var    tchiuld = getNodeAndSetSiblingNode(ts, childNode);
                 string ost     = tchiuld.OuterXml;
                 LineInfoElementImpl.unsetReadonly(tchiuld);
                 Unifiable processChildNode = ProcessChildNode(tchiuld);
                 SaveResultOnChild(childNode, processChildNode);
                 var readNode = getNodeAndSetSiblingNode("<node>" + Unifiable.InnerXmlText(childNode) + "</node>", childNode);
                 LineInfoElementImpl.unsetReadonly(readNode);
                 if (readNode.ChildNodes.Count == 1)
                 {
                     XmlNode chilz = readNode.ChildNodes[0];
                     LineInfoElementImpl.chopParent(chilz);
                     attach.AppendChild(chilz);
                     return;
                 }
                 foreach (XmlNode child in readNode.ChildNodes)
                 {
                     LineInfoElementImpl.unsetReadonly(child);
                     attach.AppendChild(child.CloneNode(true));
                 }
             }
         }
     }
 }
Example #2
0
        protected override string InnerSource()
        {
            if (templateNode.Name.ToLower() == "condition")
            {
                // heuristically work out the type of condition being Processed
                int tncount = AttributesCount(templateNode, "name,value");
                if (tncount == 2) // block
                {
                    Unifiable name  = GetAttribValue("name", null);
                    Unifiable value = GetAttribValue("value", null);
                    if ((name != null) & (value != null))
                    {
                        Unifiable actualValue = query.grabSetting(name);
                        if (IsPredMatch(value, actualValue, query))
                        {
                            Succeed();
                            return(Unifiable.InnerXmlText(templateNode));
                        }
                        return(Unifiable.Empty);
                    }
                    UnknownCondition();
                }
                else if (tncount == 1) // single predicate
                {
                    if (templateNode.Attributes[0].Name == "name")
                    {
                        string name = GetAttribValue("name", String.Empty);

                        foreach (XmlNode childLINode in templateNode.ChildNodes)
                        {
                            int cac = AttributesCount(childLINode, "name,value");
                            if (childLINode.Name.ToLower() == "li")
                            {
                                if (cac == 1)
                                {
                                    if (childLINode.Attributes[0].Name.ToLower() == "value")
                                    {
                                        bool      succeed;
                                        Unifiable actualValue = GetActualValue(childLINode, name, childLINode.Name, out succeed, query);;
                                        Unifiable value       = GetAttribValue <Unifiable>(childLINode, "value", NullUnifyFunct, ReduceStarAttribute <Unifiable>);
                                        if (IsPredMatch(value, actualValue, query))
                                        {
                                            Succeed();
                                            return(Unifiable.InnerXmlText(childLINode));
                                        }
                                    }
                                }
                                else if (cac == 0)
                                {
                                    Succeed();
                                    return(Unifiable.InnerXmlText(childLINode));
                                }
                            }
                        }
                    }
                }
                else if (tncount == 0) // multi-predicate
                {
                    foreach (XmlNode childLINode in templateNode.ChildNodes)
                    {
                        if (childLINode.Name.ToLower() == "li")
                        {
                            int cac = AttributesCount(childLINode, "name,value");

                            if (cac == 2)
                            {
                                string    name  = GetAttribValue <string>(childLINode, "name", NullStringFunct, ReduceStarAttribute <string>);
                                Unifiable value = GetAttribValue(childLINode, "value", NullUnifyFunct, ReduceStarAttribute);
                                if ((name.Length > 0) & (!IsNullOrEmpty(value)))
                                {
                                    bool      succeed;
                                    Unifiable actualValue = base.GetActualValue(name, childLINode.Name, out succeed);
                                    if (IsPredMatch(value, actualValue, query))
                                    {
                                        Succeed();
                                        return(Unifiable.InnerXmlText(childLINode));
                                    }
                                }
                            }
                            if (cac == 1)
                            {
                                string name = GetAttribValue <string>(childLINode, "name", NullStringFunct, ReduceStarAttribute <string>);
                                if ((name.Length > 0) && query.containsSettingCalled(name))
                                {
                                    Succeed();
                                    return(Unifiable.InnerXmlText(childLINode));
                                }
                            }
                            else if (cac == 0)
                            {
                                Succeed();
                                return(Unifiable.InnerXmlText(childLINode));
                            }
                        }
                    }
                }
            }
            return(Unifiable.Empty);
        }
Example #3
0
        private XmlNode RunTest(Request request, XmlNode src, OutputDelegate outputdelegate, out bool m)
        {
            // request = request ?? Loader.LoaderRequest00;
            User   user  = request.Requester;
            AltBot robot = request.TargetBot ?? Loader.TargetBot;

            string tcname = StaticXMLUtils.FindNodeOrAttrib(src, "name", null);
            string tcdesc = FindNodeOrAttrib(src, "Description", null);
            string input  = FindNodeOrAttrib(src, "Input", null);

            if (input == null)
            {
                outputdelegate("ERROR cannot find 'Input' in '" + src.OuterXml + "'");
                m = false;
                return(getNodeAndSetSibling(false,
                                            "<template type=\"error\">ERROR cannot find 'Input' in '" + src.OuterXml + "'</template>", true,
                                            false, src));
            }
            string userID = FindNodeOrAttrib(src, "UserId,UserName", () => user.UserID);

            const string MISSING_EXPECTED_ANSWER = "ExpectedKeywords";
            var          matchTheseToPass        = new List <string>();
            string       expectedAnswer          = FindNodeOrAttrib(src, "ExpectedAnswer", () => MISSING_EXPECTED_ANSWER);

            expectedAnswer = Fudge(expectedAnswer);
            if (expectedAnswer == MISSING_EXPECTED_ANSWER)
            {
                var nodes = FindNodes("ExpectedKeywords", src);
                if (nodes == null || nodes.Count == 0)
                {
                    outputdelegate("ERROR cannot find 'ExpectedAnswer' in '" + src.OuterXml + "'");
                }
                else
                {
                    foreach (XmlNode list in nodes)
                    {
                        string v = Unifiable.InnerXmlText(list);

                        matchTheseToPass.Add(".*" + Fudge(v) + ".*");
                    }
                }
            }
            else
            {
                matchTheseToPass.Add("^" + Fudge(expectedAnswer) + "$");
            }

            outputdelegate("{0}: {1} ", tcname, tcdesc);
            outputdelegate("{0}: {1} ", userID, input);
            string resp = "ERROR";

            try
            {
                var requestToBot = robot.MakeRequestToBot(input, userID, true, RequestKind.ChatRealTime);
                requestToBot.IsTraced = traceIt;
                if (traceIt)
                {
                    AltBot.Breakpoint("testing...");
                    requestToBot.DebugLevel = 9;
                }
                Result result = robot.Chat(requestToBot);
                resp = result.Output ?? result.ToString() ?? resp;
                if (resp == null)
                {
                    resp = "NULLED";
                }
                resp = Fudge(resp);
                outputdelegate("{0}: {1} ", robot, resp);
                m = true;
                int good = 0;
                foreach (string s in matchTheseToPass)
                {
                    if (!Matches(resp, s, FindNodeOrAttrib(src, "MatchType,Match", null)))
                    {
                        m = false;
                    }
                    else
                    {
                        good++;
                    }
                }
                outputdelegate("PASSED={0}", m);
                if (traceIt)
                {
                    AltBot.Breakpoint("tested...");
                }
                return(GetMessage(src, "PASSED='" + m +
                                  "'", "TESTCASE='" + tcname + "' GOOD='" + good +
                                  "' RESPNS='" + resp +
                                  "' EXPECT='" + expectedAnswer +
                                  "' INPUT='" + input +
                                  "' DESC='" + tcdesc + "'"));
            }
            catch (Exception err)
            {
                string ERRMSG = "" + err;
                m = false;
                errorCount++;
                return(GetMessage(src, "PASSED='" + m +
                                  "'", "TESTCASE='" + tcname + "' ERRMSG='" + ERRMSG + "' RESP='" + resp +
                                  "' EXPECT='" + expectedAnswer +
                                  "' INPUT='" + input +
                                  "' DESC='" + tcdesc + "'"));
            }
        }