Example #1
0
        public void GetterArrayTest()
        {
            var tArray = new int[] { 1, 2, 3 };

            IStringIntIndexer tTest = ImpromptuGet.Create <IStringIntIndexer>(tArray);

            Assert.AreEqual(tArray[2].ToString(), tTest[2]);
        }
Example #2
0
        public void GetterEventTest()
        {
            var tActsLike = ImpromptuGet.Create <IEvent>(new PocoEvent());
            var tSet      = false;

            tActsLike.Event += (obj, args) => tSet = true;

            tActsLike.OnEvent(null, null);
            Assert.AreEqual(true, tSet);
        }
Example #3
0
        public void GetterEventTest2()
        {
            var tActsLike = ImpromptuGet.Create <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);
        }
Example #4
0
        public void TestAnonInterface()
        {
            var tInterface = ImpromptuGet.Create <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());
        }
Example #5
0
        public void DynamicAnnonymousWrapper()
        {
            var tData = new Dictionary <int, string> {
                { 1, "test" }
            };
            var tDyn = ImpromptuGet.Create(new
            {
                Test1          = 1,
                Test2          = "2",
                IsGreaterThan5 = Return <bool> .Arguments <int>(it => it > 5),
                ClearData      = ReturnVoid.Arguments(() => tData.Clear())
            });

            Assert.AreEqual(1, tDyn.Test1);
            Assert.AreEqual("2", tDyn.Test2);
            Assert.AreEqual(true, tDyn.IsGreaterThan5(6));
            Assert.AreEqual(false, tDyn.IsGreaterThan5(4));

            Assert.AreEqual(1, tData.Count);
            tDyn.ClearData();
            Assert.AreEqual(0, tData.Count);
        }