示例#1
0
        public void ChangeTrackerTest()
        {
            var entity = new MockEntity();

            entity.EntityLoadCompleted();
            Assert.IsFalse(entity.HasChanges);
            var changesSnapshot1 = entity.GetChanges();

            Assert.IsFalse(changesSnapshot1.Any());

            AssertHelper.PropertyChangedEvent(entity, x => x.HasChanges, () => entity.Name = "Bill");
            Assert.IsTrue(entity.HasChanges);
            var changesSnapshot2 = entity.GetChanges();

            Assert.IsFalse(changesSnapshot1.Any());
            Assert.AreEqual("Name", changesSnapshot2.Single());

            AssertHelper.PropertyChangedEvent(entity, x => x.HasChanges, () => entity.ClearChanges());
            Assert.IsFalse(entity.HasChanges);
            var changesSnapshot3 = entity.GetChanges();

            Assert.IsFalse(changesSnapshot1.Any());
            Assert.AreEqual("Name", changesSnapshot2.Single());
            Assert.IsFalse(changesSnapshot3.Any());

            entity.Name = "Bill";
            Assert.IsFalse(entity.HasChanges);
        }
示例#2
0
        public void ChangeTrackerTest()
        {
            var entity = new MockEntity();
            Assert.IsFalse(entity.HasChanges);
            var changesSnapshot1 = entity.GetChanges();
            Assert.IsFalse(changesSnapshot1.Any());

            AssertHelper.PropertyChangedEvent(entity, x => x.HasChanges, () => entity.Name = "Bill");
            Assert.IsTrue(entity.HasChanges);
            var changesSnapshot2 = entity.GetChanges();
            Assert.IsFalse(changesSnapshot1.Any());
            Assert.AreEqual("Name", changesSnapshot2.Single());

            AssertHelper.PropertyChangedEvent(entity, x => x.HasChanges, () => entity.ClearChanges());
            Assert.IsFalse(entity.HasChanges);
            var changesSnapshot3 = entity.GetChanges();
            Assert.IsFalse(changesSnapshot1.Any());
            Assert.AreEqual("Name", changesSnapshot2.Single());
            Assert.IsFalse(changesSnapshot3.Any());

            entity.Name = "Bill";
            Assert.IsFalse(entity.HasChanges);
        }