public void ShouldNotTrackAddedItemAsModified() { var emailToAdd = new FriendEmailWrapper(new FriendEmail()); var c = new ChangeTrackingCollections <FriendEmailWrapper>(_emails); c.Add(emailToAdd); emailToAdd.Email = "*****@*****.**"; Assert.IsTrue(emailToAdd.IsChanged); Assert.AreEqual(3, c.Count); Assert.AreEqual(1, c.AddedItems.Count); Assert.AreEqual(0, c.RemovedItems.Count); Assert.AreEqual(0, c.ModifiedItems.Count); Assert.IsTrue(c.IsChanged); }
public void ShouldTrackRemovedItems() { var emailToRemove = _emails.First(); var c = new ChangeTrackingCollections <FriendEmailWrapper>(_emails); Assert.AreEqual(2, c.Count); Assert.IsFalse(c.IsChanged); c.Remove(emailToRemove); Assert.AreEqual(1, c.Count); Assert.AreEqual(0, c.AddedItems.Count); Assert.AreEqual(1, c.RemovedItems.Count); Assert.AreEqual(0, c.ModifiedItems.Count); Assert.AreEqual(emailToRemove, c.RemovedItems.First()); Assert.IsTrue(c.IsChanged); c.Add(emailToRemove); Assert.AreEqual(2, c.Count); Assert.AreEqual(0, c.AddedItems.Count); Assert.AreEqual(0, c.RemovedItems.Count); Assert.AreEqual(0, c.ModifiedItems.Count); Assert.IsFalse(c.IsChanged); }
public void ShouldRejectChanges() { var emailToModify = _emails.First(); var emailToRemove = _emails.Skip(1).First(); var emailToAdd = new FriendEmailWrapper(new FriendEmail { Email = "*****@*****.**" }); var c = new ChangeTrackingCollections <FriendEmailWrapper>(_emails); c.Add(emailToAdd); c.Remove(emailToRemove); emailToModify.Email = "*****@*****.**"; Assert.AreEqual("*****@*****.**", emailToModify.EmailOriginalValue); Assert.AreEqual(2, c.Count); Assert.AreEqual(1, c.AddedItems.Count); Assert.AreEqual(1, c.ModifiedItems.Count); Assert.AreEqual(1, c.RemovedItems.Count); c.RejectChanges(); Assert.AreEqual(2, c.Count); Assert.IsTrue(c.Contains(emailToModify)); Assert.IsTrue(c.Contains(emailToRemove)); Assert.AreEqual(0, c.AddedItems.Count); Assert.AreEqual(0, c.ModifiedItems.Count); Assert.AreEqual(0, c.RemovedItems.Count); Assert.IsFalse(emailToModify.IsChanged); Assert.AreEqual("*****@*****.**", emailToModify.Email); Assert.AreEqual("*****@*****.**", emailToModify.EmailOriginalValue); Assert.IsFalse(c.IsChanged); }