/// <summary> /// Generates Error Reports for books with specific titles /// Facilitates testing of error reporting. /// </summary> private static void CheckForFakeTestErrors(string title) { const string fakeProblemMessage = "Fake problem for development/testing purposes"; var fakeException = new ApplicationException("Fake exception for development/testing purposes"); if (title == "Error NotifyUser NoReport") { // Tests a path through libPalaso directly (goes thru overloads 1, 2, 5) ErrorReport.NotifyUserOfProblem(fakeProblemMessage); } else if (title == "Error NotifyUser LongMessage") { var longMessageBuilder = new StringBuilder(); while (longMessageBuilder.Length < 3000) { longMessageBuilder.Append(fakeProblemMessage + " "); } ErrorReport.NotifyUserOfProblem(longMessageBuilder.ToString()); } else if (title == "Error NotifyUser Report NoRetry") { // Tests another path through libPalaso directly (goes thru overloads 3, 4, 5) ErrorReport.NotifyUserOfProblem((Exception)null, fakeProblemMessage); } else if (title == "Error NotifyUser Report NoRetry 2") { // Tests a path where you need to go through the ErrorReportUtils adapters // (follow-up actions automatically invoked) ErrorReportUtils.NotifyUserOfProblem("", null, null, fakeProblemMessage); } else if (title == "Error NotifyUser Report Retry") { // Tests a path where you need to go through the ErrorReportUtils adapters // (follow-up actions automatically invoked) var secondaryButtonLabel = LocalizationManager.GetString("ErrorReportDialog.Retry", "Retry"); ErrorReportUtils.NotifyUserOfProblem(secondaryButtonLabel, ErrorReportUtils.TestAction, fakeException, fakeProblemMessage); } else if (title == "Error NotifyUser Custom") { // Tests another path where you need to go through the ErrorReportUtils adapters // (follow-up actions are NOT auto-invoked) var result = ErrorReportUtils.NotifyUserOfProblem(new ShowAlwaysPolicy(), "CustomReport", ErrorResult.Yes, "CustomRetry", ErrorResult.Retry, fakeProblemMessage); string message = null; switch (result) { case ErrorResult.Yes: message = "Report button clicked."; break; case ErrorResult.Retry: message = "Retry button clicked."; break; default: break; } if (message != null) { MessageBox.Show(message); } } else if (title == "Error ReportNonFatalException") { ErrorReport.ReportNonFatalException(fakeException); } else if (title == "Error ReportNonFatalExceptionWithMessage") { ErrorReport.ReportNonFatalExceptionWithMessage(fakeException, fakeProblemMessage); } else if (title == "Error ReportNonFatalExceptionWithMessage Scrollbar") { var longMessageBuilder = new StringBuilder(); while (longMessageBuilder.Length < 500) { longMessageBuilder.AppendLine(fakeProblemMessage); } ErrorReport.ReportNonFatalExceptionWithMessage(fakeException, longMessageBuilder.ToString()); } else if (title == "Error ReportNonFatalMessageWithStackTrace") { ErrorReport.ReportNonFatalMessageWithStackTrace(fakeProblemMessage); } else if (title == "Error ReportFatalException") { ErrorReport.ReportFatalException(fakeException); } else if (title == "Error ReportFatalMessageWithStackTrace") { ErrorReport.ReportFatalMessageWithStackTrace(fakeProblemMessage); } else if (title == "Error ReportFatalMessageWithStackTrace Scrollbar") { var longMessageBuilder = new StringBuilder(); while (longMessageBuilder.Length < 500) { longMessageBuilder.AppendLine(fakeProblemMessage); } ErrorReport.ReportFatalMessageWithStackTrace(longMessageBuilder.ToString()); } }
/// <summary> /// Generates Error Reports for books with specific titles /// Facilitates manual testing of error reporting using specific books. /// </summary> private static void CheckForFakeTestErrors(string title) { const string fakeProblemMessage = "Fake problem for development/testing purposes"; Exception fakeException; // Throwing/catching the exception populates the stack trace try { throw new ApplicationException("Fake exception for development/testing purposes"); } catch (ApplicationException e) { fakeException = e; } if (title == "Error NotifyUser NoReport") { // Exercises a path through libPalaso directly (goes thru overloads 1, 2, 4) ErrorReport.NotifyUserOfProblem(fakeProblemMessage); } else if (title == "Error NotifyUser NoReport 2") { // Exercises a path through libPalaso directly (goes thru overloads 3, 4) ErrorReport.NotifyUserOfProblem((Exception)null, fakeProblemMessage); } else if (title == "Error NotifyUser NoReport 3") { // Exercises a path where you go through the ErrorReportUtils adapters ErrorReportUtils.NotifyUserOfProblem(fakeProblemMessage); } else if (title == "Error NotifyUser LongMessage") { var longMessageBuilder = new StringBuilder(); while (longMessageBuilder.Length < 3000) { longMessageBuilder.Append(fakeProblemMessage + " "); } ErrorReport.NotifyUserOfProblem(longMessageBuilder.ToString()); } else if (title == "Error NotifyUser Report NoRetry") { // Exercises another path through libPalaso directly (goes thru overloads 3, 4) ErrorReport.NotifyUserOfProblem(fakeException, fakeProblemMessage); } else if (title == "Error NotifyUser Report NoRetry 2") { // Exercises a path where you go through the ErrorReportUtils adapters ErrorReportUtils.NotifyUserOfProblem(fakeProblemMessage, fakeException); } else if (title == "Error NotifyUser Report Retry") { // Exercises a path where you need to go through the ErrorReportUtils adapters var secondaryButtonLabel = LocalizationManager.GetString("ErrorReportDialog.Retry", "Retry"); ErrorReportUtils.NotifyUserOfProblem(fakeProblemMessage, fakeException, null, null, secondaryButtonLabel, ErrorReportUtils.TestAction); } else if (title == "Error NotifyUser Custom") { // Exercises a path where you need to go through the ErrorReportUtils adapters var secondaryButtonLabel = LocalizationManager.GetString("ErrorReportDialog.Retry", "Retry"); ErrorReportUtils.NotifyUserOfProblem(fakeProblemMessage, fakeException, "CustomReport", (ex, msg) => { MessageBox.Show("CustomReport button pressed."); }, secondaryButtonLabel, ErrorReportUtils.TestAction); } else if (title == "Error NotifyUser LegacyInterface") { // Exercises the legacy 5-argument implementation in libpalaso // (follow-up actions are manually invoked by the caller) var result = ErrorReport.NotifyUserOfProblem(new ShowAlwaysPolicy(), "CustomReport", ErrorResult.Yes, fakeProblemMessage); string message = result == ErrorResult.Yes ? "Report button clicked. [Legacy]" : null; if (message != null) { MessageBox.Show(message); } } else if (title == "Error ReportNonFatalException") { ErrorReport.ReportNonFatalException(fakeException); } else if (title == "Error ReportNonFatalExceptionWithMessage") { ErrorReport.ReportNonFatalExceptionWithMessage(fakeException, fakeProblemMessage); } else if (title == "Error ReportNonFatalExceptionWithMessage Scrollbar") { var longMessageBuilder = new StringBuilder(); while (longMessageBuilder.Length < 500) { longMessageBuilder.AppendLine(fakeProblemMessage); } ErrorReport.ReportNonFatalExceptionWithMessage(fakeException, longMessageBuilder.ToString()); } else if (title == "Error ReportNonFatalMessageWithStackTrace") { ErrorReport.ReportNonFatalMessageWithStackTrace(fakeProblemMessage); } else if (title == "Error ReportFatalException") { ErrorReport.ReportFatalException(fakeException); } else if (title == "Error ReportFatalMessageWithStackTrace") { ErrorReport.ReportFatalMessageWithStackTrace(fakeProblemMessage); } else if (title == "Error ReportFatalMessageWithStackTrace Scrollbar") { var longMessageBuilder = new StringBuilder(); while (longMessageBuilder.Length < 500) { longMessageBuilder.AppendLine(fakeProblemMessage); } ErrorReport.ReportFatalMessageWithStackTrace(longMessageBuilder.ToString()); } }