Example #1
0
        public void DynamicObjectEqualsTest()
        {
            var tDictionary = new Dictionary <string, object>
            {
                { "Test1", 1 },
                { "Test2", 2 },
                {
                    "TestD", new Dictionary <string, object>()
                    {
                        { "TestA", "A" },
                        { "TestB", "B" }
                    }
                }
            };

            dynamic tDynamic    = new DynamicObjects.Dictionary(tDictionary);
            dynamic tNotDynamic = new DynamicObjects.Dictionary(tDictionary);


            Dynamic.ApplyEquivalentType(tDynamic, typeof(IDynamicDict));
            Dynamic.ApplyEquivalentType(tNotDynamic, typeof(INonDynamicDict));

            Assert.AreEqual(tDynamic, tNotDynamic);

            Assert.AreEqual(tDynamic, tDictionary);

            Assert.AreEqual(tNotDynamic, tDictionary);
        }
Example #2
0
        public void DictionaryNullMethodsTest()
        {
            dynamic tNew = new DynamicObjects.Dictionary();

            Dynamic.ApplyEquivalentType(tNew, typeof(ISimpleStringMethod));

            Assert.That((object)tNew.StartsWith("Te"), Is.False);
        }
Example #3
0
        public void GetterArrayTest()
        {
            var tArray = new int[] { 1, 2, 3 };

            dynamic tTest = new DynamicObjects.Get(tArray);

            Dynamic.ApplyEquivalentType(tTest, typeof(IStringIntIndexer));

            Assert.AreEqual(tArray[2].ToString(), tTest[2]);
        }
Example #4
0
        public void GetterEventTest2()
        {
            dynamic dynEvent = new DynamicObjects.Get(new PocoEvent());

            Dynamic.ApplyEquivalentType(dynEvent, typeof(IEvent));
            var tSet = false;
            EventHandler <EventArgs> tActsLikeOnEvent = (obj, args) => tSet = true;

            dynEvent.Event += tActsLikeOnEvent;
            dynEvent.Event -= tActsLikeOnEvent;
            dynEvent.OnEvent(null, null);
            Assert.AreEqual(false, tSet);
        }
Example #5
0
        public void InterfaceDictionaryWrappedTest()
        {
            var tDictionary = new Dictionary <string, object>
            {
                { "Test1", 1 },
                { "Test2", 2L },
                { "Test3", 1 },
                { "Test4", "Two" },
                {
                    "TestD", new Dictionary <string, object>()
                    {
                        { "TestA", "A" },
                        { "TestB", "B" }
                    }
                }
            };

            dynamic tDynamic    = new DynamicObjects.Dictionary(tDictionary);
            dynamic tNotDynamic = new DynamicObjects.Dictionary(tDictionary);


            Dynamic.ApplyEquivalentType(tDynamic, typeof(IDynamicDict));
            Dynamic.ApplyEquivalentType(tNotDynamic, typeof(INonDynamicDict));


            Assert.AreEqual(tDynamic, tNotDynamic);

            Assert.AreEqual(1, tDynamic.Test1);
            Assert.AreEqual(2L, tDynamic.Test2);
            Assert.AreEqual(TestEnum.One, tDynamic.Test3);
            Assert.AreEqual(TestEnum.Two, tDynamic.Test4);

            Assert.AreEqual("A", tDynamic.TestD.TestA);
            Assert.AreEqual("B", tDynamic.TestD.TestB);

            Assert.AreEqual(1, tNotDynamic.Test1);
            Assert.AreEqual(2L, tNotDynamic.Test2);
            Assert.AreEqual(TestEnum.One, tNotDynamic.Test3);
            Assert.AreEqual(TestEnum.Two, tNotDynamic.Test4);

            Assert.AreEqual(typeof(Dictionary <string, object>), tNotDynamic.TestD.GetType());
            Assert.AreEqual(typeof(DynamicObjects.Dictionary), tDynamic.TestD.GetType());
        }
Example #6
0
        public void TestAnonInterface()
        {
            dynamic tInterface = new DynamicObjects.Get(new
            {
                CopyArray =
                    ReturnVoid.Arguments <Array, int>(
                        (ar, i) => Enumerable.Range(1, 10)),
                Count          = 10,
                IsSynchronized = false,
                SyncRoot       = this,
                GetEnumerator  =
                    Return <IEnumerator> .Arguments(
                        () => Enumerable.Range(1, 10).GetEnumerator())
            });

            Dynamic.ApplyEquivalentType(tInterface, typeof(ICollection), typeof(IEnumerable));

            Assert.AreEqual(10, tInterface.Count);
            Assert.AreEqual(false, tInterface.IsSynchronized);
            Assert.AreEqual(this, tInterface.SyncRoot);
            Assert.That((object)tInterface.GetEnumerator(), Is.InstanceOf <IEnumerator>());
        }