public void WhenActionSucceeds_ShouldNotRunOnErrorAndReturnTwo() { var isOnErrorExecuted = false; var returnValue = ExWrapper.Try <Exception, object>( () => 1 + 1, ex => { isOnErrorExecuted = true; }); Assert.AreEqual(2, returnValue); Assert.IsFalse(isOnErrorExecuted); }
public void WhenActionSucceeds_ShouldNotRunOnErrorAndReturnTrue() { var isOnErrorExecuted = false; var returnValue = ExWrapper.Try( () => { }, () => { isOnErrorExecuted = true; }); Assert.IsTrue(returnValue); Assert.IsFalse(isOnErrorExecuted); }
public void WhenExceptionThrownInAction_ShouldRunOnErrorAndReturnDefault() { var isOnErrorExecuted = false; var returnValue = ExWrapper.Try <Exception, object>( () => { throw new Exception("Crash, MOFO!."); }, () => { isOnErrorExecuted = true; }); Assert.AreEqual(default(object), returnValue); Assert.IsTrue(isOnErrorExecuted); }
public void WhenExceptionThrownInAction_ShouldRunOnErrorAndReturnFalse() { var isOnErrorExecuted = false; var returnValue = ExWrapper.Try( () => { throw new Exception("Crash, MOFO!."); }, () => { isOnErrorExecuted = true; }); Assert.IsFalse(returnValue); Assert.IsTrue(isOnErrorExecuted); }
public void WhenExceptionThrownInAction_ShouldRunOnErrorWithExceptionAndReturnFalse() { Exception receivedException = null; Exception thrownException = null; ExWrapper.Try( () => { thrownException = new Exception("Get that!"); throw thrownException; }, ex => { receivedException = ex; }); Assert.AreEqual(thrownException, receivedException); Assert.AreEqual(thrownException.Message, receivedException.Message); }
public void WhenExceptionThrownInAction_ShouldRunOnErrorWithExceptionAndReturnDefault() { Exception receivedException = null; Exception thrownException = null; var returnValue = ExWrapper.Try <Exception, object>( () => { thrownException = new Exception("Get that!"); throw thrownException; }, ex => { receivedException = ex; }); Assert.AreEqual(thrownException, receivedException); Assert.AreEqual(thrownException.Message, receivedException.Message); Assert.AreEqual(default(object), returnValue); }
public void WhenExceptionThrownInAction_ShouldNotThrowExceptionAndReturnDefault() { var returnValue = new object(); try { returnValue = ExWrapper.Try <Exception, object>( () => { throw new Exception("Throw that!"); }); } catch (Exception) { Assert.Fail("Should not throw Exception."); } finally { Assert.AreEqual(default(object), returnValue); } }
public void WhenExceptionThrownInAction_ShouldNotThrowExceptionAndReturnFalse() { var returnValue = false; try { returnValue = ExWrapper.Try( () => { throw new Exception("Throw that!"); }); } catch (Exception) { Assert.Fail("Should not throw Exception."); } finally { Assert.IsFalse(returnValue); } }
public void WhenExceptionThrownInError_ShouldThrowException2() { ExWrapper.Try <Exception, object>( () => { throw new Exception("Forces call to OnError."); }, () => { throw new Exception("Thrown from OnError."); }); }
private ExWrapper(Action action, ExWrapper prev = null) { _action = action; _prev = prev; }
public void WhenOtherExceptionThrownInAction_ShouldThrowOtherException2() { ExWrapper.Try <ArgumentNullException, object>( () => { throw new ArgumentException(); }); }
public void WhenActionIsNull_ShouldThrowArgumentNullException2() { ExWrapper.Try <Exception, object>(null); }
public void WhenActionIsNull_ShouldThrowArgumentNullException() { ExWrapper.Try(null); }