Exemplo n.º 1
0
 public void GivenGlobalAddedToEngine_WhenScriptUsesGlobalFunction_ThenResultReturned()
 {
     using (var engine = new IEJavaScriptEngine())
     {
         engine.AddGlobalValue("Test", new GlobalData());
         engine.LoadLibrary("function go() { return Test.hello('John'); }");
         var result = engine.CallFunction <string>("go");
         result.ShouldEqual("Hello, John");
     }
 }
Exemplo n.º 2
0
        public void GivenGlobalAddedToEngine_WhenScriptUsesGlobalFunctionWithCallback_ThenCallbackInvoked()
        {
            using (var engine = new IEJavaScriptEngine())
            {
                engine.AddGlobalValue("Test", new GlobalData());
                engine.LoadLibrary(@"
function go() { 
    var result;
    Test.process(function(x) {
        result = x;
    });
    return result;
}");
                var result = engine.CallFunction <string>("go");
                result.ShouldEqual("done");
            }
        }