public void Register(ContainerBuilder builder) { ScriptEngine e = new ScriptEngine(); e.AddFunction <string, string, object>("data", (repository, query) => { return(string.Format("{0}/{1}/{2}/{3}", repository, query, 0, 10)); }); e.AddFunction <string, string, int, object>("data", (repository, query, index) => { return(string.Format("{0}/{1}/{2}/{3}", repository, query, index, 10)); }); e.AddFunction <string, string, int, int, object>("data", (repository, query, index, pageSize) => { return(string.Format("{0}/{1}/{2}/{3}", repository, query, index, pageSize)); }); builder.RegisterInstance <ScriptEngine>(e).SingleInstance().Named <ScriptEngine>(DynamicDataRegister.DynamicDataProvider); }
public void EvaluateString() { var script = new ScriptEngine(); script.AddFunction<string, string>("append", message => { return message + " World!"; }); var code = new StringBuilder(); code.AppendLine("return append('Hello')"); // Should run log, pass { indent: 1 } Assert.AreEqual("Hello World!", script.Evaluate<string>(code.ToString())); }
public void EvaluateString() { var script = new ScriptEngine(); script.AddFunction <string, string>("append", message => { return(message + " World!"); }); var code = new StringBuilder(); code.AppendLine("return append('Hello')"); // Should run log, pass { indent: 1 } Assert.AreEqual("Hello World!", script.Evaluate <string>(code.ToString())); }