public void ApplyStateChangedTest()
        {
            {
                var sample1 = new SampleEntity();
                var sample2 = new SampleEntity();

                Assert.IsFalse(StateUtil.ApplyStateChanged(sample1, sample2));
                Assert.IsFalse(sample1.IsStateChanged);
                Assert.IsFalse(sample2.IsStateChanged);

                sample2.Id = 2;

                Assert.IsTrue(StateUtil.ApplyStateChanged(sample1, sample2));
                Assert.IsFalse(sample1.IsStateChanged);
                Assert.IsTrue(sample2.IsStateChanged);

                sample2.SetStateChanged(false);
                sample2.Id   = 1;
                sample2.Name = "Kuma";

                Assert.IsTrue(StateUtil.ApplyStateChanged(sample1, sample2));
                Assert.IsFalse(sample1.IsStateChanged);
                Assert.IsTrue(sample2.IsStateChanged);
            }

            {
                var root1 = new RootEntity();
                var root2 = new RootEntity();

                Assert.IsFalse(StateUtil.ApplyStateChanged(root1, root2));
                Assert.IsFalse(root1.IsStateChanged);
                Assert.IsFalse(root2.IsStateChanged);

                root2.Sample = new SampleEntity();
                Assert.IsTrue(StateUtil.ApplyStateChanged(root1, root2));
                Assert.IsFalse(root1.IsStateChanged);
                Assert.IsTrue(root2.IsStateChanged);

                root2.SetStateChanged(false);

                root1.Sample = new SampleEntity();
                Assert.IsFalse(StateUtil.ApplyStateChanged(root1, root2));
                Assert.IsFalse(root1.IsStateChanged);
                Assert.IsFalse(root2.IsStateChanged);

                root2.Sample.Id = root1.Sample.Id + 1;
                Assert.IsTrue(StateUtil.ApplyStateChanged(root1, root2));
                Assert.IsFalse(root1.IsStateChanged);
                Assert.IsTrue(root2.IsStateChanged);
            }
        }
Beispiel #2
0
        public void MemoryCloneTest()
        {
            var sample1 = new SampleEntity();

            sample1.SetStateChanged();
            var sample2 = CloneUtil.MemoryClone(sample1) as SampleEntity;

            Assert.AreEqual(sample1.Id, sample2.Id);
            Assert.AreEqual(sample1.Name, sample2.Name);
            Assert.AreEqual(sample1.IsStateChanged, sample2.IsStateChanged);

            sample2.Id   = sample1.Id + 1;
            sample2.Name = "John";

            Assert.AreNotEqual(sample1.Id, sample2.Id);
            Assert.AreNotEqual(sample1.Name, sample2.Name);
        }
        public void ResetStateChangedTest()
        {
            var sample = new SampleEntity();

            sample.SetStateChanged();
            Assert.IsTrue(sample.IsStateChanged);
            StateUtil.ResetStateChanged(sample);
            Assert.IsFalse(sample.IsStateChanged);

            var root = new RootEntity();

            root.SetStateChanged();
            root.Sample = new SampleEntity();
            root.Sample.SetStateChanged();
            Assert.IsTrue(root.IsStateChanged);
            Assert.IsTrue(root.Sample.IsStateChanged);
            StateUtil.ResetStateChanged(root);
            Assert.IsFalse(root.IsStateChanged);
            Assert.IsFalse(root.Sample.IsStateChanged);
        }