public virtual void Log(LoggableEntity entity) { AuditLog log = new AuditLog(); log.AccountId = AccountId ?? HttpContext.Current.User.Identity.Name; log.AccountId = !String.IsNullOrEmpty(log.AccountId) ? log.AccountId : null; log.Changes = entity.ToString(); log.EntityName = entity.Name; log.Action = entity.Action; log.EntityId = entity.Id; Context.Set<AuditLog>().Add(log); }
public virtual void Log(LoggableEntity entity) { AuditLog log = new AuditLog(); log.AccountId = AccountId ?? HttpContext.Current.User.Identity.Name; log.AccountId = !String.IsNullOrEmpty(log.AccountId) ? log.AccountId : null; log.Changes = entity.ToString(); log.EntityName = entity.Name; log.Action = entity.Action; log.EntityId = entity.Id; Context.Set <AuditLog>().Add(log); }
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); }
private void Logs(DbEntityEntry<BaseModel> entry) { LoggableEntity expected = new LoggableEntity(entry); logger.When(sub => sub.Log(Arg.Any<LoggableEntity>())).DoNotCallBase(); logger.When(sub => sub.Log(Arg.Any<LoggableEntity>())).Do(info => { LoggableEntity actual = info.Arg<LoggableEntity>(); Assert.Equal(expected.ToString(), actual.ToString()); Assert.Equal(expected.Action, actual.Action); Assert.Equal(expected.Name, actual.Name); Assert.Equal(expected.Id, actual.Id); }); logger.Log(new[] { entry }); logger.ReceivedWithAnyArgs().Log(expected); }
public virtual void Log(LoggableEntity entity) { context.Set <AuditLog>().Add(new AuditLog(entity.Action, entity.Name, entity.Id, entity.ToString())); }
public void ToString_FormsEntityChanges() { StringBuilder changes = new StringBuilder(); LoggableEntity loggableEntity = new LoggableEntity(entry); foreach (LoggableProperty property in loggableEntity.Properties) changes.AppendFormat("{0}{1}", property, Environment.NewLine); String actual = loggableEntity.ToString(); String expected = changes.ToString(); Assert.Equal(expected, actual); }