示例#1
0
        public void Db_ErrorsReportingService_LogException_WithInner()
        {
            using (IUnityContainer childContainer = this.container.CreateChildContainer())
            {
                IErrorsReportingService service = childContainer.Resolve <IErrorsReportingService>();

                try
                {
                    ExceptionGenerator.ThrowsTwo();
                }
                catch (Exception exception)
                {
                    int?id = null;
                    Assert.That(() =>
                    {
                        id = service.LogException(this.dataSet.ApplicationsIds.ElementAt(0), exception, "ErrorType.Specific");
                    }, Throws.Nothing);

                    Assert.IsNotNull(id);

                    ErrorReportException ex      = this.exceptionsSqlHelper.Get(id.Value);
                    ErrorReportException innerEx = this.exceptionsSqlHelper.Get(ex.IdInnerException.Value);

                    Assert.AreEqual("Two", ex.Message);
                    Assert.AreEqual("One", innerEx.Message);
                }
            }
        }
        public void LogException()
        {
            VolatileDataset store = new VolatileDataset();

            Mock <IErrorsReportingService> mockService = new Mock <IErrorsReportingService>();

            mockService.Setup(s => s.LogException(It.IsIn <int>(store.Applications.Select(a => a.Id)),
                                                  It.IsAny <Exception>(),
                                                  It.IsAny <string>()))
            .Callback <int, Exception, string>((idApplicaton, exception, errorCore) =>
            {
                store.Exceptions.Add(new ErrorReportException
                {
                    Id              = 1,
                    IdApplication   = idApplicaton,
                    Type            = exception.GetType().ToString(),
                    Message         = exception.Message,
                    Source          = exception.Source,
                    SiteModule      = (exception.TargetSite != null && exception.TargetSite.Module != null) ? exception.TargetSite.Module.Name : null,
                    SiteName        = exception.TargetSite.Name,
                    StackTrace      = exception.StackTrace,
                    HelpLink        = exception.HelpLink,
                    Date            = DateTime.Now,
                    CustomErrorType = errorCore,
                });
            })
            .Returns((int?)1);

            IErrorsReportingService service = mockService.Object;

            try
            {
                ExceptionGenerator.ThrowsOne();
            }
            catch (Exception exception)
            {
                int?id = null;
                Assert.That(() =>
                {
                    id = service.LogException(store.Applications.First().Id, exception, "ErrorType.Specific");
                }, Throws.Nothing);

                Assert.IsNotNull(id);

                Assert.AreEqual("One", store.Exceptions.First().Message);
            }
        }