Inheritance: IAuditLogger
        public void AuditLogger_AccountId_DisablesChangesDetection()
        {
            TestingContext context = new TestingContext();
            context.Configuration.AutoDetectChangesEnabled = true;

            using (AuditLogger logger = new AuditLogger(context, "Test"))
                Assert.False(context.Configuration.AutoDetectChangesEnabled);
        }
        public AuditLoggerTests()
        {
            context = new TestingContext();
            logger = new AuditLogger(context, 1);
            Role model = ObjectFactory.CreateRole();
            TestingContext dataContext = new TestingContext();

            entry = dataContext.Entry<BaseModel>(dataContext.Set<Role>().Add(model));
            dataContext.Set<AuditLog>().RemoveRange(dataContext.Set<AuditLog>());
            dataContext.DropData();
        }
Esempio n. 3
0
        public AuditLoggerTests()
        {
            context = new TestingContext();
            dataContext = new TestingContext();
            TestModel model = ObjectFactory.CreateTestModel();
            logger = Substitute.ForPartsOf<AuditLogger>(context);

            entry = dataContext.Entry<BaseModel>(dataContext.Set<TestModel>().Add(model));
            dataContext.Set<TestModel>().RemoveRange(dataContext.Set<TestModel>());
            dataContext.SaveChanges();
        }
        public void Dispose_Context()
        {
            TestingContext context = Substitute.For<TestingContext>();
            AuditLogger logger = new AuditLogger(context);

            logger.Dispose();

            context.Received().Dispose();
        }
        public void Save_LogsOnce(Int32? accountId, String identityName, Int32? 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);
            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);
        }
Esempio n. 6
0
        public void Save_Logs()
        {
            TestingContext context = Substitute.For<TestingContext>();
            logger = Substitute.ForPartsOf<AuditLogger>(context);

            logger.Save();

            context.Received().SaveChanges();
        }
Esempio n. 7
0
        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 Dispose_DisposesContext()
        {
            DbContext context = Substitute.For<DbContext>();
            logger = Substitute.ForPartsOf<AuditLogger>(context);

            logger.Dispose();

            context.Received().Dispose();
        }