public void ReplacedNonExistingLocalObject_Failure() { using (var expression = new CSharpScript("1 + obj.int_Field")) { var obj = new TestClass { int_Field = 2 }; expression.ReplaceObjectInScope("obj", obj); Assert.AreEqual(4, expression.Execute()); } }
public void RunExpressionTwiceReferencingReplacedLocalObject_Success() { using (var expression = new CSharpScript("1 + obj.int_Field")) { var obj = new TestClass { int_Field = 2 }; expression.AddObjectInScope("obj", obj); Assert.AreEqual(3, expression.Execute()); var obj2 = new TestClass { int_Field = 3 }; expression.ReplaceObjectInScope("obj", obj2); Assert.AreEqual(4, expression.Execute()); } }
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)); } }