Exemple #1
0
        public void AddAndReadDynamicPropertiesTest()
        {
            // strong typing first
            var ex = new ExpandoInstance();
            ex.Name = "Alex";
            ex.Entered = DateTime.Now;

            // create dynamic and create new props
            dynamic exd = ex;
            string company = "Exclr8";
            int count = 10;

            exd.Company = company;
            exd.Accesses = count;

            Assert.AreEqual(exd.Company, company);
            Assert.AreEqual(exd.Accesses, count);
        }
Exemple #2
0
        public void ExandoModesTest()
        {
            // Set standard properties
            var ex = new ExpandoInstance();
            ex.Name = "Alex";
            ex.Entered = DateTime.Now;

            // set dynamic properties
            dynamic exd = ex;
            exd.Company = "Exclr8";
            exd.Accesses = 10;

            // set dynamic properties as dictionary
            ex["Address"] = "64 Atlantic Beach Drive";
            ex["Email"] = "*****@*****.**";
            ex["TotalOrderAmounts"] = 51233.99M;

            // iterate over all properties dynamic and native
            foreach (var prop in ex.GetProperties(true))
            {
                Console.WriteLine(prop.Key + " " + prop.Value);
            }

            // you can access plain properties both as explicit or dynamic
            Assert.AreEqual(ex.Name, exd.Name, "Name doesn't match");

            // You can access dynamic properties either as dynamic or via IDictionary
            Assert.AreEqual(exd.Company, ex["Company"] as string, "Company doesn't match");
            Assert.AreEqual(exd.Address, ex["Address"] as string, "Name doesn't match");

            // You can access strong type properties via the collection as well (inefficient though)
            Assert.AreEqual(ex.Name, ex["Name"] as string);

            // dynamic can access everything
            Assert.AreEqual(ex.Name, exd.Name);  // native property
            Assert.AreEqual(ex["TotalOrderAmounts"], exd.TotalOrderAmounts); // dictionary property
        }
Exemple #3
0
        public void AddAndReadDynamicIndexersTest()
        {
            var ex = new ExpandoInstance();
            ex.Name = "Alex";
            ex.Entered = DateTime.Now;

            string address = "64 Atlantic Beach Drive";

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

            dynamic exd = ex;

            Assert.AreEqual(exd.Address, ex["Address"]);
            Assert.AreEqual(exd.Contacted, true);
        }
Exemple #4
0
        public void XmlSerializeTest()
        {
            var ex = new ExpandoInstance();
            ex.Name = "Alex";
            ex.Entered = DateTime.Now;

            string address = "64 Atlantic Beach Drive";

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

            dynamic exd = ex;
            exd.Count = 10;
            exd.Completed = DateTime.Now.AddHours(2);

            string xml;
            Core.Utilities.Serialization.SerializeObject(ex, out xml);

            Console.WriteLine(xml);

            ExpandoInstance ex2 = Core.Utilities.Serialization.DeSerializeObject(xml, typeof(ExpandoInstance)) as ExpandoInstance;

            Assert.IsNotNull(ex2);
            Assert.IsTrue(ex2["Address"] as string == address);
        }
Exemple #5
0
        public void JsonSerializeTest()
        {
            var ex = new ExpandoInstance();
            ex.Name = "Alex";
            ex.Entered = DateTime.Now;

            string address = "64 Atlantic Beach Drive";

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

            dynamic exd = ex;
            exd.Count = 10;
            exd.Completed = DateTime.Now.AddHours(2);


           
            Console.WriteLine("*** Serialized Native object:");
            Console.WriteLine(Core.Utilities.Serialization.SerializeObjectToJson(ex));
            Console.WriteLine();

            Console.WriteLine();
            Console.WriteLine("*** Serialized Dynamic object:");
            Console.WriteLine(Core.Utilities.Serialization.SerializeObjectToJson(exd));
            Console.WriteLine();
        }
Exemple #6
0
        public void IterateOverDynamicPropertiesTest()
        {
            var ex = new ExpandoInstance();
            ex.Name = "Alex";
            ex.Entered = DateTime.Now;

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

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

            // 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))
            {
                Console.WriteLine(prop.Key + " " + prop.Value);
            }
        }
Exemple #7
0
        public void DynamicAccessToPropertyTest()
        {
            // Set standard properties
            var ex = new ExpandoInstance();
            ex.Name = "Alex";
            ex.Entered = DateTime.Now;

            // turn into dynamic
            dynamic exd = ex;

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

        }
Exemple #8
0
        public void PropertyAsIndexerTest()
        {
            // Set standard properties
            var ex = new ExpandoInstance();
            ex.Name = "Alex";
            ex.Entered = DateTime.Now;

            Assert.AreEqual(ex.Name, ex["Name"]);
            Assert.AreEqual(ex.Entered, ex["Entered"]);
        }