예제 #1
0
        public void WhenChangedTest()
        {
            bool hasChanged1 = false;
            bool hasChanged2 = false;
            bool hasChanged3 = false;


            TrackableObject context2 = new TrackableObject();

            context2.Children.Add(new TrackableSubObject()
            {
                Name = "Sub 2"
            });
            context2.Children.Add(new TrackableSubObject()
            {
                Name = "Sub 3"
            });

            context2.StartTracking();
            context2.WhenChanged(() => { hasChanged1 = true; });
            context2.WhenChanged(() => { hasChanged2 = true; });


            context2.Children.WhenChanged(() => { hasChanged3 = true; });

            var subItem3 = new TrackableSubObject()
            {
                Name = "Sub 3"
            };

            context2.Children.Add(subItem3);
            subItem3.New(context2);

            Assert.IsTrue(hasChanged1);
            Assert.IsTrue(hasChanged2);
            Assert.IsTrue(hasChanged3);
        }
예제 #2
0
        public void MergeTrackingEntityTest()
        {
            TrackableObject context1 = new TrackableObject();

            context1.StartTracking();
            Assert.IsFalse(context1.HasChanges());

            context1.IntValue = 2;
            Assert.IsTrue(context1.HasChanges());

            var testSubItem = new TrackableSubObject()
            {
                Name = "Sub 1"
            };

            testSubItem.New();
            context1.Children.Add(testSubItem);
            Assert.IsTrue(context1.IsNew());

            Assert.IsTrue(context1.Children[0].HasChanges());
            Assert.IsTrue(context1.Children[0].IsNew());

            context1.Child = new TrackableSubObject()
            {
                Name = "Child 1"
            };
            context1.Child.New();

            TrackableObject context2 = new TrackableObject();

            context2.Children.Add(new TrackableSubObject()
            {
                Name = "Sub 2"
            });
            context2.Children.Add(new TrackableSubObject()
            {
                Name = "Sub 3"
            });

            context2.MergeTracking(context1);

            //Have the changes from context 1 been merged onto context 2?
            //If the merge was successful we should see changes merged onto context 2
            Assert.AreEqual(context1.IntValue, context2.IntValue);
            Assert.IsTrue(context2.HasChanges());

            Assert.IsFalse(context2.Children[0].HasChanges());
            Assert.IsFalse(context2.Children[1].HasChanges());

            Assert.IsTrue(context2.Children[2].HasChanges());
            Assert.IsTrue(context2.Children[2].IsNew());

            Assert.IsNotNull(context2.Child);
            Assert.IsTrue(context2.Child.IsNew());

            var postMergeSubItem = new TrackableSubObject()
            {
                Name = "Sub 4"
            };

            postMergeSubItem.New();
            context2.Children.Add(postMergeSubItem);
            Assert.IsTrue(context2.IsNew());
        }