Esempio n. 1
0
        public static ErrorReport FromException(Exception exc)
        {
            if (exc == null)
            {
                return null;
            }

            var errorReport = new ErrorReport
                                    {
                                        Message = exc.Message,
            #if !(SILVERLIGHT || WinRT)
                                        Source = exc.Source,
            #endif
                                        StackTrace = exc.StackTrace,
                                        AdditionalData = GetAdditionalData(exc)
                                    };

            // Populate additional data from providers
            foreach (var errorDataProvider in GlobalConfig.ErrorDataProviders)
            {
                foreach (var keyValuePair in errorDataProvider.GetData())
                {
                    errorReport.AdditionalData.Add(keyValuePair);
                }
            }

            return errorReport;
        }
        public void TryStore_Always_CallsReportRequestBuilderBuildWithReport()
        {
            var errorReport = new ErrorReport();

            new SequentialResult(_subject.Save(errorReport)).Execute(new ExecutionContext());

            _mockReportRequestBuilder.Verify(m => m.BuildAsync(errorReport));
        }
        public void TryStore_WhenNoException_ReturnsTrue()
        {
            var errorReport = new ErrorReport();
            var mockRequest = new Mock<WebRequest>();
            _mockReportRequestBuilder.Setup(m => m.BuildAsync(errorReport))
                .Raises(m => m.BuildCompleted += null, new ReportRequestBuildCompletedEventArgs { Result = mockRequest.Object });
            ErrorReportSaveCompletedEventArgs eventArgs = null;
            _subject.SaveCompleted += (o, e) => { eventArgs = e; };

            _subject.Save(errorReport).ToList();

            Assert.IsTrue(eventArgs.Success);
        }
        public void Serialize_WhenPropertyIsNull_SetsEmpty()
        {
            var errorReport = new ErrorReport
                                  {
                                      Message = null,
                                      Source = null,
                                      StackTrace = null
                                  };

            var result = _subject.Serialize(errorReport);

            Assert.AreEqual("message=&source=&stackTrace=", result);
        }
        public void Serialize_Always_FormatsStringProperties()
        {
            var errorReport = new ErrorReport
                                  {
                                      Message = "test message",
                                      Source = "source",
                                      StackTrace = "stack trace"
                                  };

            var result = _subject.Serialize(errorReport);

            Assert.AreEqual("message=test%20message&source=source&stackTrace=stack%20trace", result);
        }
        public void Serialize_Always_AddsDataFromAdditionalData()
        {
            var errorReport = new ErrorReport
                                  {
                                      Message = "test message",
                                      Source = "source",
                                      StackTrace = "stack trace"
                                  };
            errorReport.AdditionalData.Add(new KeyValuePair<string, string>("OS", "WinXp"));
            errorReport.AdditionalData.Add(new KeyValuePair<string, string>("NET_VERSION", "3.5"));

            var result = _subject.Serialize(errorReport);

            Assert.AreEqual("message=test%20message&source=source&stackTrace=stack%20trace&additionalData[OS]=WinXp&additionalData[NET_VERSION]=3.5", result);
        }