Example #1
0
        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);
        }
Example #2
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
 private Task <bool> TextEnteredHandler(string value)
 {
     return(SafeExecution.TryCatchWithResultAsync(() => _autoLocalConnector.ExecuteCommand(value),
                                                  exception => _recorder.DefaultException(this, exception)));;
 }