/// <summary> /// Sets the <see cref="IsChanged"/> flag to true manually. /// </summary> public void SetChanged() { // the order of these two operations is important // to keep the service in a consistent state IsChanged = true; if (ChangeTrackingService != null) { ChangeTrackingService.Add(this); } OnSetChanged(); }
public void Add_UnchangedObjectIsAdded_ThrowsException() { _InitializeDependencies(); // stub change tracking object var changedObject = new Mock <IChangeTracking>(); changedObject.Setup(o => o.IsChanged) .Returns(false); var target = new ChangeTrackingService(); target.Add(changedObject.Object); }
public void Add_ChangedObjectIsAdded_HasChangesIsTrue() { _InitializeDependencies(); // stub change tracking object var changedObject = new Mock <IChangeTracking>(); changedObject.Setup(o => o.IsChanged) .Returns(true); var target = new ChangeTrackingService(); target.Add(changedObject.Object); Assert.IsTrue(target.HasChanges); }
public void Add_ChangedObjectIsAdded_RaisesHasChangesChangedEvent() { _InitializeDependencies(); // stub change tracking object var changedObject = new Mock <IChangeTracking>(); changedObject.Setup(o => o.IsChanged) .Returns(true); bool eventWasRaised = false; var target = new ChangeTrackingService(); target.HasChangesChanged += (o, e) => eventWasRaised = true; target.Add(changedObject.Object); Assert.IsTrue(eventWasRaised); }
public void HasChanges_ChangedObjectIsResetToUnchangedButNotRemoved_ThrowsException() { _InitializeDependencies(); // stub change tracking object var changedObject = new Mock <IChangeTracking>(); changedObject.Setup(o => o.IsChanged) .Returns(true); var target = new ChangeTrackingService(); target.Add(changedObject.Object); // reset change (cannot be detected by service) changedObject.Setup(o => o.IsChanged) .Returns(false); // successive access to "HasChanges" shall detect invalid state var hasChanges = target.HasChanges; }