public void Db_ErrorsReportingService_LogExceptionAsync() { using (ThreadScopedLifestyle.BeginScope(container)) { ErrorsReportingService service = container.GetInstance <ErrorsReportingService>(); try { ExceptionGenerator.ThrowsOne(); } 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); Assert.AreEqual("One", ex.Message); } } }
public void Db_ErrorsReportingService_LogExceptionAsync() { using (IUnityContainer childContainer = this.container.CreateChildContainer()) { IErrorsReportingService service = childContainer.Resolve <IErrorsReportingService>(); try { ExceptionGenerator.ThrowsOne(); } 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); Assert.AreEqual("One", ex.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); } }
public void LogErrorAsync() { VolatileErrorsReportingDataset store = new VolatileErrorsReportingDataset(); Mock <IErrorsReportingManager> mockManager = new Mock <IErrorsReportingManager>(); mockManager.Setup(m => m.LogErrorAsync(It.IsAny <Exception>(), It.IsAny <AssemblyName>(), It.IsAny <string>())) .Returns(Task.FromResult <object>(null)) .Callback <Exception, AssemblyName, string>((exception, assemblyName, errorCode) => { store.Exceptions.Add(new ErrorReportException { Id = 1, IdApplication = store.Applications.First().Id, 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 = errorCode }); }).Verifiable(); this.errorsReportingManager = mockManager.Object; try { ExceptionGenerator.ThrowsOne(); } catch (Exception exception) { Assert.That(async() => { await this.errorsReportingManager.LogErrorAsync(exception, Assembly.GetExecutingAssembly().GetName(), "ErrorType.Specific"); }, Throws.Nothing); mockManager.Verify(m => m.LogErrorAsync(It.IsAny <Exception>(), It.IsAny <AssemblyName>(), It.IsAny <string>()), Times.Once()); Assert.AreEqual(1, store.Exceptions.Count); } }