コード例 #1
0
        public void OptionValuesAreInMessage()
        {
            const string channelName  = "#testChannel";
            const string userName     = "******";
            const string emoji        = "emoji";
            const string text         = "message text";
            const string attColor     = "attachment color";
            const string attTitle     = "attachment title";
            const string attTitleLink = "attachment title link";
            var          client       = new MockSlackClient(x =>
            {
                Assert.AreEqual(channelName, x.Channel);
                Assert.AreEqual(userName, x.Username);
                Assert.AreEqual(emoji, x.IconEmoji);
                Assert.AreEqual(text, x.Text);
                Assert.AreEqual(attColor, x.Attachments[0].Color);
                Assert.AreEqual(attTitle, x.Attachments[0].Title);
                Assert.AreEqual(attTitleLink, x.Attachments[0].TitleLink);
            });
            var reporter = new WebHookExceptionReporter(client);
            var options  = TestHelpers.GetMinimalOptions();

            options.ChannelName         = channelName;
            options.UserName            = userName;
            options.IconEmoji           = emoji;
            options.Text                = text;
            options.AttachmentColor     = attColor;
            options.AttachmentTitle     = attTitle;
            options.AttachmentTitleLink = attTitleLink;
            reporter.ReportException(new Exception(), options);
        }
コード例 #2
0
        public void NullOptionsThrowsError()
        {
            var client   = new MockSlackClient(true);
            var reporter = new WebHookExceptionReporter(client);

            reporter.ReportException(new Exception(), null);
        }
コード例 #3
0
        public void MessageHasAttachment()
        {
            var client   = new MockSlackClient(x => Assert.IsTrue(x.Attachments.Count > 0));
            var reporter = new WebHookExceptionReporter(client);

            reporter.ReportException(new Exception(), TestHelpers.GetMinimalOptions());
        }
コード例 #4
0
        public void NullOptionsThrowsError()
        {
            var client = new MockSlackClient(true);
            var filter = new WebHookErrorReportFilter(null, client);

            filter.OnException(MakeExceptionContext());
        }
コード例 #5
0
 public void MockClientCallsCallback()
 {
     var result = false;
     var client = new MockSlackClient(x => result = true);
     client.Post(new SlackMessage());
     Assert.IsTrue(result);
 }
コード例 #6
0
        public void MockClientReturnsFalse()
        {
            var client = new MockSlackClient(false);
            var result = client.Post(new SlackMessage());

            Assert.IsFalse(result);
        }
コード例 #7
0
 public void AttachmentTextContainsExceptionMessage()
 {
     const string message = "This is a test exception.";
     var client = new MockSlackClient(x => Assert.IsTrue(x.Attachments[0].Text.Contains(message)));
     var reporter = new WebHookExceptionReporter(client);
     reporter.ReportException(new Exception(message), TestHelpers.GetMinimalOptions());
 }
コード例 #8
0
        public void EmptyWebHookUrlThrowsError()
        {
            var client   = new MockSlackClient(true);
            var reporter = new WebHookExceptionReporter(client);

            reporter.ReportException(new Exception(), new WebHookOptions(""));
        }
コード例 #9
0
        public void ClientReportsTrue()
        {
            var client   = new MockSlackClient(true);
            var reporter = new WebHookExceptionReporter(client);

            Assert.IsTrue(reporter.ReportException(new Exception(), TestHelpers.GetMinimalOptions()));
        }
コード例 #10
0
        public void MockClientCallsCallback()
        {
            var result = false;
            var client = new MockSlackClient(x => result = true);

            client.Post(new SlackMessage());
            Assert.IsTrue(result);
        }
コード例 #11
0
 public void ClientReports()
 {
     var isReported = false;
     var client = new MockSlackClient(x => isReported = true);
     var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);
     filter.OnException(MakeExceptionContext());
     Assert.IsTrue(isReported);
 }
コード例 #12
0
        public void OnExceptionReportedIndicatesSuccess()
        {
            var client = new MockSlackClient(true);
            var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);

            filter.OnExceptionReported += args => Assert.IsTrue(args.ReportSucceeded);
            filter.OnException(MakeExceptionContext());
        }
コード例 #13
0
        public void ReporterErrorIgnored()
        {
            var client = new MockSlackClient(x => { throw new MockClientException(); });
            var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);

            filter.ThrowOnFailure = false;
            filter.OnException(MakeExceptionContext());
        }
コード例 #14
0
        public void AttachmentFallbackContainsExceptionMessage()
        {
            const string message  = "This is a test exception.";
            var          client   = new MockSlackClient(x => Assert.IsTrue(x.Attachments[0].Fallback.Contains(message)));
            var          reporter = new WebHookExceptionReporter(client);

            reporter.ReportException(new Exception(message), TestHelpers.GetMinimalOptions());
        }
コード例 #15
0
 public void EventsContainOptions()
 {
     var client = new MockSlackClient(true);
     var options = TestHelpers.GetMinimalOptions();
     var filter = new WebHookErrorReportFilter(options, client);
     filter.OnExceptionReporting += args => Assert.AreSame(options, args.Options);
     filter.OnExceptionReported += args => Assert.AreSame(options, args.Options);
     filter.OnException(MakeExceptionContext());
 }
コード例 #16
0
 public void AttachmentTextIsCustomFormat()
 {
     const string format = "This is the custom format for the attachment.";
     var client = new MockSlackClient(x => Assert.AreEqual(format, x.Attachments[0].Text));
     var reporter = new WebHookExceptionReporter(client);
     var options = TestHelpers.GetMinimalOptions();
     options.ExceptionTextFormat = format;
     reporter.ReportException(new Exception(), options);
 }
コード例 #17
0
        public void WhiteSpaceCustomExceptionFormatIsDefault()
        {
            var client   = new MockSlackClient(x => Assert.IsFalse(string.IsNullOrWhiteSpace(x.Attachments[0].Text)));
            var reporter = new WebHookExceptionReporter(client);
            var options  = TestHelpers.GetMinimalOptions();

            options.ExceptionTextFormat = "   ";
            reporter.ReportException(new Exception(), options);
        }
コード例 #18
0
        public void ClientReports()
        {
            var isReported = false;
            var client     = new MockSlackClient(x => isReported = true);
            var filter     = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);

            filter.OnException(MakeExceptionContext());
            Assert.IsTrue(isReported);
        }
コード例 #19
0
        public void ReportingCanceledByOnExceptionReporting()
        {
            var isReported = false;
            var client     = new MockSlackClient(x => isReported = true);
            var filter     = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);

            filter.OnExceptionReporting += args => args.CancelReport = true;
            filter.OnException(MakeExceptionContext());
            Assert.IsFalse(isReported);
        }
コード例 #20
0
        public void AttachmentTextIsCustomFormat()
        {
            const string format   = "This is the custom format for the attachment.";
            var          client   = new MockSlackClient(x => Assert.AreEqual(format, x.Attachments[0].Text));
            var          reporter = new WebHookExceptionReporter(client);
            var          options  = TestHelpers.GetMinimalOptions();

            options.ExceptionTextFormat = format;
            reporter.ReportException(new Exception(), options);
        }
コード例 #21
0
        public void OnExceptionReportingRaisesOnTime()
        {
            var eventFired = false;
            var client     = new MockSlackClient(x => Assert.IsTrue(eventFired));
            var filter     = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);

            filter.OnExceptionReporting += delegate { eventFired = true; };
            Assert.IsFalse(eventFired);
            filter.OnException(MakeExceptionContext());
        }
コード例 #22
0
        public void EventsContainOptions()
        {
            var client  = new MockSlackClient(true);
            var options = TestHelpers.GetMinimalOptions();
            var filter  = new WebHookErrorReportFilter(options, client);

            filter.OnExceptionReporting += args => Assert.AreSame(options, args.Options);
            filter.OnExceptionReported  += args => Assert.AreSame(options, args.Options);
            filter.OnException(MakeExceptionContext());
        }
コード例 #23
0
 public void EventsContainException()
 {
     var client = new MockSlackClient(true);
     var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);
     var exception = new Exception("test exception");
     filter.OnExceptionReporting += args => Assert.AreSame(exception, args.Exception);
     filter.OnExceptionReported += args => Assert.AreSame(exception, args.Exception);
     var context = MakeExceptionContext();
     context.Exception = exception;
     filter.OnException(context);
 }
コード例 #24
0
        public void DontIgnoreExceptionType()
        {
            var isReported = false;
            var client = new MockSlackClient(x => isReported = true);
            var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);
            filter.IgnoreExceptionTypes = new[] { typeof(NullReferenceException), typeof(ArgumentException) };
            var context = MakeExceptionContext();

            context.Exception = new Exception();
            filter.OnException(context);
            Assert.IsTrue(isReported);
        }
コード例 #25
0
        public void DontIgnoreExceptionType()
        {
            var isReported = false;
            var client     = new MockSlackClient(x => isReported = true);
            var filter     = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);

            filter.IgnoreExceptionTypes = new[] { typeof(NullReferenceException), typeof(ArgumentException) };
            var context = MakeExceptionContext();

            context.Exception = new Exception();
            filter.OnException(context);
            Assert.IsTrue(isReported);
        }
コード例 #26
0
        public void PostEventContainsReporterError()
        {
            var reporterException = new MockClientException();
            var client            = new MockSlackClient(x => { throw reporterException; });
            var filter            = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);

            filter.OnExceptionReported += delegate(ExceptionReportedEventArgs args)
            {
                Assert.AreSame(reporterException, args.ReportException);
                Assert.IsFalse(args.ReportSucceeded);
            };
            filter.OnException(MakeExceptionContext());
        }
コード例 #27
0
        public void EventsContainException()
        {
            var client    = new MockSlackClient(true);
            var filter    = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);
            var exception = new Exception("test exception");

            filter.OnExceptionReporting += args => Assert.AreSame(exception, args.Exception);
            filter.OnExceptionReported  += args => Assert.AreSame(exception, args.Exception);
            var context = MakeExceptionContext();

            context.Exception = exception;
            filter.OnException(context);
        }
コード例 #28
0
 public void MessageDefaultsAreCorrect()
 {
     var client = new MockSlackClient(x =>
     {
         Assert.IsNull(x.Channel);
         Assert.IsNull(x.Username);
         Assert.AreEqual(WebHookExceptionReporter.DEFAULT_TEXT, x.Text);
         Assert.AreEqual(WebHookExceptionReporter.DEFAULT_COLOR, x.Attachments[0].Color);
         Assert.AreEqual(Webhooks.Emoji.HeavyExclamationMark, x.IconEmoji);
         Assert.AreEqual("text", x.Attachments[0].MrkdwnIn.First());
     });
     var reporter = new WebHookExceptionReporter(client);
     Assert.IsTrue(reporter.ReportException(new Exception(), TestHelpers.GetMinimalOptions()));
 }
コード例 #29
0
        public void NoReportIfExceptionHandledWhenIgnoring()
        {
            var isReported = false;
            var client     = new MockSlackClient(x => isReported = true);
            var filter     = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client)
            {
                IgnoreHandled = true
            };
            var context = MakeExceptionContext();

            context.ExceptionHandled = true;
            filter.OnException(context);
            Assert.IsFalse(isReported);
        }
コード例 #30
0
        public void MessageDefaultsAreCorrect()
        {
            var client = new MockSlackClient(x =>
            {
                Assert.IsNull(x.Channel);
                Assert.IsNull(x.Username);
                Assert.AreEqual(WebHookExceptionReporter.DEFAULT_TEXT, x.Text);
                Assert.AreEqual(WebHookExceptionReporter.DEFAULT_COLOR, x.Attachments[0].Color);
                Assert.AreEqual(Webhooks.Emoji.HeavyExclamationMark, x.IconEmoji);
                Assert.AreEqual("text", x.Attachments[0].MrkdwnIn.First());
            });
            var reporter = new WebHookExceptionReporter(client);

            Assert.IsTrue(reporter.ReportException(new Exception(), TestHelpers.GetMinimalOptions()));
        }
コード例 #31
0
        public void OnExceptionReportingOverridesOptions()
        {
            var originalOptions = TestHelpers.GetMinimalOptions();
            var newOptions      = TestHelpers.GetMinimalOptions();

            Assert.AreNotSame(originalOptions, newOptions);
            var client = new MockSlackClient(true);
            var filter = new WebHookErrorReportFilter(originalOptions, client);

            filter.OnExceptionReporting += args => args.Options = newOptions;
            filter.OnExceptionReported  += args =>
            {
                Assert.AreSame(newOptions, args.Options);
                Assert.AreNotSame(originalOptions, args.Options);
            };
            filter.OnException(MakeExceptionContext());
        }
コード例 #32
0
 public void ClientReportsTrue()
 {
     var client = new MockSlackClient(true);
     var reporter = new WebHookExceptionReporter(client);
     Assert.IsTrue(reporter.ReportException(new Exception(), TestHelpers.GetMinimalOptions()));
 }
コード例 #33
0
 public void ReportingCanceledByOnExceptionReporting()
 {
     var isReported = false;
     var client = new MockSlackClient(x => isReported = true);
     var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);
     filter.OnExceptionReporting += args => args.CancelReport = true;
     filter.OnException(MakeExceptionContext());
     Assert.IsFalse(isReported);
 }
コード例 #34
0
 public void ReporterErrorThrown()
 {
     var client = new MockSlackClient(x => { throw new MockClientException(); });
     var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);
     filter.ThrowOnFailure = true;
     filter.OnException(MakeExceptionContext());
 }
コード例 #35
0
 public void PostEventContainsReporterError()
 {
     var reporterException = new MockClientException();
     var client = new MockSlackClient(x => { throw reporterException; });
     var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);
     filter.OnExceptionReported += delegate(ExceptionReportedEventArgs args)
     {
         Assert.AreSame(reporterException, args.ReportException);
         Assert.IsFalse(args.ReportSucceeded);
     };
     filter.OnException(MakeExceptionContext());
 }
コード例 #36
0
 public void OnExceptionReportingRaisesOnTime()
 {
     var eventFired = false;
     var client = new MockSlackClient(x => Assert.IsTrue(eventFired));
     var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);
     filter.OnExceptionReporting += delegate { eventFired = true; };
     Assert.IsFalse(eventFired);
     filter.OnException(MakeExceptionContext());
 }
コード例 #37
0
 public void OnExceptionReportingOverridesOptions()
 {
     var originalOptions = TestHelpers.GetMinimalOptions();
     var newOptions = TestHelpers.GetMinimalOptions();
     Assert.AreNotSame(originalOptions, newOptions);
     var client = new MockSlackClient(true);
     var filter = new WebHookErrorReportFilter(originalOptions, client);
     filter.OnExceptionReporting += args => args.Options = newOptions;
     filter.OnExceptionReported += args =>
     {
         Assert.AreSame(newOptions, args.Options);
         Assert.AreNotSame(originalOptions, args.Options);
     };
     filter.OnException(MakeExceptionContext());
 }
コード例 #38
0
 public void OnExceptionReportedIndicatesSuccess()
 {
     var client = new MockSlackClient(true);
     var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client);
     filter.OnExceptionReported += args => Assert.IsTrue(args.ReportSucceeded);
     filter.OnException(MakeExceptionContext());
 }
コード例 #39
0
 public void NullOptionsThrowsError()
 {
     var client = new MockSlackClient(true);
     var filter = new WebHookErrorReportFilter(null, client);
     filter.OnException(MakeExceptionContext());
 }
コード例 #40
0
        public void MockClientThrowsException()
        {
            var client = new MockSlackClient(x => { throw new MockClientException(); });

            client.Post(new SlackMessage());
        }
コード例 #41
0
        public void OptionValuesAreInMessage()
        {
            const string channelName = "#testChannel";
            const string userName = "******";
            const string emoji = "emoji";
            const string text = "message text";
            const string attColor = "attachment color";
            const string attTitle = "attachment title";
            const string attTitleLink = "attachment title link";
            var client = new MockSlackClient(x =>
            {
                Assert.AreEqual(channelName, x.Channel);
                Assert.AreEqual(userName, x.Username);
                Assert.AreEqual(emoji, x.IconEmoji);
                Assert.AreEqual(text, x.Text);
                Assert.AreEqual(attColor, x.Attachments[0].Color);
                Assert.AreEqual(attTitle, x.Attachments[0].Title);
                Assert.AreEqual(attTitleLink, x.Attachments[0].TitleLink);

            });
            var reporter = new WebHookExceptionReporter(client);
            var options = TestHelpers.GetMinimalOptions();
            options.ChannelName = channelName;
            options.UserName = userName;
            options.IconEmoji = emoji;
            options.Text = text;
            options.AttachmentColor = attColor;
            options.AttachmentTitle = attTitle;
            options.AttachmentTitleLink = attTitleLink;
            reporter.ReportException(new Exception(), options);
        }
コード例 #42
0
 public void MessageHasAttachment()
 {
     var client = new MockSlackClient(x => Assert.IsTrue(x.Attachments.Count > 0));
     var reporter = new WebHookExceptionReporter(client);
     reporter.ReportException(new Exception(), TestHelpers.GetMinimalOptions());
 }
コード例 #43
0
 public void MockClientReturnsTrue()
 {
     var client = new MockSlackClient(true);
     var result = client.Post(new SlackMessage());
     Assert.IsTrue(result);
 }
コード例 #44
0
 public void NullCustomExceptionFormatIsDefault()
 {
     var client = new MockSlackClient(x => Assert.IsFalse(string.IsNullOrWhiteSpace(x.Attachments[0].Text)));
     var reporter = new WebHookExceptionReporter(client);
     var options = TestHelpers.GetMinimalOptions();
     options.ExceptionTextFormat = null;
     reporter.ReportException(new Exception(), options);
 }
コード例 #45
0
 public void EmptyWebHookUrlThrowsError()
 {
     var client = new MockSlackClient(true);
     var reporter = new WebHookExceptionReporter(client);
     reporter.ReportException(new Exception(), new WebHookOptions(""));
 }
コード例 #46
0
 public void MockClientThrowsException()
 {
     var client = new MockSlackClient(x => { throw new MockClientException(); });
     client.Post(new SlackMessage());
 }
コード例 #47
0
 public void NoReportIfExceptionHandledWhenIgnoring()
 {
     var isReported = false;
     var client = new MockSlackClient(x => isReported = true);
     var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client) { IgnoreHandled = true };
     var context = MakeExceptionContext();
     context.ExceptionHandled = true;
     filter.OnException(context);
     Assert.IsFalse(isReported);
 }
コード例 #48
0
 public void NullOptionsThrowsError()
 {
     var client = new MockSlackClient(true);
     var reporter = new WebHookExceptionReporter(client);
     reporter.ReportException(new Exception(), null);
 }