Ejemplo n.º 1
0
        public void TestFilterChainT1()
        {
            var filter = new CatLib.FilterChain.FilterChain();

            var chain = filter.Create <string>();

            var data   = "123";
            var isCall = false;

            chain.Add((inData, next) =>
            {
                if (inData == data)
                {
                    isCall = true;
                }
                next(inData);
            });
            chain.Add((in1Data, next) =>
            {
                next(in1Data);
            });
            var completeCall = false;

            chain.Do(data, (in1) =>
            {
                completeCall = true;
            });

            Assert.AreEqual(2, chain.FilterList.Length);
            Assert.AreEqual(true, isCall);
            Assert.AreEqual(true, completeCall);
        }
Ejemplo n.º 2
0
        public void NoFilterChainCallT1()
        {
            var filter = new CatLib.FilterChain.FilterChain();
            var chain  = filter.Create <string>();

            var isCall = false;

            chain.Do("", (i) =>
            {
                isCall = !isCall;
            });

            chain.Do("");
            Assert.AreEqual(true, isCall);
        }
Ejemplo n.º 3
0
        public void RecursiveCallChain()
        {
            var filter = new CatLib.FilterChain.FilterChain();

            var chain = filter.Create <string>();

            var data   = "123";
            var isCall = false;

            chain.Add((inData, next) =>
            {
                if (inData == data)
                {
                    isCall = !isCall;
                }
                if (isCall)
                {
                    chain.Do(data, (in1) =>
                    {
                    });
                }
                next(inData);
            });

            chain.Add((in1Data, next) =>
            {
                next(in1Data);
            });

            var completeCall = false;

            chain.Do(data, (in1) =>
            {
                completeCall = true;
            });
            Assert.AreEqual(false, isCall);
            Assert.AreEqual(true, completeCall);
        }
Ejemplo n.º 4
0
        public void TestFilterChainT1T2T3()
        {
            var filter = new CatLib.FilterChain.FilterChain();

            var chain = filter.Create <string, string, string>();

            var data1 = "123";
            var data2 = "222";
            var data3 = "333";

            var isCall = false;

            chain.Add((in1Data, in2Data, in3Data, next) =>
            {
                if (in1Data == data1 && in2Data == data2 && in3Data == data3)
                {
                    isCall = true;
                }
                next(in1Data, in2Data, in3Data);
            });

            chain.Add((in1Data, in2Data, in3Data, next) =>
            {
                next(in1Data, in2Data, in3Data);
            });

            var completeCall = false;

            chain.Do(data1, data2, data3, (in1, in2, in3) =>
            {
                completeCall = true;
            });

            Assert.AreEqual(2, chain.FilterList.Length);
            Assert.AreEqual(true, isCall);
            Assert.AreEqual(true, completeCall);
        }