Ejemplo n.º 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); });
            }
Ejemplo n.º 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);
            }
Ejemplo n.º 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);
            }
Ejemplo n.º 4
0
            public void ShouldSucceedToHandleUsingRegisteredHandler()
            {
                var exceptionService = new ExceptionService();

                exceptionService.Register <DivideByZeroExceptionHandler>();

                exceptionService.Process(() => { throw new DivideByZeroException("trying to divide by zero"); });
            }
Ejemplo n.º 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);
            }
Ejemplo n.º 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);
            }
Ejemplo n.º 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);
            }
Ejemplo n.º 8
0
 public void ThrowsArgumentNullExceptionForNullParameterInGeneric()
 {
     var exceptionService = new ExceptionService();
     ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => exceptionService.Process<int>(null));
 }
Ejemplo n.º 9
0
            public void ThrowsArgumentNullExceptionForNullParameterInNonGeneric()
            {
                var exceptionService = new ExceptionService();

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