Example #1
0
        public void DefaultValueTest()
        {
            var O = new TypedExpando();

            O.AddProperty("Age", typeof(int));

            var D = (dynamic)O;

            Assert.AreEqual(0, D.Age);
        }
Example #2
0
        public void PropertyTypeMismatchTest()
        {
            var O = new TypedExpando();

            O.AddProperty("Age", typeof(int));

            var D = (dynamic)O;

            D.Age = "Hello";
        }
Example #3
0
        public void PropertyDoesNotExistsTest()
        {
            var O = new TypedExpando();

            O.AddProperty("Name", typeof(string));

            var D = (dynamic)O;

            D.Age = 22;
        }
Example #4
0
        public void PropertyTypeMatchTest()
        {
            var O = new TypedExpando();

            O.AddProperty("Numbers", typeof(IReadOnlyList <int>));

            var D = (dynamic)O;

            D.Numbers = new[] { 1, 2, 3 };

            Assert.IsTrue(((IEnumerable <int>)D.Numbers).SequenceEqual(new[] { 1, 2, 3 }));
        }
Example #5
0
        public void GetSetTest()
        {
            var O = new TypedExpando();

            O.AddProperty("Name", typeof(string));
            O.AddProperty("Age", typeof(int));

            var D = (dynamic)O;

            D.Name = "Rafa";
            D.Age  = 22;

            Assert.AreEqual("Rafa", D.Name);
            Assert.AreEqual(22, D.Age);
        }
Example #6
0
        public void NullableValueTest()
        {
            var O = new TypedExpando();

            O.AddProperty("Age", typeof(int?));

            //Initial value should be null
            var D = (dynamic)O;

            Assert.AreEqual(null, D.Age);

            D.Age = 20;
            Assert.AreEqual(20, D.Age);

            D.Age = null;
            Assert.AreEqual(null, D.Age);
        }
Example #7
0
        public void PropertyChangedTestIndexer()
        {
            var O = new TypedExpando(new[] {
                Tuple.Create("Age", typeof(int)),
                Tuple.Create("Name", typeof(string))
            }
                                     );

            bool Ok = false;

            O.PropertyChanged += (sender, e) =>
            {
                Assert.AreEqual("Name", e.PropertyName);
                Ok = true;
            };
            var D = (dynamic)O;

            D["Name"] = "Rafa";

            Assert.IsTrue(Ok);
        }
Example #8
0
        public void PropertyChangedAccesorTest()
        {
            var O = new TypedExpando(new[] {
                Tuple.Create("Age", typeof(int)),
                Tuple.Create("Name", typeof(string))
            }
                                     );

            bool Ok = false;

            O.PropertyChanged += (sender, e) =>
            {
                Assert.AreEqual("Name", e.PropertyName);
                Ok = true;
            };
            var D = (dynamic)O;

            var CTD = (ICustomTypeDescriptor)O;

            CTD.GetProperties().Cast <PropertyDescriptor>().First(x => x.Name == "Name").SetValue(CTD, "Rafael");

            Assert.IsTrue(Ok);
        }