示例#1
0
            public void ShouldHandleTheGoodExceptionUsingCustomHandler()
            {
                var exceptionService = new ExceptionService();

                exceptionService.Register <CodeExceptionHandler>();

                exceptionService.Register <DivideByZeroException>(
                    exception => Assert.AreEqual("trying to divide by zero", exception.Message));

                ExceptionTester.CallMethodAndExpectException <CodeException>(() => exceptionService.Process(() => { throw new CodeException(2); }));
                exceptionService.Process(() => { throw new DivideByZeroException("trying to divide by zero"); });
                exceptionService.Process(() => { throw new CodeException(3); });
            }
示例#2
0
            public void ProceedToSucceed()
            {
                var exceptionService = new ExceptionService();
                var value = string.Empty;

                exceptionService.Register<ArgumentException>(exception => { value = exception.Message; });
                value = exceptionService.Process(() => (1 + 1).ToString(CultureInfo.InvariantCulture));

                Assert.AreEqual("2", value);

                exceptionService.Process<string>(() => { throw new ArgumentException("achieved"); });

                Assert.AreEqual("achieved", value);
            }
示例#3
0
            public void ProceedToSucceed()
            {
                var exceptionService = new ExceptionService();
                var value            = string.Empty;

                exceptionService.Register <ArgumentException>(exception => { value = exception.Message; });
                value = exceptionService.Process(() => (1 + 1).ToString(CultureInfo.InvariantCulture));

                Assert.AreEqual("2", value);

                exceptionService.Process <string>(() => { throw new ArgumentException("achieved"); });

                Assert.AreEqual("achieved", value);
            }
示例#4
0
            public void ShouldSucceedToHandleUsingRegisteredHandler()
            {
                var exceptionService = new ExceptionService();

                exceptionService.Register <DivideByZeroExceptionHandler>();

                exceptionService.Process(() => { throw new DivideByZeroException("trying to divide by zero"); });
            }
示例#5
0
            public void ProceedToFail()
            {
                var exceptionService = new ExceptionService();
                var value = string.Empty;

                exceptionService.Register<ArgumentException>(exception => { value = exception.Message; });
                exceptionService.Process<string>(() => { throw new ArgumentOutOfRangeException("achieved"); });

                Assert.AreNotEqual("achieved", value);
            }
示例#6
0
            public void ProceedToFail()
            {
                var exceptionService = new ExceptionService();
                var value            = string.Empty;

                exceptionService.Register <ArgumentException>(exception => { value = exception.Message; });
                exceptionService.Process <string>(() => { throw new ArgumentOutOfRangeException("achieved"); });

                Assert.AreNotEqual("achieved", value);
            }
示例#7
0
            public void ProceedToSucceed()
            {
                var exceptionService = new ExceptionService();
                var value            = string.Empty;

                exceptionService.Register <ArgumentException>(exception => { value = exception.Message; }, null);
                exceptionService.Process(() => { throw new ArgumentException("achieved"); });

                Assert.AreEqual("achieved", value);
            }
示例#8
0
 public void ThrowsArgumentNullExceptionForNullParameterInGeneric()
 {
     var exceptionService = new ExceptionService();
     ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => exceptionService.Process<int>(null));
 }
示例#9
0
            public void ThrowsArgumentNullExceptionForNullParameterInNonGeneric()
            {
                var exceptionService = new ExceptionService();

                ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => exceptionService.Process(null));
            }