public void Execute_Object_Call_Entry_Assembly_Without_Explicit_Reference() { //Mock entry assembly for test envirioment ContextHelper.SetEntryAssembly(typeof(CSharpObjectHandlerTest).Assembly); var rs = new RiveScript(); rs.setHandler("csharp", new CSharp()); rs.stream(new[] { "", "", "", "+ show context data", "- data is: <call>context</call>", "", "> object context csharp", "", " using RiveScript.Tests.Helper;", "", " return ContextHelper.Property;", "< object", "" }); rs.sortReplies(); rs.reply("show context data") .AssertAreEqual("data is: Context_Property"); }
public void Execute_Full_Object_Call_With_Parameter() { var rs = new RiveScript(); rs.setHandler("csharp", new CSharp()); rs.stream(new[] { "", "+ sum # and #", "- result is: <call>sum <star1> <star2></call>", "", "> object sum csharp", " return (int.Parse(args[0]) + int.Parse(args[1])).ToString();", "< object", "" }); rs.sortReplies(); var result = rs.reply("sum 10 and 15"); Assert.AreEqual("result is: 25", result); }
public void Execute_Full_Object_Call_Without_Parameter() { var rs = new RiveScript(); rs.setHandler("csharp", new CSharp()); rs.stream(new[] { "", "+ who is current user", "- current user is: <call>current</call>", "", "> object current csharp", " return rs.currentUser();", "< object", "" }); rs.sortReplies(); var result = rs.reply("who is current user"); Assert.AreEqual("current user is: default", result); }
public void Execute_Full_Object_Call_Custom_References() { var rs = new RiveScript(); rs.setHandler("csharp", new CSharp()); rs.stream(new[] { "", "+ show data enum", "- enum is: <call>test</call>", "", "> object test csharp", " reference System.Data.dll;", " using System.Data;", "", " return DataRowState.Added.ToString();", "< object", "" }); rs.sortReplies(); var result = rs.reply("show data enum"); Assert.AreEqual("enum is: Added", result); }
public static void setCSharpHandler(this RiveScript rs) { rs.setHandler(Constants.CSharpHandlerName, new CSharp()); }