public void ReadOnlyProperty_instance_setter()
        {
            var instance = new TestClass();
            dynamic expando = new Expando(instance);

            expando.ReadOnlyFullName = "John Doe";
        }
Exemple #2
0
        public void PublicProperty_default()
        {
            dynamic expando = new Expando();

            expando.Property = "value";
            Assert.AreEqual("value", expando.Property);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
        public void PrivateProperty_instance_getter()
        {
            var instance = new TestClass();
            dynamic expando = new Expando(instance);

            Assert.Throws<MemberAccessException>(() => { var value = expando.PrivateAge; });
        }
Exemple #6
0
        public void ReadOnlyProperty_instance_setter()
        {
            var instance = new TestClass();
            dynamic expando = new Expando(instance);

            Assert.Throws<MemberAccessException>(() => expando.ReadOnlyFullName = "John Doe");
        }
Exemple #7
0
 public void Constructor_instance()
 {
     var instance = new TestClass();
     dynamic expando = new Expando(instance);
 }
Exemple #8
0
 public void Constructor_default()
 {
     dynamic expando = new Expando();
 }
Exemple #9
0
        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;
        }
Exemple #10
0
        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.");
            }
        }
Exemple #11
0
        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);
        }
Exemple #12
0
        public void Dynamic_Property(object age)
        {
            dynamic expando = new Expando();
            expando.Age = age;

            Assert.AreEqual(age, expando.Age);
        }
Exemple #13
0
        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);
        }
Exemple #14
0
        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";
        }