Skip to content

Commit

Permalink
Merge branch 'MarcDrexler-develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Sneed committed Aug 30, 2016
2 parents fea857d + 17ad6b9 commit 2b32d09
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,24 @@ public void Added_Employee_After_Tracking_Enabled_Should_Not_Mark_Manually_Added
Assert.Equal(TrackingState.Added, employee.TrackingState);
Assert.True(employee.Territories.All(t => t.TrackingState == TrackingState.Added));
}

[Fact]
public void Adding_And_Removing_The_Same_Territory_Should_Not_Keep_Added_Territory_In_Territory_Collection()
{
// Arrange
var database = new MockNorthwind();
var employee = database.Employees[0];
var changeTracker = new ChangeTrackingCollection<Employee>(employee);

// Act
employee.Territories.Add(database.Territories[4]);
employee.Territories.Remove(database.Territories[4]);

// Assert
var changes = changeTracker.GetChanges();
Assert.Equal(0, changes.Count);
Assert.Equal(3, employee.Territories.Count);
}

#endregion

Expand Down
2 changes: 2 additions & 0 deletions Source/TrackableEntities.Client/ChangeTrackingCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,13 +235,15 @@ protected override void RemoveItem(int index)
item.SetTracking(false, visitationHelper.Clone(), true);

// Mark item and trackable collection properties
bool manyToManyAdded = Parent != null && item.TrackingState == TrackingState.Added;
item.SetState(TrackingState.Deleted, visitationHelper.Clone());

// Fire EntityChanged event
if (EntityChanged != null) EntityChanged(this, EventArgs.Empty);

// Cache deleted item if not added or already cached
if (item.TrackingState != TrackingState.Added
&& !manyToManyAdded
&& !_deletedEntities.Contains(item))
_deletedEntities.Add(item);
}
Expand Down

0 comments on commit 2b32d09

Please sign in to comment.