public void HandleException_SpecificException_TargetThrowsDifferentException_NotHandledByGivenDelegate() { bool isHandled = false; SafeExecutionHelpers.HandleException <SpecificException>(new DifferentException(), (ex) => isHandled = true); Assert.False(isHandled); }
public void HandleException_SpecificException_TargetThrowsSpecificException_IsHandledByGivenDelegate() { BeforeEachTest(); bool isHandled = false; SafeExecutionHelpers.HandleException <SpecificException>(new SpecificException(), (ex) => isHandled = true); Assert.True(isHandled); AfterEachTest(); }
public void HandleException_SpecificExceptionThrown_NoHandlers_Throws() { SafeExecutionHelpers.RevertToDefaultImplementation(); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); //MockForms.Init(); //For Device.BeginInvokeOnMainThread var exception = new Exception(); var handler = new Mock <Action <SpecificException> >(); Assert.Throws <SafeExecutionHelpersException>(() => SafeExecutionHelpers.HandleException(exception, handler.Object)); }
public void HandleException_SpecificException_TargetThrowsDifferentException_NotHandledByGivenDelegate() { SafeExecutionHelpers.RevertToDefaultImplementation(); SafeExecutionHelpers.SetDefaultExceptionHandler((ex) => { }); bool isHandled = false; SafeExecutionHelpers.HandleException <SpecificException>(new DifferentException(), (ex) => isHandled = true); Assert.False(isHandled); }
public void HandleException_SpecificExceptionThrown_NoHandlers_Throws() { SafeExecutionHelpers.RevertToDefaultImplementation(); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); var exception = new Exception(); var handler = new Mock <Action <SpecificException> >(); Assert.Throws <SafeExecutionHelpersException>(() => SafeExecutionHelpers.HandleException(exception, handler.Object)); }
public void HandleException_Exception_SpecificExceptionOnException_NotHandled() { SafeExecutionHelpers.Initialize(); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); var exception = new Exception(); var handler = new Mock <Action <SpecificException> >(); SafeExecutionHelpers.HandleException(exception, handler.Object); Assert.Empty(handler.Invocations); }
public void HandleException_SpecificException_SpecificExceptionOnException_Handled() { SafeExecutionHelpers.Initialize(); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); var exception = new SpecificException(); var handler = new Mock <Action <SpecificException> >(); SafeExecutionHelpers.HandleException(exception, handler.Object); handler.Verify(h => h.Invoke(exception)); }
public void HandleException_Exception_SpecificExceptionOnException_NotHandled() { SafeExecutionHelpers.RevertToDefaultImplementation(); SafeExecutionHelpers.SetDefaultExceptionHandler((ex) => { }); var exception = new Exception(); var handler = new Mock <Action <SpecificException> >(); SafeExecutionHelpers.HandleException(exception, handler.Object); Assert.Empty(handler.Invocations); }
public void HandleException_Exception_ExceptionOnException_Handled() { SafeExecutionHelpers.RevertToDefaultImplementation(); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); var exception = new Exception(); var handler = new Mock <Action <Exception> >(); SafeExecutionHelpers.HandleException(exception, handler.Object); handler.Verify(h => h.Invoke(exception)); }
public void HandleException_ShouldRethrow_Throws() { Xamarin.Forms.Mocks.MockForms.Init(); //For Device.BeginInvokeOnMainThread SafeExecutionHelpers.Initialize(shouldAlwaysRethrowException: true); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); var exception = new NullReferenceException(); var handler = new Mock <Action <Exception> >(); Assert.Throws <NullReferenceException>(() => SafeExecutionHelpers.HandleException(exception, handler.Object)); handler.Verify(h => h.Invoke(exception)); }
public void HandleException_ShouldRethrow_Throws() { SafeExecutionHelpers.RevertToDefaultImplementation(); //MockForms.Init(); //For Device.BeginInvokeOnMainThread SafeExecutionHelpers.Configure(s => s.ShouldAlwaysRethrowException = true); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); var exception = new NullReferenceException(); var handler = new Mock <Action <Exception> >(); Assert.Throws <NullReferenceException>(() => SafeExecutionHelpers.HandleException(exception, handler.Object)); handler.Verify(h => h.Invoke(exception)); }
public void HandleException_DefaultHandlerSet_Exception_ExceptionOnException_DefaultNotInvoked() { SafeExecutionHelpers.Initialize(); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); var defaultHandler = new Mock <Action <Exception> >(); SafeExecutionHelpers.SetDefaultExceptionHandler(defaultHandler.Object); var exception = new Exception(); SafeExecutionHelpers.HandleException(exception, new Mock <Action <Exception> >().Object); Assert.Empty(defaultHandler.Invocations); }
public void HandleException_DefaultHandlerSet_Exception_SpecificExceptionOnException__DefaultInvoked() { SafeExecutionHelpers.RevertToDefaultImplementation(); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); var defaultHandler = new Mock <Action <Exception> >(); SafeExecutionHelpers.SetDefaultExceptionHandler(defaultHandler.Object); var exception = new Exception(); var handler = new Mock <Action <SpecificException> >(); SafeExecutionHelpers.HandleException(exception, handler.Object); Assert.NotEmpty(defaultHandler.Invocations); }