public void IntegratationTestWithErrorReportUtils() { var mockFactory = GetDefaultMockReactDialogFactory(); var reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); Bloom.Program.ErrorReporter = reporter; try { // System Under Test ErrorReportUtils.NotifyUserOfProblem("message", new ApplicationException("fake exception"), "CustomReport", null, "Retry", ErrorReportUtils.TestAction); // Verification mockFactory.Verify(x => x.CreateReactDialog( It.Is <string>(b => b == "problemReportBundle"), It.Is <object>(props => (string)props.GetType().GetProperty("level").GetValue(props) == ProblemLevel.kNotify && (string)props.GetType().GetProperty("reportLabel").GetValue(props) == "CustomReport" && (string)props.GetType().GetProperty("secondaryLabel").GetValue(props) == "Retry" && (string)props.GetType().GetProperty("message").GetValue(props) == "message") )); } finally { ErrorReport.SetErrorReporter(null); } }
/// <summary> /// Sends a problem report directly (without bringing up the UI dialog). /// This may be useful when the user has selected "Report" after receiving a Notify, especially if we can't bring up the HTML-based UI. /// </summary> /// <param name="levelOfProblem">One of the values of ProblemLevel. e.g. fatal, nonfatal, user, notify</param> /// <param name="exception">Optional - the exception to report. </param> /// <param name="shortUserLevelMessage">Optional. Short Description. If provided, must be the raw, literal, unencoded text... No using HTML to apply formatting</param> /// <param name="detailedMessage">Optional. Additional Description.</param> /// <param name="additionalPathsToInclude">Optional. If provided, the paths in this IEnumerable will be attached to the issue</param> public void SendReportWithoutUI(string levelOfProblem, Exception exception, string shortUserLevelMessage, string detailedMessage, IEnumerable <string> additionalPathsToInclude) { // Before we do anything that might be "risky", put the problem in the log. LogProblem(exception, detailedMessage, levelOfProblem); // Acquire the lock (even though we're not technically SHOWING a problem report dialog) // so that there's no interference with the member variables lock (_showingProblemReportLock) { if (_showingProblemReport) { // Prevent multiple calls, in case of unbounded recursion const string msg = "MULTIPLE CALLS to ShowProblemDialog. Suppressing the subsequent calls"; Console.Write(msg); Logger.WriteEvent(msg); return; // Abort } _showingProblemReport = true; } string issueLink; try { GatherReportInfoExceptScreenshot(exception, detailedMessage, shortUserLevelMessage, false); // NOTE: Taking screenshots not supported in this mode (yet) // NOTE: kFailureResult may be returned (if submitting the issue failed). issueLink = SubmitToYouTrack(levelOfProblem, "", SIL.Windows.Forms.Registration.Registration.Default.Email, false, false, additionalPathsToInclude); } catch (Exception) { issueLink = kFailureResult; } finally { _showingProblemReport = false; } string message = issueLink.StartsWith(kFailureResult) ? "Failed to report issue. Please email Bloom team manually." : "Successfully reported issue: " + issueLink; // NOTE: This call should ideally be invoked after _showingProblemReport is back to false, // so that the resources will be available to this call. ErrorReportUtils.NotifyUserOfProblem(message); }