public void setupMockObjects() { this.mockBot = new Bot(); this.mockUser = new User("1", this.mockBot); this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *"); this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest); }
/// <summary> /// Ctor /// </summary> /// <param name="bot">The bot involved in this request</param> /// <param name="user">The user making the request</param> /// <param name="query">The query that originated this node</param> /// <param name="request">The request inputted into the system</param> /// <param name="result">The result to be passed to the user</param> /// <param name="templateNode">The node to be processed</param> public star(AIMLbot.Bot bot, AIMLbot.User user, AIMLbot.Utils.SubQuery query, AIMLbot.Request request, AIMLbot.Result result, XmlNode templateNode) : base(bot, user, query, request, result, templateNode) { }
public void setupMockObjects() { this.mockBot = new Bot(); this.mockBot.loadSettings(); this.mockBot.GlobalSettings.addSetting("timeout", "9999999999"); this.mockNode = new AIMLbot.Utils.Node(); this.mockRequest = new Request("Test 1", new User("1", this.mockBot), this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery("Test 1 <that> * <topic> *"); }
public void setupMockObjects() { this.mockBot = new Bot(); this.mockUser = new User("1", this.mockBot); this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *"); this.mockQuery.InputStar.Insert(0, "first star"); this.mockQuery.InputStar.Insert(0, "second star"); //this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest); }
public void testEvaluateWithEmptyNode() { this.mockBot = new Bot(); this.mockBot.loadSettings(); this.mockNode = new AIMLbot.Utils.Node(); this.mockRequest = new Request("Test 1", new User("1", this.mockBot), this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery("Test 1 <that> that <topic> topic"); Assert.AreEqual(string.Empty, this.mockNode.evaluate("Test 1 <that> that <topic> topic", this.mockQuery, this.mockRequest, AIMLbot.Utils.MatchState.UserInput, new StringBuilder())); }
/// <summary> /// Ctor /// </summary> /// <param name="bot">The bot involved in this request</param> /// <param name="user">The user making the request</param> /// <param name="query">The query that originated this node</param> /// <param name="request">The request inputted into the system</param> /// <param name="result">The result to be passed to the user</param> /// <param name="templateNode">The node to be processed</param> public condition(AIMLbot.Bot bot, AIMLbot.User user, AIMLbot.Utils.SubQuery query, AIMLbot.Request request, AIMLbot.Result result, XmlNode templateNode) : base(bot, user, query, request, result, templateNode) { this.isRecursive = false; }
public void testEvaluateWithNoWildCards() { string path = "Test 1 <that> that <topic> topic"; string template = "<srai>TEST</srai>"; this.mockNode = new AIMLbot.Utils.Node(); this.mockNode.addCategory(path, template, "filename"); this.mockRequest = new Request("Test 1", new User("1", this.mockBot), this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery(path); Assert.AreEqual("<srai>TEST</srai>", this.mockNode.evaluate("Test 1 <that> that <topic> topic", this.mockQuery, this.mockRequest, AIMLbot.Utils.MatchState.UserInput, new StringBuilder())); }
/// <summary> /// Ctor /// </summary> /// <param name="bot">The bot involved in this request</param> /// <param name="user">The user making the request</param> /// <param name="query">The query that originated this node</param> /// <param name="request">The request inputted into the system</param> /// <param name="result">The result to be passed to the user</param> /// <param name="templateNode">The node to be processed</param> public javascript(AIMLbot.Bot bot, AIMLbot.User user, AIMLbot.Utils.SubQuery query, AIMLbot.Request request, AIMLbot.Result result, XmlNode templateNode) : base(bot, user, query, request, result, templateNode) { // Preprocess javascript, return result and then process result this.isRecursive = false; }
/// <summary> /// Ctor /// </summary> /// <param name="bot">The bot involved in this request</param> /// <param name="user">The user making the request</param> /// <param name="query">The query that originated this node</param> /// <param name="request">The request itself</param> /// <param name="result">The result to be passed back to the user</param> /// <param name="templateNode">The node to be processed</param> public AIMLTagHandler(AIMLbot.Bot bot, AIMLbot.User user, AIMLbot.Utils.SubQuery query, AIMLbot.Request request, AIMLbot.Result result, XmlNode templateNode) : base(bot, templateNode.OuterXml) { this.user = user; this.query = query; this.request = request; this.result = result; this.templateNode = templateNode; }
public void setupMockObjects() { this.mockBot = new Bot(); this.mockUser = new User("1", this.mockBot); this.mockRequest = new Request("This is a test", this.mockUser, this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *"); this.mockResult = new Result(this.mockUser, this.mockBot, this.mockRequest); this.possibleResults = new ArrayList(); this.possibleResults.Add("random 1"); this.possibleResults.Add("random 2"); this.possibleResults.Add("random 3"); this.possibleResults.Add("random 4"); this.possibleResults.Add("random 5"); }
/// <summary> /// Ctor /// </summary> /// <param name="bot">The bot involved in this request</param> /// <param name="user">The user making the request</param> /// <param name="query">The query that originated this node</param> /// <param name="request">The request itself</param> /// <param name="result">The result to be passed back to the user</param> /// <param name="templateNode">The node to be processed</param> public AIMLTagHandler(Bot bot, AIMLbot.User user, AIMLbot.Utils.SubQuery query, Request request, AIMLbot.Result result, XmlNode templateNode) : base(bot, templateNode.OuterXml) { this.user = user; this.query = query; this.request = request; this.result = result; this.templateNode = templateNode; this.templateNode.Attributes.RemoveNamedItem("xmlns"); }
/// <summary> /// Ctor /// </summary> /// <param name="bot">The bot involved in this request</param> /// <param name="user">The user making the request</param> /// <param name="query">The query that originated this node</param> /// <param name="request">The request itself</param> /// <param name="result">The result to be passed back to the user</param> /// <param name="templateNode">The node to be processed</param> public AIMLTagHandler( AIMLbot.Bot bot, AIMLbot.User user, AIMLbot.Utils.SubQuery query, AIMLbot.Request request, AIMLbot.Result result, XmlNode templateNode) : base(bot,templateNode.OuterXml) { this.user = user; this.query = query; this.request = request; this.result = result; this.templateNode = templateNode; }
public void testResultHandlers() { XmlNode testNode = getNode("<that/>"); var mockQuery = new AIMLbot.Utils.SubQuery("This is a test <that> * <topic> *"); mockQuery.InputStar.Insert(0, "first star"); mockQuery.InputStar.Insert(0, "second star"); var mockRequest = new Request("Sentence 1. Sentence 2", this.mockUser, this.mockBot); var mockResult = new Result(this.mockUser, this.mockBot, mockRequest); var mockBotTagHandler = new AIMLbot.AIMLTagHandlers.that(this.mockBot, this.mockUser, mockQuery, mockRequest, mockResult, testNode); Assert.Equal("", mockBotTagHandler.Transform()); mockResult.OutputSentences.Add("Result 1"); mockResult.OutputSentences.Add("Result 2"); this.mockUser.addResult(mockResult); Result mockResult2 = new Result(this.mockUser, this.mockBot, mockRequest); mockResult2.OutputSentences.Add("Result 3"); mockResult2.OutputSentences.Add("Result 4"); this.mockUser.addResult(mockResult2); Assert.Equal("Result 3", mockBotTagHandler.Transform()); testNode = getNode("<that index=\"1\"/>"); mockBotTagHandler = new AIMLbot.AIMLTagHandlers.that(this.mockBot, this.mockUser, mockQuery, mockRequest, mockResult, testNode); Assert.Equal("Result 3", mockBotTagHandler.Transform()); testNode = getNode("<that index=\"2,1\"/>"); mockBotTagHandler = new AIMLbot.AIMLTagHandlers.that(this.mockBot, this.mockUser, mockQuery, mockRequest, mockResult, testNode); Assert.Equal("Result 1", mockBotTagHandler.Transform()); testNode = getNode("<that index=\"1,2\"/>"); mockBotTagHandler = new AIMLbot.AIMLTagHandlers.that(this.mockBot, this.mockUser, mockQuery, mockRequest, mockResult, testNode); Assert.Equal("Result 4", mockBotTagHandler.Transform()); testNode = getNode("<that index=\"2,2\"/>"); mockBotTagHandler = new AIMLbot.AIMLTagHandlers.that(this.mockBot, this.mockUser, mockQuery, mockRequest, mockResult, testNode); Assert.Equal("Result 2", mockBotTagHandler.Transform()); testNode = getNode("<that index=\"1,3\"/>"); mockBotTagHandler = new AIMLbot.AIMLTagHandlers.that(this.mockBot, this.mockUser, mockQuery, mockRequest, mockResult, testNode); Assert.Equal("", mockBotTagHandler.Transform()); testNode = getNode("<that index=\"3\"/>"); mockBotTagHandler = new AIMLbot.AIMLTagHandlers.that(this.mockBot, this.mockUser, mockQuery, mockRequest, mockResult, testNode); Assert.Equal("", mockBotTagHandler.Transform()); }
public void testEvaluateWithStarWildCardThat() { string path = "Test 1 <that> Test * 1 <topic> topic"; string template = "<srai>TEST</srai>"; this.mockNode = new AIMLbot.Utils.Node(); this.mockNode.addCategory(path, template, "filename"); string pathAlt = "Alt Test <that> that <topic> topic"; string templateAlt = "<srai>TEST ALT</srai>"; this.mockNode.addCategory(pathAlt, templateAlt, "filename"); this.mockRequest = new Request("Test 1", new User("1", this.mockBot), this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery(path); Assert.AreEqual("<srai>TEST</srai>", this.mockNode.evaluate("Test 1 <that> Test WILDCARD WORDS 1 <topic> topic", this.mockQuery, this.mockRequest, AIMLbot.Utils.MatchState.UserInput, new StringBuilder())); Assert.AreEqual("WILDCARD WORDS", (string)this.mockQuery.ThatStar[0]); }
public void testCustomTagsMultipleInstances() { this.mockBot = new Bot(); this.mockBot.loadSettings(); this.mockBot.loadAIMLFromFiles(); AIMLbot.User mockUser = new User("1", this.mockBot); AIMLbot.Request mockRequest = new Request("Pig latin", mockUser, this.mockBot); AIMLbot.Result mockResult = new Result(mockUser, this.mockBot, mockRequest); AIMLbot.Utils.SubQuery mockSubquery = new AIMLbot.Utils.SubQuery("PIG LATIN <that> * <topic> *"); FileInfo fi = new FileInfo(this.pathToCustomTagDll); Assert.AreEqual(true, fi.Exists); this.mockBot.loadCustomTagHandlers(this.pathToCustomTagDll); XmlNode pigLatin1 = AIMLbot.Utils.AIMLTagHandler.getNode("<piglatin>(All the world is a stage!)</piglatin>"); XmlNode pigLatin2 = AIMLbot.Utils.AIMLTagHandler.getNode("<piglatin>(All the world is still a stage!)</piglatin>"); AIMLbot.Utils.AIMLTagHandler taghandler1 = this.mockBot.getBespokeTags(mockUser, mockSubquery, mockRequest, mockResult, pigLatin1); AIMLbot.Utils.AIMLTagHandler taghandler2 = this.mockBot.getBespokeTags(mockUser, mockSubquery, mockRequest, mockResult, pigLatin2); Assert.AreEqual("(Allway ethay orldway isway away agestay!)", taghandler1.Transform()); Assert.AreEqual("(Allway ethay orldway isway illstay away agestay!)", taghandler2.Transform()); }
public void testEvaluateWithWildcardsInDifferentPartsOfPath() { string path = "Test * 1 <that> Test * 1 <topic> Test * 1"; string template = "<srai>TEST</srai>"; this.mockNode = new AIMLbot.Utils.Node(); this.mockNode.addCategory(path, template, "filename"); string pathAlt = "Alt Test <that> that <topic> topic"; string templateAlt = "<srai>TEST ALT</srai>"; this.mockNode.addCategory(pathAlt, templateAlt, "filename"); this.mockRequest = new Request("Test 1", new User("1", this.mockBot), this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery(path); Assert.AreEqual("<srai>TEST</srai>", this.mockNode.evaluate("Test WILDCARD USER WORDS 1 <that> Test WILDCARD THAT WORDS 1 <topic> Test WILDCARD TOPIC WORDS 1", this.mockQuery, this.mockRequest, AIMLbot.Utils.MatchState.UserInput, new StringBuilder())); Assert.AreEqual("WILDCARD USER WORDS", (string)this.mockQuery.InputStar[0]); Assert.AreEqual("WILDCARD THAT WORDS", (string)this.mockQuery.ThatStar[0]); Assert.AreEqual("WILDCARD TOPIC WORDS", (string)this.mockQuery.TopicStar[0]); }
public void testCustomTagsMultipleInstances() { this.mockBot = new Bot(); this.mockBot.loadSettings(); this.mockBot.loadAIMLFromFiles(); AIMLbot.User mockUser = new User("1", this.mockBot); AIMLbot.Request mockRequest = new Request("Pig latin",mockUser,this.mockBot); AIMLbot.Result mockResult = new Result(mockUser,this.mockBot,mockRequest); AIMLbot.Utils.SubQuery mockSubquery = new AIMLbot.Utils.SubQuery("PIG LATIN <that> * <topic> *"); FileInfo fi = new FileInfo(this.pathToCustomTagDll); Assert.AreEqual(true, fi.Exists); this.mockBot.loadCustomTagHandlers(this.pathToCustomTagDll); XmlNode pigLatin1 = AIMLbot.Utils.AIMLTagHandler.getNode("<piglatin>(All the world is a stage!)</piglatin>"); XmlNode pigLatin2 = AIMLbot.Utils.AIMLTagHandler.getNode("<piglatin>(All the world is still a stage!)</piglatin>"); AIMLbot.Utils.AIMLTagHandler taghandler1 = this.mockBot.getBespokeTags(mockUser, mockSubquery, mockRequest, mockResult, pigLatin1); AIMLbot.Utils.AIMLTagHandler taghandler2 = this.mockBot.getBespokeTags(mockUser, mockSubquery, mockRequest, mockResult, pigLatin2); Assert.AreEqual("(Allway ethay orldway isway away agestay!)",taghandler1.Transform()); Assert.AreEqual("(Allway ethay orldway isway illstay away agestay!)", taghandler2.Transform()); }
public void testEvaluateWith_WildCardUserInput() { string path = "_ Test 1 <that> that <topic> topic"; string template = "<srai>TEST</srai>"; this.mockNode = new AIMLbot.Utils.Node(); this.mockNode.addCategory(path, template, "filename"); string pathAlt = "Alt Test <that> that <topic> topic"; string templateAlt = "<srai>TEST ALT</srai>"; this.mockNode.addCategory(pathAlt, templateAlt, "filename"); this.mockRequest = new Request("Test 1", new User("1", this.mockBot), this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery(path); Assert.AreEqual("<srai>TEST</srai>", this.mockNode.evaluate("WILDCARD WORDS Test 1 <that> that <topic> topic", this.mockQuery, this.mockRequest, AIMLbot.Utils.MatchState.UserInput, new StringBuilder())); Assert.AreEqual("WILDCARD WORDS", (string)this.mockQuery.InputStar[0]); }
public void testEvaluateTimeOut() { this.mockBot = new Bot(); this.mockBot.loadSettings(); this.mockBot.GlobalSettings.addSetting("timeout", "10"); this.mockNode = new AIMLbot.Utils.Node(); this.mockRequest = new Request("Test 1", new User("1", this.mockBot), this.mockBot); string path = "Test 1 <that> that <topic> topic"; string template = "<srai>TEST</srai>"; this.mockNode = new AIMLbot.Utils.Node(); this.mockNode.addCategory(path, template, "filename"); string pathAlt = "Alt Test <that> that <topic> topic"; string templateAlt = "<srai>TEST ALT</srai>"; this.mockNode.addCategory(pathAlt, templateAlt, "filename"); this.mockQuery = new AIMLbot.Utils.SubQuery(path); System.Threading.Thread.Sleep(20); string result = this.mockNode.evaluate("Test 1 <that> that <topic> topic", this.mockQuery, this.mockRequest, AIMLbot.Utils.MatchState.UserInput, new StringBuilder()); Assert.AreEqual(string.Empty, result); Assert.AreEqual(true, this.mockRequest.hasTimedOut); }
public void testEvaluateWithInternationalCharset() { string path = "中 文 <that> * <topic> *"; string template = "中文 (Chinese)"; this.mockNode = new AIMLbot.Utils.Node(); this.mockNode.addCategory(path, template, "filename"); string path2 = "日 本 語 <that> * <topic> *"; string template2 = "日 本 語 (Japanese)"; this.mockNode.addCategory(path2, template2, "filename"); string path3 = "Русский язык <that> * <topic> *"; string template3 = "Русский язык (Russian)"; this.mockNode.addCategory(path3, template3, "filename"); this.mockRequest = new Request("中 文", new User("1", this.mockBot), this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery(path); Assert.AreEqual("中文 (Chinese)", this.mockNode.evaluate("中 文 <that> * <topic> *", this.mockQuery, this.mockRequest, AIMLbot.Utils.MatchState.UserInput, new StringBuilder())); this.mockRequest = new Request("日 本 語", new User("1", this.mockBot), this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery(path); Assert.AreEqual("日 本 語 (Japanese)", this.mockNode.evaluate("日 本 語 <that> * <topic> *", this.mockQuery, this.mockRequest, AIMLbot.Utils.MatchState.UserInput, new StringBuilder())); this.mockRequest = new Request("Русский язык", new User("1", this.mockBot), this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery(path); Assert.AreEqual("Русский язык (Russian)", this.mockNode.evaluate("Русский язык <that> * <topic> *", this.mockQuery, this.mockRequest, AIMLbot.Utils.MatchState.UserInput, new StringBuilder())); }
public void testEvaluateWithMultipleWildcardsSwitched() { string path = "Test * 1 _ <that> Test * 1 _ <topic> Test _ 1 *"; string template = "<srai>TEST</srai>"; this.mockNode = new AIMLbot.Utils.Node(); this.mockNode.addCategory(path, template, "filename"); string pathAlt = "Alt Test <that> that <topic> topic"; string templateAlt = "<srai>TEST ALT</srai>"; this.mockNode.addCategory(pathAlt, templateAlt, "filename"); this.mockRequest = new Request("Test 1", new User("1", this.mockBot), this.mockBot); this.mockQuery = new AIMLbot.Utils.SubQuery(path); Assert.AreEqual("<srai>TEST</srai>", this.mockNode.evaluate("Test FIRST USER 1 SECOND USER <that> Test FIRST THAT 1 SECOND THAT <topic> Test FIRST TOPIC 1 SECOND TOPIC", this.mockQuery, this.mockRequest, AIMLbot.Utils.MatchState.UserInput, new StringBuilder())); Assert.AreEqual(2, this.mockQuery.InputStar.Count); Assert.AreEqual("SECOND USER", (string)this.mockQuery.InputStar[0]); Assert.AreEqual("FIRST USER", (string)this.mockQuery.InputStar[1]); Assert.AreEqual(2, this.mockQuery.ThatStar.Count); Assert.AreEqual("SECOND THAT", (string)this.mockQuery.ThatStar[0]); Assert.AreEqual("FIRST THAT", (string)this.mockQuery.ThatStar[1]); Assert.AreEqual(2, this.mockQuery.TopicStar.Count); Assert.AreEqual("SECOND TOPIC", (string)this.mockQuery.TopicStar[0]); Assert.AreEqual("FIRST TOPIC", (string)this.mockQuery.TopicStar[1]); }