public void Map_DomainToTransfer_Test() { //Arrange IDiagnosticsMapper mapper = new DiagnosticsMapper(); var domainDiagnostics = new Diagnostics { DiagnosticsId = 1, Date = new DateTime(2015, 1, 1), EntityState = EntityState.Unchanged, ExceptionName = "NewException", Message = "Error", UserId = 1 }; var expectedTransferDiagnostics = new TransferDiagnosticsLikeness { DiagnosticsId = 1, Date = new DateTime(2015, 1, 1), EntityState = EntityState.Unchanged, ExceptionName = "NewException", Message = "Error", UserId = 1 }; //Act var actualTransferDiagnostics = mapper.Map(domainDiagnostics); //Assert Assert.That(actualTransferDiagnostics, Is.EqualTo(expectedTransferDiagnostics)); }
public TransferDiagnostics Map(Diagnostics diagnostics) { if (diagnostics == null) { return null; } return new TransferDiagnostics { DiagnosticsId = diagnostics.DiagnosticsId, UserId = diagnostics.UserId, ExceptionName = diagnostics.ExceptionName, Message = diagnostics.Message, Date = diagnostics.Date, EntityState = EntityState.Unchanged }; }
public async Task SaveDiagnosticAsync(Diagnostics diagnostic) { if (diagnostic == null) { throw new ArgumentNullException("diagnostic"); } using (var context = _diagnosticsDbContextFactory.Create()) { context.Diagnostics.Add(new Diagnostics { UserId = diagnostic.UserId, ExceptionName = diagnostic.ExceptionName, Message = diagnostic.Message, Date = diagnostic.Date, EntityState = EntityState.Added }); await context.SaveChangesAsync(); } }
public void LogError(Exception exception, HttpContext context) { if (context == null) { throw new ArgumentNullException("context"); } if (exception == null) { throw new ArgumentNullException("exception"); } var identity = (FormsIdentity)context.User.Identity; var userId = _cookieParser.GetUserId(identity); Diagnostics diagnostic = new Diagnostics { UserId = userId, ExceptionName = exception.GetType().ToString(), Message = exception.Message, Date = DateTime.Now, EntityState = EntityState.Added }; _diagnosticsService.SaveDiagnosticAsync(diagnostic); }