public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters.Add(new HandleErrorAttribute()); var slackReport = new WebHookErrorReportFilter( new WebHookOptions(ConfigurationManager.AppSettings["slack:webhookurl"]) { ChannelName = ConfigurationManager.AppSettings["slack:channel"], //UserName = ConfigurationManager.AppSettings["slack:username"], //IconEmoji = ConfigurationManager.AppSettings["slack:iconEmoji"], //AttachmentColor = ConfigurationManager.AppSettings["slack:color"], //AttachmentTitle = ConfigurationManager.AppSettings["slack:title"], //AttachmentTitleLink = ConfigurationManager.AppSettings["slack:link"], //Text = ConfigurationManager.AppSettings["slack:text"], //ExceptionTextFormat = ConfigurationManager.AppSettings["slack:exceptionTextFormat"], } ) { IgnoreHandled = true, IgnoreExceptionTypes = new[] { typeof(System.ApplicationException) }, }; filters.Add(slackReport, 1); //var slackReportEvented = new WebHookErrorReportFilter(); //slackReportEvented.OnExceptionReporting += slackReportEvented_OnExceptionReporting; //filters.Add(slackReportEvented); }
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 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 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 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 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 ReporterErrorThrown() { var client = new MockSlackClient(x => { throw new MockClientException(); }); var filter = new WebHookErrorReportFilter(TestHelpers.GetMinimalOptions(), client); filter.ThrowOnFailure = true; filter.OnException(MakeExceptionContext()); }
public void CanCreate() { var filter = new WebHookErrorReportFilter(); }
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 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 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 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 NullOptionsThrowsError() { var client = new MockSlackClient(true); var filter = new WebHookErrorReportFilter(null, client); filter.OnException(MakeExceptionContext()); }