Пример #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);
        }