public void CustomNotifyUserManual_WhenCloseButtonClicked_ThenOKReturned() { // Simulate click on a button var mockFactory = new Mock <IReactDialogFactory>(); var mockBrowserDialog = new Mock <IBrowserDialog>(); mockBrowserDialog.Setup(x => x.ShowDialog()).Callback(delegate { mockBrowserDialog.Object.CloseSource = null; }); mockFactory.Setup(x => x.CreateReactDialog(It.IsAny <string>(), It.IsAny <object>())) .Returns(mockBrowserDialog.Object); var reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); // CustomNotifyUserManual calls ErrorReport, so we should set it up ErrorReport.SetErrorReporter(reporter); // System Under Test var result = reporter.CustomNotifyUserManual(new ShowAlwaysPolicy(), "Report", ErrorResult.Yes, "Retry", ErrorResult.Retry, "message"); // Verification Assert.AreEqual(ErrorResult.OK, result); }
public void NotifyUserOfProblem_LongMessage() { var messageTextBuilder = new StringBuilder(); for (int i = 0; i < 3000; ++i) { messageTextBuilder.Append('a'); } var messageText = messageTextBuilder.ToString(); var mockFactory = GetDefaultMockReactDialogFactory(); var reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); // System Under Test reporter.NotifyUserOfProblem(new ShowAlwaysPolicy(), null, messageText); // 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("message").GetValue(props) == messageText) )); }
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); } }
public void CustomNotifyUserManual_WhenSecondaryActionButtonClicked_ThenSecondaryActionResultReturned() { // Simulate click on a button var mockFactory = new Mock <IReactDialogFactory>(); var mockBrowserDialog = new Mock <IBrowserDialog>(); mockBrowserDialog.SetupAllProperties(); // This is necessary for properties like CloseSource to set their values. mockBrowserDialog.Setup(x => x.ShowDialog()).Callback(delegate { mockBrowserDialog.Object.CloseSource = "closedByAlternateButton"; }); mockFactory.Setup(x => x.CreateReactDialog(It.IsAny <string>(), It.IsAny <object>())).Returns(mockBrowserDialog.Object); var reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); // CustomNotifyUserManual calls ErrorReport, so we should set it up ErrorReport.SetErrorReporter(reporter); // System Under Test var result = reporter.CustomNotifyUserManual(new ShowAlwaysPolicy(), "Report", ErrorResult.Yes, "Retry", ErrorResult.Retry, "message"); // Verification Assert.AreEqual(ErrorResult.Retry, result); // Cleanup }
public void NotifyUserOfProblem_UnsafeMessage() { var mockFactory = GetDefaultMockReactDialogFactory(); var reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); // System Under Test reporter.NotifyUserOfProblem(new ShowAlwaysPolicy(), null, "<b>Tags should not be encoded</b>"); 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("message").GetValue(props) == "<b>Tags should not be encoded</b>") )); }
public void NotifyUserOfProblem_ExceptionNotProvided_EmptyReportLabel() { var mockFactory = GetDefaultMockReactDialogFactory(); var reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); // System Under Test reporter.NotifyUserOfProblem(new ShowAlwaysPolicy(), null, "message"); 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.IsNullOrEmpty((string)props.GetType().GetProperty("reportLabel").GetValue(props))) )); }
public void SetNotifyUserOfProblemCustomParams_SecondaryActionButtonLabel() { var mockFactory = GetDefaultMockReactDialogFactory(); IBloomErrorReporter reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); // System Under Test reporter.SetNotifyUserOfProblemCustomParams(extraButtonLabel: "Retry"); reporter.NotifyUserOfProblem(new ShowAlwaysPolicy(), null, "message"); // 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("secondaryLabel").GetValue(props) == "Retry") )); }
public void NotifyUserOfProblem_IfParamIsDetailsThenConvertedToReport() { var mockFactory = GetDefaultMockReactDialogFactory(); var reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); // System Under Test reporter.NotifyUserOfProblem(new ShowAlwaysPolicy(), "Details", ErrorResult.Yes, "message"); 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) == "Report") ) ); }
public void NotifyUserOfProblem_ReportButton(string reportLabel) { var mockFactory = GetDefaultMockReactDialogFactory(); IBloomErrorReporter reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); // System Under Test reporter.SetNotifyUserOfProblemCustomParams(reportLabel); reporter.NotifyUserOfProblem(new ShowAlwaysPolicy(), new ApplicationException("fake exception"), "message"); 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) == reportLabel) ) ); }
public void SetNotifyUserOfProblemCustomParams_ReportButtonPresent(string exceptionMessage) { var mockFactory = GetDefaultMockReactDialogFactory(); IBloomErrorReporter reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); var exceptionOrNull = exceptionMessage != null ? new ApplicationException(exceptionMessage) : null; // System Under Test reporter.SetNotifyUserOfProblemCustomParams(reportButtonLabel: "CustomReport"); reporter.NotifyUserOfProblem(new ShowAlwaysPolicy(), exceptionOrNull, "message"); // 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") )); }
public void SetNotifyUserOfProblemCustomParams_SecondaryActionAutoInvoked() { // Simulate click on a button var mockFactory = new Mock <IReactDialogFactory>(); var mockBrowserDialog = new Mock <IBrowserDialog>(); mockBrowserDialog.SetupAllProperties(); // This is necessary for properties like CloseSource to set their values. mockBrowserDialog.Setup(x => x.ShowDialog()).Callback(delegate { mockBrowserDialog.Object.CloseSource = "closedByAlternateButton"; }); mockFactory.Setup(x => x.CreateReactDialog(It.IsAny <string>(), It.IsAny <object>())) .Returns(mockBrowserDialog.Object); var reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); _testValue = ""; Action <Exception, string> action = delegate(Exception e, string s) { _testValue = "Retry was pressed"; }; try { // System Under Test reporter.SetNotifyUserOfProblemCustomParams("", null, "Retry", action); reporter.NotifyUserOfProblem(new ShowAlwaysPolicy(), null, "message"); // Verification Assert.AreEqual("Retry was pressed", _testValue); } finally { // Cleanup _testValue = ""; } }
public void CustomNotifyUserAuto_SecondaryActionButtonLabel() { var mockFactory = GetDefaultMockReactDialogFactory(); var reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); // CustomNotifyUserAuto calls ErrorReport, so we should set it up ErrorReport.SetErrorReporter(reporter); // System Under Test reporter.CustomNotifyUserAuto("", "Retry", null, null, "message"); // 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("secondaryLabel").GetValue(props) == "Retry" && (string)props.GetType().GetProperty("message").GetValue(props) == "message") )); }
public void CustomNotifyUserAuto_IfInstanceVarIsDetailsThenStaysDetails() { var mockFactory = GetDefaultMockReactDialogFactory(); var reporter = new HtmlErrorReporterBuilder() .WithTestValues() .BrowserDialogFactory(mockFactory.Object) .Build(); // CustomNotifyUserAuto calls ErrorReport, so we should set it up ErrorReport.SetErrorReporter(reporter); // System Under Test reporter.CustomNotifyUserAuto("Details", null, null, null, "message"); 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) == "Details" && (string)props.GetType().GetProperty("message").GetValue(props) == "message") ) ); }