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); }
public void NullOptionsThrowsError() { var client = new MockSlackClient(true); var reporter = new WebHookExceptionReporter(client); reporter.ReportException(new Exception(), null); }
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()); }
public void NullOptionsThrowsError() { var client = new MockSlackClient(true); var filter = new WebHookErrorReportFilter(null, client); filter.OnException(MakeExceptionContext()); }
public void MockClientCallsCallback() { var result = false; var client = new MockSlackClient(x => result = true); client.Post(new SlackMessage()); Assert.IsTrue(result); }
public void MockClientReturnsFalse() { var client = new MockSlackClient(false); var result = client.Post(new SlackMessage()); Assert.IsFalse(result); }
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()); }
public void EmptyWebHookUrlThrowsError() { var client = new MockSlackClient(true); var reporter = new WebHookExceptionReporter(client); reporter.ReportException(new Exception(), new WebHookOptions("")); }
public void ClientReportsTrue() { var client = new MockSlackClient(true); var reporter = new WebHookExceptionReporter(client); Assert.IsTrue(reporter.ReportException(new Exception(), TestHelpers.GetMinimalOptions())); }
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); }
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()); }
public void ReporterErrorIgnored() { var client = new MockSlackClient(x => { throw new MockClientException(); }); var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client); filter.ThrowOnFailure = false; filter.OnException(MakeExceptionContext()); }
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()); }
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()); }
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); }
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); }
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); }
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()); }
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); }
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); }
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()); }
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())); }
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); }
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()); }
public void ReporterErrorThrown() { var client = new MockSlackClient(x => { throw new MockClientException(); }); var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client); filter.ThrowOnFailure = true; filter.OnException(MakeExceptionContext()); }
public void MockClientThrowsException() { var client = new MockSlackClient(x => { throw new MockClientException(); }); client.Post(new SlackMessage()); }
public void MockClientReturnsTrue() { var client = new MockSlackClient(true); var result = client.Post(new SlackMessage()); Assert.IsTrue(result); }
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); }