Exemplo n.º 1
0
        public void IterateOverDynamicPropertiesTest()
        {
            var ex = new ExpandoInstance
            {
                Name    = "Name",
                Entered = DateTime.Now
            };

            dynamic exd = ex;

            exd.Company  = "Company";
            exd.Accesses = 10;

            // Dictionary pseudo implementation
            ex["Count"] = 10;
            ex["Type"]  = "MyType";

            // Dictionary Count - 2 dynamic props added
            Assert.IsTrue(ex.Properties.Count == 4);

            // iterate over all properties
            foreach (KeyValuePair <string, object> prop in exd.GetProperties(true))
            {
                Trace.WriteLine(prop.Key + " " + prop.Value);
            }
        }
Exemplo n.º 2
0
        public void PropertyAsIndexerTest()
        {
            // Set standard properties
            var ex = new ExpandoInstance
            {
                Name    = "Name",
                Entered = DateTime.Now
            };

            Assert.AreEqual(ex.Name, ex["Name"]);
            Assert.AreEqual(ex.Entered, ex["Entered"]);
        }
Exemplo n.º 3
0
        public void DynamicAccessToPropertyTest()
        {
            // Set standard properties
            var ex = new ExpandoInstance
            {
                Name    = "Name",
                Entered = DateTime.Now
            };

            // turn into dynamic
            dynamic exd = ex;

            // Dynamic can access
            Assert.AreEqual(ex.Name, exd.Name);
            Assert.AreEqual(ex.Entered, exd.Entered);
        }
Exemplo n.º 4
0
        public void AddAndReadDynamicIndexersTest()
        {
            var ex = new ExpandoInstance
            {
                Name    = "Name",
                Entered = DateTime.Now
            };

            ex["Address"]   = "Address 123";
            ex["Contacted"] = true;

            dynamic exd = ex;

            Assert.AreEqual(exd.Address, ex["Address"]);
            Assert.AreEqual(exd.Contacted, true);
        }
Exemplo n.º 5
0
        public void MixInObjectInstanceTest()
        {
            // Create expando an mix-in second objectInstanceTest
            var ex = new ExpandoInstance(new Address())
            {
                Name    = "Name",
                Entered = DateTime.Now
            };

            // create dynamic
            dynamic exd = ex;

            // values should show Addresses initialized values (not null)
            Trace.WriteLine(string.Format("address:{0}", exd.FullAddress as string));
            Trace.WriteLine(string.Format("email:{0}", exd.Email as string));
            Trace.WriteLine(string.Format("phone:{0}", exd.Phone as string));
        }
Exemplo n.º 6
0
        public void AddAndReadDynamicIndexersTest()
        {
            var ex = new ExpandoInstance
            {
                Name = "Name",
                Entered = DateTime.Now
            };

            ex["Address"] = "Address 123";
            ex["Contacted"] = true;

            dynamic exd = ex;

            Assert.AreEqual(exd.Address, ex["Address"]);
            Assert.AreEqual(exd.Contacted, true);
        }
Exemplo n.º 7
0
        public void PropertyAsIndexerTest()
        {
            // Set standard properties
            var ex = new ExpandoInstance
            {
                Name = "Name",
                Entered = DateTime.Now
            };

            Assert.AreEqual(ex.Name, ex["Name"]);
            Assert.AreEqual(ex.Entered, ex["Entered"]);
        }
Exemplo n.º 8
0
        public void MixInObjectInstanceTest()
        {
            // Create expando an mix-in second objectInstanceTest
            var ex = new ExpandoInstance(new Address())
            {
                Name = "Name",
                Entered = DateTime.Now
            };

            // create dynamic
            dynamic exd = ex;

            // values should show Addresses initialized values (not null)
            Trace.WriteLine(string.Format("address:{0}", exd.FullAddress as string));
            Trace.WriteLine(string.Format("email:{0}", exd.Email as string));
            Trace.WriteLine(string.Format("phone:{0}", exd.Phone as string));
        }
Exemplo n.º 9
0
        public void IterateOverDynamicPropertiesTest()
        {
            var ex = new ExpandoInstance
            {
                Name = "Name",
                Entered = DateTime.Now
            };

            dynamic exd = ex;
            exd.Company = "Company";
            exd.Accesses = 10;

            // Dictionary pseudo implementation
            ex["Count"] = 10;
            ex["Type"] = "MyType";

            // Dictionary Count - 2 dynamic props added
            Assert.IsTrue(ex.Properties.Count == 4);

            // iterate over all properties
            foreach (KeyValuePair<string, object> prop in exd.GetProperties(true))
            {
                Trace.WriteLine(prop.Key + " " + prop.Value);
            }
        }
Exemplo n.º 10
0
        public void DynamicAccessToPropertyTest()
        {
            // Set standard properties
            var ex = new ExpandoInstance
            {
                Name = "Name",
                Entered = DateTime.Now
            };

            // turn into dynamic
            dynamic exd = ex;

            // Dynamic can access
            Assert.AreEqual(ex.Name, exd.Name);
            Assert.AreEqual(ex.Entered, exd.Entered);
        }