Exemple #1
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 + "'"));
            }
        }