public void Log_NoChanges_DoesNotLog() { entry.State = EntityState.Modified; logger.Log(new[] { entry }); logger.DidNotReceiveWithAnyArgs().Log((LoggableEntity)null); }
public void Log_DoesNotSaveLogs() { entry.State = EntityState.Added; DbContext context = Substitute.For <DbContext>(); logger = Substitute.ForPartsOf <AuditLogger>(context); logger.When(sub => sub.Log(Arg.Any <LoggableEntity>())).DoNotCallBase(); logger.Log(new[] { entry }); logger.DidNotReceive().Save(); context.DidNotReceive().SaveChanges(); }
public void Log_Added() { entry.State = EntityState.Added; logger.Log(new[] { entry }); logger.Save(); LoggableEntity expected = new LoggableEntity(entry); AuditLog actual = context.Set <AuditLog>().Single(); Assert.Equal(expected.ToString(), actual.Changes); Assert.Equal(expected.Name, actual.EntityName); Assert.Equal(expected.Action, actual.Action); Assert.Equal(expected.Id(), actual.EntityId); Assert.Equal(1, actual.AccountId); }
public void Log_AddsLogToTheSet(String accountId, String identityName, String expectedAccountId) { HttpContext.Current = HttpContextFactory.CreateHttpContext(); HttpContext.Current.User.Identity.Name.Returns(identityName); LoggableEntity entity = new LoggableEntity(entry); logger = new AuditLogger(context, accountId); logger.Log(entity); AuditLog actual = context.ChangeTracker.Entries <AuditLog>().First().Entity; LoggableEntity expected = entity; Assert.Equal(expectedAccountId, actual.AccountId); Assert.Equal(expected.ToString(), actual.Changes); Assert.Equal(expected.Name, actual.EntityName); Assert.Equal(expected.Action, actual.Action); Assert.Equal(expected.Id, actual.EntityId); }
public void Save_LogsOnce(Int32?expectedAccountId) { LoggableEntity entity = new LoggableEntity(entry); logger = new AuditLogger(context, expectedAccountId); logger.Log(entity); logger.Save(); logger.Save(); AuditLog actual = context.Set <AuditLog>().Single(); LoggableEntity expected = entity; Assert.Equal(expectedAccountId, actual.AccountId); Assert.Equal(expected.ToString(), actual.Changes); Assert.Equal(expected.Name, actual.EntityName); Assert.Equal(expected.Action, actual.Action); Assert.Equal(expected.Id(), actual.EntityId); }
public void Save_LogsOnce(Int32?accountId, String identity, Int32?expectedAccountId) { HttpContext.Current = HttpContextFactory.CreateHttpContext(); HttpContext.Current.User.Identity.Name.Returns(identity); LoggableEntity entity = new LoggableEntity(entry); logger = new AuditLogger(context, accountId); logger.Log(entity); logger.Save(); logger.Save(); AuditLog actual = context.Set <AuditLog>().Single(); LoggableEntity expected = entity; Assert.Equal(expectedAccountId, actual.AccountId); Assert.Equal(expected.ToString(), actual.Changes); Assert.Equal(expected.Name, actual.EntityName); Assert.Equal(expected.Action, actual.Action); Assert.Equal(expected.Id(), actual.EntityId); }
public void OnException(ExceptionContext context) { _logger.Log(new AuditEntry { DateTime = DateTime.Now, LogLevel = LogLevel.Error, Details = context.Exception.ToString() }); _emailNotificator.SendErrorReportToAdmin(new ReportModel { Subject = "System response exception.", Body = context.Exception.ToString() }); context.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", "Home" }, { "action", "Error" } }); context.Result.ExecuteResultAsync(context); }
public void Log_AddsLogToTheSet(String accountId, String identityName, String expectedAccountId) { HttpContext.Current = HttpContextFactory.CreateHttpContext(); HttpContext.Current.User.Identity.Name.Returns(identityName); LoggableEntity entity = new LoggableEntity(entry); logger = new AuditLogger(context, accountId); logger.Log(entity); AuditLog actual = context.ChangeTracker.Entries<AuditLog>().First().Entity; LoggableEntity expected = entity; Assert.Equal(expectedAccountId, actual.AccountId); Assert.Equal(expected.ToString(), actual.Changes); Assert.Equal(expected.Name, actual.EntityName); Assert.Equal(expected.Action, actual.Action); Assert.Equal(expected.Id, actual.EntityId); }