public void InvokeMethodTwice_Success() { using (var expression = new CSharpScript()) { expression.AddMember( @"public int Test() { return 10; }"); Assert.AreEqual(10, expression.Invoke("Test", null)); Assert.AreEqual(10, expression.Invoke("Test", null)); } }
public void CreateTwoObjectsMaintainingDifferentState_Success() { using (var script = new CSharpScript()) { script.AddMember( @"public void Test(int a) { global.a = a; }"); script.AddExpression("global.a"); var obj_a = script.CreateScriptObject(); var obj_b = script.CreateScriptObject(); Assert.AreEqual(null, script.Invoke(obj_a, "Test", new object[] { 5 })); Assert.AreEqual(null, script.Invoke(obj_b, "Test", new object[] { 10 })); Assert.AreEqual(5, script.Execute(obj_a)); Assert.AreEqual(10, script.Execute(obj_b)); } }
public void InvokeMethodWithParams_Success() { using (var expression = new CSharpScript()) { expression.AddMember( @"public int Test(int a) { return a; }"); Assert.AreEqual(5, expression.Invoke("Test", new object[] { 5 })); } }
public void CreateTwoObjectsWithObjectInScopeResettingIt_Success() { using (var script = new CSharpScript()) { script.AddMember( @"public void Test(int a) { global.a = a; }"); script.AddExpression("global.a + i"); script.AddObjectInScope("i", 1); var obj_a = script.CreateScriptObject(); var obj_b = script.CreateScriptObject(); Assert.AreEqual(null, script.Invoke(obj_a, "Test", new object[] { 5 })); Assert.AreEqual(null, script.Invoke(obj_b, "Test", new object[] { 10 })); Assert.AreEqual(6, script.Execute(obj_a)); Assert.AreEqual(11, script.Execute(obj_b)); script.ReplaceObjectInScope(obj_a, "i", 2); Assert.AreEqual(7, script.Execute(obj_a)); Assert.AreEqual(11, script.Execute(obj_b)); } }
public void InvokeVoidMethodWithParamsModifyGlobals_Success() { using (var expression = new CSharpScript()) { expression.AddMember( @"public void Test(int a) { global.a = a; }"); expression.AddExpression("global.a"); Assert.AreEqual(null, expression.Invoke("Test", new object[] { 5 })); Assert.AreEqual(5, expression.Execute()); } }
public void InvokeMethodWithParamsModifyGlobalsMultiAppDomain_Success() { using (var expression = new CSharpScript()) { expression.ExecuteInSeparateAppDomain = true; expression.AddMember( @"public int Test(int a) { global.a = 20; return a; }"); expression.AddExpression("global.a"); Assert.AreEqual(5, expression.Invoke("Test", new object[] { 5 })); Assert.AreEqual(20, expression.Execute()); } }