public void tells_if_has_changes_when_properties_are_modified() { //setup EntityUpdatedAudit subject; var initialName = Guid.NewGuid().ToString(); var newName = Guid.NewGuid().ToString(); var entity = new Gender(); entity.Name = initialName; int id; using (var addContext = CreateObjectContext()) { addContext.Genders.AddObject(entity); addContext.SaveChanges(); id = entity.Id; } entity = GetGenderById(id); entity.Name = newName; entity.IsEnabled = true; using (var updateContext = CreateObjectContext()) { var currentEntity = updateContext.Genders.Single(g => g.Id == entity.Id); updateContext.Genders.ApplyCurrentValues(entity); var objectStateEntry = updateContext.ObjectStateManager.GetObjectStateEntry(currentEntity); //act subject = new EntityUpdatedAudit(objectStateEntry); } //assert Assert.IsTrue(subject.HasChanges); }
public void does_not_track_database_generated_properties() { //setup EntityUpdatedAudit subject; var initialName = Guid.NewGuid().ToString(); var newName = Guid.NewGuid().ToString(); var entity = new Gender(); entity.Name = initialName; int id; using (var addContext = CreateObjectContext()) { addContext.Genders.AddObject(entity); addContext.SaveChanges(); id = entity.Id; } entity = GetGenderById(id); using (var updateContext = CreateObjectContext()) { var currentEntity = updateContext.Genders.Single(g => g.Id == entity.Id); updateContext.Genders.ApplyCurrentValues(entity); var objectStateEntry = updateContext.ObjectStateManager.GetObjectStateEntry(currentEntity); //act subject = new EntityUpdatedAudit(objectStateEntry); } var versionPropertyAudit = subject.AuditEntityProperties.Where(p => p.PropertyName == "Version").SingleOrDefault(); Assert.IsNull(versionPropertyAudit); }
/// <summary> /// Tracks the update. /// </summary> /// <param name="objectStateEntry">The object state entry.</param> public void TrackUpdate(ObjectStateEntry objectStateEntry) { if (objectStateEntry == null) { throw new ArgumentNullException("objectStateEntry"); } var updateAudit = new EntityUpdatedAudit(objectStateEntry); if (updateAudit.HasChanges) { AuditEntities.Add(updateAudit); } RemoveReads(); }
public void tracks_properties() { //setup EntityUpdatedAudit subject; var initialName = Guid.NewGuid().ToString(); var newName = Guid.NewGuid().ToString(); var entity = new Gender(); entity.Name = initialName; int id; using (var addContext = CreateObjectContext()) { addContext.Genders.AddObject(entity); addContext.SaveChanges(); id = entity.Id; } entity = GetGenderById(id); entity.Name = newName; entity.IsEnabled = true; using (var updateContext = CreateObjectContext()) { var currentEntity = updateContext.Genders.Single(g => g.Id == entity.Id); updateContext.Genders.ApplyCurrentValues(entity); var objectStateEntry = updateContext.ObjectStateManager.GetObjectStateEntry(currentEntity); //act subject = new EntityUpdatedAudit(objectStateEntry); } //assert var namePropertyAudit = subject.AuditEntityProperties.Where(p => p.PropertyName == "Name").SingleOrDefault(); Assert.IsNotNull(namePropertyAudit); Assert.AreEqual(newName, namePropertyAudit.NewValue); Assert.AreEqual(initialName, namePropertyAudit.OriginalValue); var isEnabledPropertyAudit = subject.AuditEntityProperties.Where(p => p.PropertyName == "IsEnabled").SingleOrDefault(); Assert.IsNotNull(isEnabledPropertyAudit); Assert.AreEqual(true.ToString(), isEnabledPropertyAudit.NewValue); Assert.AreEqual(false.ToString(), isEnabledPropertyAudit.OriginalValue); }
public void tracks_action() { EntityUpdatedAudit subject; //setup var initialValue = Guid.NewGuid().ToString(); var entity = new Gender(); entity.Name = initialValue; int id; using (var addContext = CreateObjectContext()) { addContext.Genders.AddObject(entity); addContext.SaveChanges(); id = entity.Id; } entity = GetGenderById(id); var newValue = Guid.NewGuid().ToString(); entity.Name = newValue; using (var updateContext = CreateObjectContext()) { var currentEntity = updateContext.Genders.Single(g => g.Id == entity.Id); updateContext.Genders.ApplyCurrentValues(entity); var objectStateEntry = updateContext.ObjectStateManager.GetObjectStateEntry(currentEntity); //act subject = new EntityUpdatedAudit(objectStateEntry); } //assert Assert.AreEqual(AuditEntityAction.Update, subject.AuditEntityAction); }