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_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_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); }
public void Execute_TargetThrows_HandlesException() { SafeExecutionHelpers.RevertToDefaultImplementation(); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); var mockHelpers = new Mock <ISafeExecutionHelpers>(); SafeExecutionHelpers.Implementation = mockHelpers.Object; Exception exception = new Exception(); var command = new SafeCommand(executeAction: () => throw exception); //Assert.Throws<Exception>(() => command.Execute(null)); command.Execute(null); mockHelpers.Verify(h => h.HandleException <Exception>(exception, null)); SafeExecutionHelpers.RevertToDefaultImplementation(); }
private void AfterEachTest() { SafeExecutionHelpers.Initialize(false); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); }
private void AfterEachTest() { SafeExecutionHelpers.RevertToDefaultImplementation(); SafeExecutionHelpers.Configure(s => s.ShouldAlwaysRethrowException = false); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); }
private void BeforeEachTest() { SafeExecutionHelpers.Configure(s => s.ShouldAlwaysRethrowException = false); SafeExecutionHelpers.RemoveDefaultExceptionHandler(); }