public static async Task SaveAsync(Exception exception, AssemblyName assemblyName, string errorCode) { using (ThreadScopedLifestyle.BeginScope(IoCConfiguration.Container)) { IErrorsReportingManager manager = IoCConfiguration.Container.GetInstance <IErrorsReportingManager>(); await manager.LogErrorAsync(exception, assemblyName, errorCode); } }
public static void Save(Exception exception, AssemblyName assemblyName, string errorCode) { using (IUnityContainer unit = IoCConfiguration.container.CreateChildContainer()) { IErrorsReportingManager manager = unit.Resolve <IErrorsReportingManager>(); manager.LogError(exception, assemblyName, errorCode); } }
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); } }