Ejemplo n.º 1
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)
                                   ));
        }
Ejemplo n.º 2
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)))
                                   ));
        }
Ejemplo n.º 3
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>")
                                   ));
        }
Ejemplo n.º 4
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")
                                   ));
        }
Ejemplo n.º 5
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")
                                   )
                               );
        }
Ejemplo n.º 6
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)
                                   )
                               );
        }
Ejemplo n.º 7
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")
                                   ));
        }
Ejemplo n.º 8
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 = "";
            }
        }