Ejemplo n.º 1
0
        public void tracks_context()
        {
            //setup
            var context = CreateUserContext();

            //act
            var subject = new TrackingAuditEvent(context);

            //assert
            Assert.AreEqual(context.ClientIP, subject.ClientIP);
            Assert.AreEqual(context.SessionIdentifier, subject.SessionIdentifier);
            Assert.AreEqual(context.SiteCollectionIdentifier, subject.SiteCollectionIdentifier);
            Assert.AreEqual(context.SiteIdentifier, subject.SiteIdentifier);
            Assert.AreEqual(context.Uri.ToString(), subject.Url);
            Assert.AreEqual(context.UserName, subject.UserName);
        }
Ejemplo n.º 2
0
        public void tracks_delete()
        {
            //setup
            var subject = new TrackingAuditEvent(CreateUserContext());

            var id = AddGenderAndReturnId();
            using (var deleteContext = CreateObjectContext())
            {
                var entity = deleteContext.Genders.Single(g => g.Id == id);
                deleteContext.DeleteObject(entity);
                //act
                subject.TrackDelete(deleteContext.ObjectStateManager.GetObjectStateEntry(entity));
            }

            //assert
            Assert.AreEqual(1, subject.AuditEntities.Count);
            var auditEntity = subject.AuditEntities[0];
            Assert.AreEqual(typeof(EntityDeletedAudit), auditEntity.GetType());
        }
Ejemplo n.º 3
0
        public void tracks_add()
        {
            //setup
            var subject = new TrackingAuditEvent(CreateUserContext());

            var entity = new Gender();
            entity.Name = Guid.NewGuid().ToString();
            using (var addContext = CreateObjectContext())
            {
                addContext.Genders.AddObject(entity);
                addContext.SaveChanges();
                //act
                subject.TrackAdd(addContext.ObjectStateManager.GetObjectStateEntry(entity));
            }

            //assert
            Assert.AreEqual(1, subject.AuditEntities.Count);
            var auditEntity = subject.AuditEntities[0];
            Assert.AreEqual(typeof(EntityAddedAudit), auditEntity.GetType());
        }
Ejemplo n.º 4
0
        public void tracks_add_multiple()
        {
            //setup
            var subject = new TrackingAuditEvent(CreateUserContext());

            for (int x = 0; x < 10; x++)
            {
                var entity = new Gender();
                entity.Name = Guid.NewGuid().ToString();
                using (var addContext = CreateObjectContext())
                {
                    addContext.Genders.AddObject(entity);
                    addContext.SaveChanges();
                    //act
                    subject.TrackAdd(addContext.ObjectStateManager.GetObjectStateEntry(entity));
                }
            }

            //assert
            Assert.AreEqual(10, subject.AuditEntities.Count);
        }
Ejemplo n.º 5
0
        public void tracks_update()
        {
            //setup
            var subject = new TrackingAuditEvent(CreateUserContext());

            var entity = new Gender();
            entity.Name = Guid.NewGuid().ToString();
            int id;
            using (var addContext = CreateObjectContext())
            {
                addContext.Genders.AddObject(entity);
                addContext.SaveChanges();
                id = entity.Id;
            }
            entity = GetGenderById(id);
            entity.Name = Guid.NewGuid().ToString();
            using (var updateContext = CreateObjectContext())
            {
                var currentEntity = updateContext.Genders.Single(g => g.Id == id);
                updateContext.Genders.ApplyCurrentValues(entity);

                //act
                subject.TrackUpdate(updateContext.ObjectStateManager.GetObjectStateEntry(currentEntity));
            }

            //assert
            Assert.AreEqual(1, subject.AuditEntities.Count);
            var auditEntity = subject.AuditEntities[0];
            Assert.AreEqual(typeof(EntityUpdatedAudit), auditEntity.GetType());
        }
Ejemplo n.º 6
0
        public void tracks_read_multiple()
        {
            //setup
            var subject = new TrackingAuditEvent(CreateUserContext());
            for (int x = 0; x < 10; x++)
            {
                 AddGenderAndReturnId();
            }

            //act
            IEnumerable<Gender> all;
            using (var readContext = CreateObjectContext())
            {
                all = readContext.Genders.ToList();
                foreach (var entity in all)
                {
                    subject.TrackRead(entity);
                }
            }

            //assert
            Assert.AreEqual(all.Count(), subject.AuditEntities.Count);
        }
Ejemplo n.º 7
0
        public void tracks_read()
        {
            //setup
            var subject = new TrackingAuditEvent(CreateUserContext());

            var id = AddGenderAndReturnId();

            //act
            using (var readContext = CreateObjectContext())
            {
                var entity = readContext.Genders.Single(g => g.Id == id);
                subject.TrackRead(entity);
            }

            //assert
            Assert.AreEqual(1, subject.AuditEntities.Count);
            var auditEntity = subject.AuditEntities[0];
            Assert.AreEqual(typeof(EntityReadAudit), auditEntity.GetType());
        }
Ejemplo n.º 8
0
 private void InitializeAuditEvent()
 {
     _auditEvent = new TrackingAuditEvent(_userContext);
 }