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 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_Logs() { TestingContext context = Substitute.For <TestingContext>(); logger = Substitute.ForPartsOf <AuditLogger>(context); logger.Save(); context.Received().SaveChanges(); }
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 Save_Logs() { TestingContext context = Substitute.For<TestingContext>(); logger = Substitute.ForPartsOf<AuditLogger>(context); logger.Save(); context.Received().SaveChanges(); }