Пример #1
0
        public ErrorReportDTO ReportUnique(string message, Action <ErrorReportDTO> customizations = null)
        {
            var ex     = CreateException(message);
            var report = _processor.Build(ex);

            customizations?.Invoke(report);

            SetUniqueStackTrace(report);

            _config.Uploaders.Upload(report);
            return(report);
        }
Пример #2
0
        public void should_add_the_exception_to_the_report_so_that_it_can_be_uploaded()
        {
            var dispatcher = Substitute.For <IUploadDispatcher>();
            var config     = new CoderrConfiguration(dispatcher);
            var ex         = new Exception("hello");

            var sut     = new ExceptionProcessor(config);
            var actual1 = sut.Build(ex);
            var actual2 = sut.Build(ex, "Hello world");
            var actual3 = sut.Build(new ErrorReporterContext(this, ex));

            actual1.Exception.Message.Should().Be(ex.Message);
            actual2.Exception.Message.Should().Be(ex.Message);
            actual3.Exception.Message.Should().Be(ex.Message);
        }
Пример #3
0
        public void should_use_the_assigned_reportId_factory_to_assign_a_report_id()
        {
            var dispatcher   = Substitute.For <IUploadDispatcher>();
            var config       = new CoderrConfiguration(dispatcher);
            var ex           = new Exception();
            var timesInvoked = 0;

            ReportIdGenerator.Assign(x => { timesInvoked++; return("a"); });

            var sut = new ExceptionProcessor(config);

            sut.Build(ex);
            sut.Build(ex, "Hello world");
            sut.Build(new ErrorReporterContext(this, ex));

            timesInvoked.Should().Be(3);
        }
Пример #4
0
        public void should_add_context_data_object_to_report()
        {
            var dispatcher = Substitute.For <IUploadDispatcher>();
            var config     = new CoderrConfiguration(dispatcher);
            var ex         = new Exception("hello");

            var sut    = new ExceptionProcessor(config);
            var actual = sut.Build(ex, "Hello world");

            actual.GetCollectionProperty("ContextData", "Value").Should().Be("Hello world");
        }
Пример #5
0
        public void should_add_custom_collection_to_report()
        {
            var dispatcher = Substitute.For <IUploadDispatcher>();
            var config     = new CoderrConfiguration(dispatcher);
            var ex         = new Exception("hello");
            var collection = "Hello you too".ToContextCollection("MyName");

            var sut    = new ExceptionProcessor(config);
            var actual = sut.Build(ex, collection);

            actual.GetCollectionProperty("MyName", "Value").Should().Be("Hello you too");
        }
Пример #6
0
        public void Should_be_able_to_build_a_report()
        {
            var upl    = new TestUploader();
            var config = new CoderrConfiguration();
            var filter = Substitute.For <IReportFilter>();

            config.Uploaders.Register(upl);
            config.FilterCollection.Add(filter);

            var processor = new ExceptionProcessor(config);
            var report    = processor.Build(new Exception());

            report.Should().NotBeNull();
        }
Пример #7
0
        public void should_add_log_entries_from_context()
        {
            var dispatcher = Substitute.For <IUploadDispatcher>();
            var config     = new CoderrConfiguration(dispatcher);
            var ex         = new Exception("hello");
            var context    = new ErrorReporterContext(this, ex)
            {
                LogEntries = new LogEntryDto[] { new LogEntryDto(DateTime.UtcNow, 1, "Hello") }
            };

            var sut    = new ExceptionProcessor(config);
            var actual = sut.Build(context);

            actual.LogEntries[0].Message.Should().Be(context.LogEntries[0].Message);
        }
Пример #8
0
        public void Should_not_filter_BuildReport_as_nothing_is_sent_by_that_method()
        {
            var upl    = new TestUploader();
            var config = new CoderrConfiguration();
            var filter = Substitute.For <IReportFilter>();

            config.Uploaders.Register(upl);
            config.FilterCollection.Add(filter);
            filter.Invoke(Arg.Do((ReportFilterContext context) => context.CanSubmitReport = false));

            var processor = new ExceptionProcessor(config);
            var report    = processor.Build(new Exception());

            report.Should().NotBeNull();
        }
Пример #9
0
        public void BuildReport_should_ignore_reports_that_have_already_been_reported_since_same_frameworks_have_multiple_injection_points_which_would_Report_the_same_exception()
        {
            var upl    = new TestUploader();
            var config = new CoderrConfiguration();

            config.Uploaders.Register(upl);
            var ex = new Exception("hello");

            ex.Data[ExceptionProcessor.AlreadyReportedSetting] = 1;

            var processor = new ExceptionProcessor(config);

            processor.Build(ex);

            upl.Report.Should().BeNull("because report should have been ignored");
        }
Пример #10
0
 /// <summary>
 ///     Will generate a report without uploading it.
 /// </summary>
 /// <param name="exception">Exception that you want to get reported</param>
 /// <returns>Unique identifier for this report (generated using <see cref="ReportIdGenerator" />)</returns>
 /// <exception cref="System.ArgumentNullException">exception</exception>
 /// <remarks>
 ///     <para>
 ///         A lot if context information is also included in the error report. You can configure the attached information
 ///         by
 ///         using <c>Err.Configuration.ContextProviders.Add()</c>
 ///     </para>
 ///     <para>
 ///         All library exceptions are directed to the <c>Err.ReportingFailed</c> event.
 ///         Subscribe on that event if you have trouble with reporting exceptions.
 ///     </para>
 /// </remarks>
 /// <example>
 ///     <code>
 /// public ActionResult Activate(UserViewModel model)
 /// {
 ///     if (!ModelState.IsValid)
 ///         return View(model);
 ///
 ///     try
 ///     {
 ///         var user = _repos.GetUser(model.Id);
 ///         user.Activate(model.ActivationCode);
 ///         _repos.Save(user);
 ///         return RedirectToAction("Welcome");
 ///     }
 ///     catch (Exception exception)
 ///     {
 ///         Err.Report(exception);
 ///     }
 /// }
 /// </code>
 /// </example>
 /// <seealso cref="UploadReport" />
 public static ErrorReportDTO GenerateReport(Exception exception)
 {
     return(_exceptionProcessor.Build(exception));
 }