Exemplo n.º 1
1
        public void ReadOnlyProperty_instance_setter()
        {
            var instance = new TestClass();
            dynamic expando = new Expando(instance);

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

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

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

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

            Assert.AreEqual(age, expando.Age);
        }
Exemplo n.º 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);
        }
Exemplo n.º 14
0
        public void PrivateProperty_instance_setter()
        {
            var instance = new TestClass();
            dynamic expando = new Expando(instance);

            Assert.Throws<MemberAccessException>(() => expando.PrivateAge = "John Doe");
        }
Exemplo n.º 15
0
        public void PrivateProperty_instance_getter()
        {
            var instance = new TestClass();
            dynamic expando = new Expando(instance);

            var age = expando.PrivateAge;
        }
Exemplo n.º 16
0
        public void PrivateProperty_instance_setter()
        {
            var instance = new TestClass();
            dynamic expando = new Expando(instance);

            expando.PrivateAge = "John Doe";
        }