예제 #1
0
        public void InvokeTest()
        {
            var actionInvoked = new bool[3];

            Action @delegate = null;

            void Action1()
            {
                actionInvoked[0] = true;
            }

            void Action2()
            {
                actionInvoked[1] = true;
            }

            void Action3()
            {
                actionInvoked[2] = true;
            }

            @delegate += Action1;
            @delegate += Action2;
            @delegate += Action3;

            AI4EUtilsDelegateExtensions.InvokeAll(@delegate, d => d());

            Assert.IsTrue(actionInvoked.All());
        }
예제 #2
0
        public void InvokeExceptionTest()
        {
            var actionInvoked = new bool[3];

            Action @delegate = null;

            void Action1()
            {
                actionInvoked[0] = true;
            }

            void Action2()
            {
                actionInvoked[1] = true;
                throw new CustomException();
            }

            void Action3()
            {
                actionInvoked[2] = true;
            }

            @delegate += Action1;
            @delegate += Action2;
            @delegate += Action3;

            Assert.ThrowsException <CustomException>(() =>
            {
                AI4EUtilsDelegateExtensions.InvokeAll(@delegate, d => d());
            });

            Assert.IsTrue(actionInvoked.All());
        }
예제 #3
0
        public void InvokeMultipleExceptionTest()
        {
            var actionInvoked = new bool[3];

            Action @delegate = null;

            void Action1()
            {
                actionInvoked[0] = true;
            }

            void Action2()
            {
                actionInvoked[1] = true;
                throw new CustomException();
            }

            void Action3()
            {
                actionInvoked[2] = true;
                throw new CustomException2();
            }

            @delegate += Action1;
            @delegate += Action2;
            @delegate += Action3;

            var exception = Assert.ThrowsException <AggregateException>(() =>
            {
                AI4EUtilsDelegateExtensions.InvokeAll(@delegate, d => d());
            });

            Assert.IsTrue(actionInvoked.All());
            Assert.AreEqual(2, exception.InnerExceptions.Count());
            Assert.IsTrue(exception.InnerExceptions.Any(p => p is CustomException));
            Assert.IsTrue(exception.InnerExceptions.Any(p => p is CustomException2));
        }