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