public void ReadOnlyProperty_instance_setter() { var instance = new TestClass(); dynamic expando = new Expando(instance); expando.ReadOnlyFullName = "John Doe"; }
public void PublicProperty_default() { dynamic expando = new Expando(); expando.Property = "value"; Assert.AreEqual("value", expando.Property); }
public void ReadOnlyProperty_instance_getter() { var instance = new TestClass(); dynamic expando = new Expando(instance); expando.Name = "John"; Assert.AreEqual(" John", expando.ReadOnlyFullName); Assert.AreEqual(" John", instance.ReadOnlyFullName); }
public void PublicProperty_instance() { var instance = new TestClass(); dynamic expando = new Expando(instance); expando.Name = "John"; Assert.AreEqual("John", expando.Name); Assert.AreEqual("John", instance.Name); }
public void PrivateProperty_instance_getter() { var instance = new TestClass(); dynamic expando = new Expando(instance); Assert.Throws<MemberAccessException>(() => { var value = expando.PrivateAge; }); }
public void ReadOnlyProperty_instance_setter() { var instance = new TestClass(); dynamic expando = new Expando(instance); Assert.Throws<MemberAccessException>(() => expando.ReadOnlyFullName = "John Doe"); }
public void Constructor_instance() { var instance = new TestClass(); dynamic expando = new Expando(instance); }
public void Constructor_default() { dynamic expando = new Expando(); }
public bool TryInvokeMember_Method_with_instance(int age) { var instance = new DerivedExpando(); instance.Age = age; dynamic expando = new Expando(instance); var isOld = expando.IsOld(); return isOld; }
public async Task Dynamic_Property_non_concurrent() { dynamic expando = new Expando(); Exception exception = null; Action accessor = () => { try { for (var i = 0; i <= 2000; i++) { expando["Prop" + Thread.CurrentThread.Name + i] = Thread.CurrentThread.Name + i; } } catch (Exception ex) { exception = ex; } }; var tasks = new List<Task>(); for (var j = 0; j < 200; j++) { tasks.Add(Task.Factory.StartNew(accessor)); } // normally it should crash await Task.WhenAll(tasks); if (exception == null) { Assert.Inconclusive("If the inner dictionary did not crash it doesn't mean it is thread safe."); } }
public async Task Dynamic_Property_concurrent() { dynamic expando = new Expando(isThreadSafe: true); Action accessor = () => { for (var i = 0; i <= 2000; i++) { expando["Prop" + Thread.CurrentThread.Name + i] = Thread.CurrentThread.Name + i; } }; var tasks = new List<Task>(); for (var j = 0; j < 200; j++) { tasks.Add(Task.Factory.StartNew(accessor)); } await Task.WhenAll(tasks); }
public void Dynamic_Property(object age) { dynamic expando = new Expando(); expando.Age = age; Assert.AreEqual(age, expando.Age); }
public void TryInvokeMember_Func_property_with_instance() { dynamic instance = new Expando(new TestClass()); instance.GetName = (Func<int, string>)(age => $"John Doe: {age}"); var name = instance.GetName(30); Assert.AreEqual("John Doe: 30", name); }
public void PrivateProperty_instance_setter() { var instance = new TestClass(); dynamic expando = new Expando(instance); Assert.Throws<MemberAccessException>(() => expando.PrivateAge = "John Doe"); }
public void PrivateProperty_instance_getter() { var instance = new TestClass(); dynamic expando = new Expando(instance); var age = expando.PrivateAge; }
public void PrivateProperty_instance_setter() { var instance = new TestClass(); dynamic expando = new Expando(instance); expando.PrivateAge = "John Doe"; }