Core/CafeLib.Core.UnitTests/DynamicTest.cs
/// <summary>
/// Summary method that demonstrates some
/// of the basic behaviors.
/// 
/// More specific tests are provided below
/// </summary>
Summary method that demonstrates some
of the basic behaviors.

More specific tests are provided below
Summary method that demonstrates some of the basic behaviors . More specific tests are provided below
[Fact]
        public void ExpandoBasicTests()
        {
            var ex = new User
            {
                Name = "Rick",
                Email = "rstrahl@whatsa.com",
                Active = true
            };
            dynamic exd = ex;
            exd.Entered = DateTime.Now;
            exd.Company = "West Wind";
            exd.Accesses = 10;
            ex["Address"] = "32 Kaiea";
            ex["Email"] = "rick@west-wind.com";
            ex["TotalOrderAmounts"] = 51233.99M;
            foreach (var prop in ex.GetProperties(true))
            {
                _testOutputHelper.WriteLine(prop.Key + " " + prop.Value);
            }
            Assert.Equal(ex.Name, exd.Name);
            Assert.Equal(exd.Company, (string)ex["Company"]);
            Assert.Equal(exd.Address, (string) ex["Address"]);
            Assert.Equal(ex.Name, (string)ex["Name"]);
            Assert.Equal(ex.Name, exd.Name); 
            Assert.Equal(ex["TotalOrderAmounts"], exd.TotalOrderAmounts); 
        }
[ Fact ] public void ExpandoBasicTests ( ) { var ex = new User { Name = " " , Email = " " , Active = true } ; dynamic exd = ex ; exd . Entered = DateTime . Now ; exd . Company = " " ; exd . Accesses = 10 ; ex [ " " ] = " " ; ex [ " " ] = " " ; ex [ " " ] = 51233.99M ; foreach ( var prop in ex . GetProperties ( true ) ) { _testOutputHelper . WriteLine ( prop . Key + " " + prop . Value ) ; } Assert . Equal ( ex . Name , exd . Name ) ; Assert . Equal ( exd . Company , ( string ) ex [ " " ] ) ; Assert . Equal ( exd . Address , ( string ) ex [ " " ] ) ; Assert . Equal ( ex . Name , ( string ) ex [ " " ] ) ; Assert . Equal ( ex . Name , exd . Name ) ; Assert . Equal ( ex [ " " ] , exd . TotalOrderAmounts ) ; }
Summary method that demonstrates some
of the basic behaviors.
Summary method that demonstrates some of the basic behaviors .
// Set standard properties // set dynamic properties that don't exist on type // set dynamic properties as dictionary // iterate over all properties dynamic and native // you can access plain properties both as explicit or dynamic // You can access dynamic properties either as dynamic or via IDictionary // You can access strong type properties via the collection as well (inefficient though) // dynamic can access everything // native property // dictionary property