示例#1
0
        public void Add_Dumplication_Passes()
        {
            var predicate = new SmartDelegate <BasicUsagePassesDelegate>();

            Assert.IsFalse(predicate.IsValid);
            Assert.IsNull(predicate.Instance);

            //test point
            BasicUsagePassesDelegate incrementFunc = () => {; };

            predicate.Add(incrementFunc);
            predicate.Add(incrementFunc);

            Assert.IsTrue(predicate.IsValid);
            Assert.IsNotNull(predicate.Instance);
            Assert.AreEqual(1, predicate.RegistedDelegateCount);
        }
示例#2
0
        public void Contains_Passes()
        {
            var predicate = new SmartDelegate <BasicUsagePassesDelegate>();

            Assert.IsFalse(predicate.IsValid);
            Assert.IsNull(predicate.Instance);

            //test point
            BasicUsagePassesDelegate incrementFunc = () => {; };

            Assert.IsFalse(predicate.Contains(incrementFunc));

            predicate.Add(incrementFunc);
            Assert.IsTrue(predicate.Contains(incrementFunc));

            var copy = incrementFunc;

            Assert.IsTrue(predicate.Contains(copy));

            predicate.Remove(incrementFunc);
            Assert.IsFalse(predicate.Contains(incrementFunc));
        }
示例#3
0
        public void BasicUsagePasses()
        {
            var predicate = new SmartDelegate <BasicUsagePassesDelegate>();

            Assert.IsFalse(predicate.IsValid);
            Assert.IsNull(predicate.Instance);

            int count = 0;
            BasicUsagePassesDelegate incrementFunc = () => { count++; };

            predicate.Set(incrementFunc);
            Assert.IsTrue(predicate.IsValid);
            Assert.IsNotNull(predicate.Instance);

            predicate.Instance.Invoke();
            Assert.AreEqual(1, count);

            predicate.Remove(incrementFunc);
            Assert.IsFalse(predicate.IsValid);
            Assert.IsNull(predicate.Instance);

            predicate.Add(incrementFunc);
            Assert.IsTrue(predicate.IsValid);
            Assert.IsNotNull(predicate.Instance);


            var predicate2 = new SmartDelegate <BasicUsagePassesDelegate>(predicate);

            Assert.IsTrue(predicate2.IsValid);
            Assert.IsNotNull(predicate2.Instance);

            count = 0;
            predicate2.Instance.Invoke();
            Assert.AreEqual(1, count);

            predicate.Clear();
            Assert.IsFalse(predicate.IsValid);
            Assert.IsNull(predicate.Instance);
        }