public void GetterArrayTest() { var tArray = new int[] { 1, 2, 3 }; IStringIntIndexer tTest = Impromptu.Create <Get, IStringIntIndexer>(tArray); Assert.AreEqual(tArray[2].ToString(), tTest[2]); }
public void GetterEventTest() { var tActsLike = Impromptu.Create <Get, IEvent>(new PocoEvent()); var tSet = false; tActsLike.Event += (obj, args) => tSet = true; tActsLike.OnEvent(null, null); Assert.AreEqual(true, tSet); }
public void GetterEventTest2() { var tActsLike = Impromptu.Create <Get, IEvent>(new PocoEvent()); var tSet = false; EventHandler <EventArgs> tActsLikeOnEvent = (obj, args) => tSet = true; tActsLike.Event += tActsLikeOnEvent; tActsLike.Event -= tActsLikeOnEvent; tActsLike.OnEvent(null, null); Assert.AreEqual(false, tSet); }
public void TestAnonInterface() { var tInterface = Impromptu.Create <Get, ICollection>(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()) }); Assert.AreEqual(10, tInterface.Count); Assert.AreEqual(false, tInterface.IsSynchronized); Assert.AreEqual(this, tInterface.SyncRoot); Assert.AreEqual(true, tInterface.GetEnumerator().MoveNext()); }
public void DynamicObjectEqualsTest() { var tDictionary = new Dictionary <string, object> { { "Test1", 1 }, { "Test2", 2 }, { "TestD", new Dictionary <string, object>() { { "TestA", "A" }, { "TestB", "B" } } } }; dynamic tDynamic = Impromptu.Create <Dictionary, IDynamicDict>(tDictionary); dynamic tNotDynamic = Impromptu.Create <Dictionary, INonDynamicDict>(tDictionary); Assert.AreEqual(tDynamic, tNotDynamic); Assert.AreEqual(tDynamic, tDictionary); Assert.AreEqual(tNotDynamic, tDictionary); }
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 = Impromptu.Create <Dictionary, IDynamicDict>(tDictionary); dynamic tNotDynamic = Impromptu.Create <Dictionary, INonDynamicDict>(tDictionary); 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(Dictionary), tDynamic.TestD.GetType()); }