Beispiel #1
0
        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);
        }
Beispiel #2
0
        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)
                                   ));
        }
Beispiel #3
0
        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);
            }
        }
Beispiel #4
0
        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
        }
Beispiel #5
0
        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>")
                                   ));
        }
Beispiel #6
0
        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)))
                                   ));
        }
Beispiel #7
0
        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")
                                   ));
        }
Beispiel #8
0
        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")
                                   )
                               );
        }
Beispiel #9
0
        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)
                                   )
                               );
        }
Beispiel #10
0
        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")
                                   ));
        }
Beispiel #11
0
        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 = "";
            }
        }
Beispiel #12
0
        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")
                                   ));
        }
Beispiel #13
0
        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")
                                   )
                               );
        }