public void Db_ErrorsReportingService_LogExceptionAsync_WithInner() { using (IUnityContainer childContainer = this.container.CreateChildContainer()) { IErrorsReportingService service = childContainer.Resolve <IErrorsReportingService>(); try { ExceptionGenerator.ThrowsTwo(); } catch (Exception exception) { int?id = null; Assert.That(async() => { id = await service.LogExceptionAsync(this.dataSet.ApplicationsIds.ElementAt(0), exception, "ErrorType.Specific"); }, Throws.Nothing); Assert.IsNotNull(id); ErrorReportException ex = this.exceptionsSqlHelper.GetBy(id.Value); ErrorReportException innerEx = this.exceptionsSqlHelper.GetBy(ex.IdInnerException.Value); Assert.AreEqual("Two", ex.Message); Assert.AreEqual("One", innerEx.Message); } } }
public void LogExceptionAsync() { VolatileErrorsReportingDataset store = new VolatileErrorsReportingDataset(); Mock <IErrorsReportingService> mockService = new Mock <IErrorsReportingService>(); mockService.Setup(s => s.LogExceptionAsync(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(Task.FromResult <int?>(1)); IErrorsReportingService service = mockService.Object; try { ExceptionGenerator.ThrowsOne(); } catch (Exception exception) { int?id = null; Assert.That(async() => { id = await service.LogExceptionAsync(store.Applications.First().Id, exception, "ErrorType.Specific"); }, Throws.Nothing); Assert.IsNotNull(id); Assert.AreEqual("One", store.Exceptions.First().Message); } }