示例#1
0
        public void When_rethrows_if_no_handler()
        {
            var exceptions = new Dictionary<Type, Action>();
            var exception = new ExceptionHandler(exceptions);
            int invoke = 0;
            Action action = () => invoke++;

            Assert.Throws<NotImplementedException>(() => exception.On<AbandonedMutexException>(action).When(() => { throw new NotImplementedException(); }));
        }
示例#2
0
        public void When_invokes_target()
        {
            var exceptions = new Dictionary<Type, Action>();
            var exception = new ExceptionHandler(exceptions);
            int invoke = 0;
            Action action = () => Console.WriteLine("caught");

            exception.On<Exception>(action).When(() => invoke++);
            invoke.ShouldBe(1);
        }
示例#3
0
        public void When_invokes_exception_handler_on_exception()
        {
            var exceptions = new Dictionary<Type, Action>();
            var exception = new ExceptionHandler(exceptions);
            int invoke = 0;
            Action action = () => invoke++;

            exception.On<NotImplementedException>(action).When(() => { throw new NotImplementedException(); });

            invoke.ShouldBe(1);
        }
示例#4
0
        public void On_Exception_adds_exception_and_target_invocation()
        {
            var exceptions = new Dictionary<Type, Action>();
            var exception = new ExceptionHandler(exceptions);
            Action action = () => Console.WriteLine("caught");

            exception.On<Exception>(action);

            exceptions.ContainsKey(typeof(Exception));
            exceptions.ContainsValue(action);
            exceptions.Count.ShouldBe(1);
        }