Beispiel #1
0
        public void ShouldRejectChangesWithModifiedAndRemovedItem()
        {
            var email = _emails.First();

            var c = new ValidatableChangeTrackingCollection <TestFriendEmailWrapper>(_emails);

            email.Email = "*****@*****.**";
            c.Remove(email);
            Assert.AreEqual("*****@*****.**", email.EmailOriginalValue);

            Assert.AreEqual(1, c.Count);
            Assert.AreEqual(0, c.AddedItems.Count);
            Assert.AreEqual(0, c.ModifiedItems.Count);
            Assert.AreEqual(1, c.RemovedItems.Count);

            c.RejectChanges();

            Assert.AreEqual(2, c.Count);
            Assert.IsTrue(c.Contains(email));

            Assert.AreEqual(0, c.AddedItems.Count);
            Assert.AreEqual(0, c.ModifiedItems.Count);
            Assert.AreEqual(0, c.RemovedItems.Count);

            Assert.IsFalse(email.IsChanged);
            Assert.AreEqual("*****@*****.**", email.Email);
            Assert.AreEqual("*****@*****.**", email.EmailOriginalValue);

            Assert.IsFalse(c.IsChanged);
        }
Beispiel #2
0
        public void ShouldNotTrackRemovedItemAsModified()
        {
            var emailToModifyAndRemove = _emails.First();

            var c = new ValidatableChangeTrackingCollection <TestFriendEmailWrapper>(_emails);

            emailToModifyAndRemove.Email = "*****@*****.**";
            Assert.AreEqual(2, c.Count);
            Assert.AreEqual(0, c.AddedItems.Count);
            Assert.AreEqual(0, c.RemovedItems.Count);
            Assert.AreEqual(1, c.ModifiedItems.Count);
            Assert.AreEqual(emailToModifyAndRemove, c.ModifiedItems.First());
            Assert.IsTrue(c.IsChanged);

            c.Remove(emailToModifyAndRemove);
            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(emailToModifyAndRemove, c.RemovedItems.First());
            Assert.IsTrue(c.IsChanged);
        }
Beispiel #3
0
        public void ShouldRejectChanges()
        {
            var emailToModify = _emails.First();
            var emailToRemove = _emails.Skip(1).First();
            var emailToAdd    =
                new TestFriendEmailWrapper(new TestFriendEmail
            {
                Email = "*****@*****.**"
            });

            var c = new ValidatableChangeTrackingCollection <TestFriendEmailWrapper>(_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);
        }
Beispiel #4
0
        public void ShouldTrackRemovedItems()
        {
            var emailToRemove = _emails.First();
            var c             = new ValidatableChangeTrackingCollection <TestFriendEmailWrapper>(_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);
        }
Beispiel #5
0
        public void ShouldTrackAddedItems()
        {
            var emailToAdd = _testWrappersFactory.GetWrapper <TestFriendEmailWrapper>(new TestFriendEmail());

            var c = new ValidatableChangeTrackingCollection <TestFriendEmailWrapper>(_emails);

            Assert.AreEqual(2, c.Count);
            Assert.IsFalse(c.IsChanged);

            c.Add(emailToAdd);
            Assert.AreEqual(3, c.Count);
            Assert.AreEqual(1, c.AddedItems.Count);
            Assert.AreEqual(0, c.RemovedItems.Count);
            Assert.AreEqual(0, c.ModifiedItems.Count);
            Assert.AreEqual(emailToAdd, c.AddedItems.First());
            Assert.IsTrue(c.IsChanged);

            c.Remove(emailToAdd);
            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);
        }