/// <summary> /// Tracks the properties. /// </summary> /// <param name="objectStateEntry">The object state entry.</param> protected void TrackProperties(ObjectStateEntry objectStateEntry) { foreach (string propertyName in objectStateEntry.GetModifiedProperties()) { if (!IsStoreGenerated(propertyName, objectStateEntry)) { var auditProperty = new TrackingAuditEntityProperty(propertyName, objectStateEntry); if (auditProperty.HasChanges) { AuditEntityProperties.Add(auditProperty); } } } }
public void tells_if_does_not_have_changes_when_no_properties_change() { var initialValue = Guid.NewGuid().ToString(); var entity = new Gender(); entity.Name = initialValue; var context = CreateObjectContext(); context.Genders.Attach(entity); context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); var objectStateEntry = context.ObjectStateManager.GetObjectStateEntry(entity); //act var subject = new TrackingAuditEntityProperty("Name", objectStateEntry); Assert.IsFalse(subject.HasChanges); }
public void tracks_property_value_on_add() { //setup var newValue = Guid.NewGuid().ToString(); var entity = new Gender(); entity.Name = newValue; var context = CreateObjectContext(); context.Genders.AddObject(entity); var objectStateEntry = context.ObjectStateManager.GetObjectStateEntry(entity); //act var subject = new TrackingAuditEntityProperty("Name", objectStateEntry); //assert Assert.AreEqual("Name", subject.PropertyName); Assert.AreEqual(newValue, subject.NewValue); }
public void tracks_property_value_on_update() { //setup var newValue = Guid.NewGuid().ToString(); var initialValue = Guid.NewGuid().ToString(); var entity = new Gender(); entity.Name = initialValue; var context = CreateObjectContext(); context.Genders.Attach(entity); entity.Name = newValue; context.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); var objectStateEntry = context.ObjectStateManager.GetObjectStateEntry(entity); //act var subject = new TrackingAuditEntityProperty("Name", objectStateEntry); //assert Assert.AreEqual("Name", subject.PropertyName); Assert.AreEqual(initialValue, subject.OriginalValue); Assert.AreEqual(newValue, subject.NewValue); }