public void DefineMethod() { DynamicObject dynobj = new DynamicObject(); ICommand body = new ReturnCommand(new VariableExpression("Name")); Function function = new Function(null, body); dynobj.SetValue("GetName", function); object result = dynobj.GetValue("GetName"); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(ICallable)); Assert.IsTrue(result == function); }
public void GetValueFromPrototypeAndSetValueInObject() { Function function = new Function(null, null); DynamicObject dynobj = new DynamicObject(function); DynamicObject prototype = new DynamicObject(); function.SetValue("prototype", prototype); prototype.SetValue("x", 10); dynobj.SetValue("x", 20); Assert.AreEqual(20, dynobj.GetValue("x")); Assert.AreEqual(10, prototype.GetValue("x")); }
public void GetUndefinedForUndefinedValue() { DynamicObject dynobj = new DynamicObject(); Assert.AreSame(Undefined.Instance, dynobj.GetValue("Foo")); }
public void UsePrototypeForGetValue() { Function function = new Function(null, null); DynamicObject dynobj = new DynamicObject(function); DynamicObject prototype = new DynamicObject(); function.SetValue("prototype", prototype); prototype.SetValue("x", 10); Assert.AreEqual(10, dynobj.GetValue("x")); }
public void SetAndGetValue() { DynamicObject dynobj = new DynamicObject(); dynobj.SetValue("Foo", "Bar"); Assert.AreEqual("Bar", dynobj.GetValue("Foo")); }
public void RemoveValue() { DynamicObject dynobj = new DynamicObject(); dynobj.SetValue("name", "Adam"); Assert.IsTrue(dynobj.HasName("name")); dynobj.RemoveValue("name"); Assert.IsFalse(dynobj.HasName("name")); Assert.AreSame(Undefined.Instance, dynobj.GetValue("name")); }
public void GetValueFromPrototypeAndSetValueInObject() { DynamicObject prototype = new DynamicObject(); this.function.SetValue("prototype", prototype); prototype.SetValue("x", 10); this.dynobj.SetValue("x", 20); Assert.AreEqual(20, this.dynobj.GetValue("x")); Assert.AreEqual(10, prototype.GetValue("x")); }