Пример #1
0
        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);
        }
Пример #2
0
        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();
        }
Пример #4
0
        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);
        }
Пример #5
0
        public void Save_Logs()
        {
            TestingContext context = Substitute.For<TestingContext>();
            logger = Substitute.ForPartsOf<AuditLogger>(context);

            logger.Save();

            context.Received().SaveChanges();
        }