public void ExecuteAssignDotCommandOnNativeProperty() { Person person = new Person(); Machine machine = new Machine(); machine.RootContext.SetLocalValue("p", person); var leftvalue = (DotExpression)(new Parser("p.FirstName")).ParseExpression(); var value = new ConstantExpression("Adam"); AssignDotExpressions cmd = new AssignDotExpressions(leftvalue, value); var result = cmd.Evaluate(machine.RootContext); Assert.IsNotNull(result); Assert.AreEqual("Adam", result); Assert.AreEqual("Adam", person.FirstName); }
public void ExecuteAssignDotCommand() { Machine machine = new Machine(); var @class = new DynamicClass("Dog"); var method = new DefinedFunction((new Parser("@name = name")).ParseCommand(), new string[] { "name" }, machine.RootContext); @class.SetInstanceMethod("name=", method); var nero = @class.CreateInstance(); machine.RootContext.SetLocalValue("nero", nero); var leftvalue = (DotExpression)(new Parser("nero.name")).ParseExpression(); var value = new ConstantExpression("Nero"); AssignDotExpressions cmd = new AssignDotExpressions(leftvalue, value); var result = cmd.Evaluate(machine.RootContext); Assert.IsNotNull(result); Assert.AreEqual("Nero", result); Assert.AreEqual("Nero", nero.GetValue("name")); }
public void ExecuteAssignDotCommandWithUnknownMethod() { Machine machine = new Machine(); var @class = new DynamicClass("Dog"); var nero = @class.CreateInstance(); machine.RootContext.SetLocalValue("nero", nero); var leftvalue = (DotExpression)(new Parser("nero.name")).ParseExpression(); var value = new ConstantExpression("Nero"); AssignDotExpressions cmd = new AssignDotExpressions(leftvalue, value); try { cmd.Evaluate(machine.RootContext); Assert.Fail(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(NoMethodError)); } }