public void TryCatchWithResultAsync_OnException_ShouldCatch() { var wasCatched = false; async Task <bool> TestMethod() { throw new Exception("test exception"); } var task = SafeExecution.TryCatchWithResultAsync(() => TestMethod(), exception => wasCatched = true); Assert.True(wasCatched); Assert.False(task.Result); }
public void TryCatchWithResultAsync_OnException_ShouldReturnDefault() { var wasCatched = false; async Task <int> TestMethod() { throw new Exception("test exception"); } var task = SafeExecution.TryCatchWithResultAsync(() => TestMethod(), exception => wasCatched = true, 6); Assert.True(wasCatched); Assert.Equal(6, task.Result); }
public void TryCatchWithResultAsync_OnSuccess_ShouldReturnResult() { var wasCatched = false; async Task <bool> TestMethod() { return(true); } var task = SafeExecution.TryCatchWithResultAsync(() => TestMethod(), exception => wasCatched = true); Assert.False(wasCatched); Assert.True(task.Result); }
private Task <bool> TextEnteredHandler(string value) { return(SafeExecution.TryCatchWithResultAsync(() => _autoLocalConnector.ExecuteCommand(value), exception => _recorder.DefaultException(this, exception)));; }