Пример #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");
     }
 }
Пример #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");
            }
        }