示例#1
0
        public void TestTouching()
        {
            var change1 = new ChangeableProperty <bool>(true);

            Assert.IsFalse(change1.IsTouched);

            change1.Touch();
            Assert.IsTrue(change1.IsTouched);

            change1.Touch();
            Assert.IsTrue(change1.IsTouched);

            change1.Reset(ValueResetType.Soft);
            Assert.IsTrue(change1.IsTouched);

            change1.Reset(ValueResetType.Hard);
            Assert.IsFalse(change1.IsTouched);
        }
示例#2
0
        public void TestReset()
        {
            var change1 = new ChangeableProperty <bool>(false);

            change1.CurrentValue = true;
            Assert.IsFalse(change1.OriginalValue, "Original value must not be changed.");
            Assert.IsTrue(change1.CurrentValue);
            Assert.IsTrue(change1.IsDirty);
            Assert.IsTrue(change1.IsTouched);

            change1.Reset();
            Assert.IsFalse(change1.OriginalValue, "Original value must not be changed by reset methods.");
            Assert.IsFalse(change1.CurrentValue);
            Assert.IsFalse(change1.IsDirty);
            Assert.IsFalse(change1.IsTouched);

            var change2 = new ChangeableProperty <bool>(false);

            change2.Reset(); // calling reset without changing the value
            Assert.IsFalse(change2.OriginalValue);
            Assert.IsFalse(change2.CurrentValue);
            Assert.IsFalse(change2.IsDirty);
            Assert.IsFalse(change2.IsTouched);

            change2.CurrentValue = true;
            change2.Reset(ValueResetType.Soft);
            Assert.IsFalse(change2.OriginalValue, "Original value must not be changed by reset methods.");
            Assert.IsFalse(change2.CurrentValue, "Current value must be reset to the base value after calling reset.");
            Assert.IsFalse(change2.IsDirty, "IsDirty must be False after calling reset.");
            Assert.IsTrue(change2.IsTouched, "When resetting using soft mode, the IsTouched flag must be not changed.");

            change2.CurrentValue = true;
            change2.Reset(ValueResetType.Hard);
            Assert.IsFalse(change2.OriginalValue, "Original value must not be changed by reset methods.");
            Assert.IsFalse(change2.CurrentValue, "Current value must be reset to the base value after calling reset.");
            Assert.IsFalse(change2.IsDirty, "IsDirty must be False after calling reset.");
            Assert.IsFalse(change2.IsTouched, "When resetting using hard mode, the IsTouched flag must be always false.");
        }
示例#3
0
        public void ChangeableContainerTest()
        {
            var prop1 = new ChangeableProperty <string>("initial");
            var prop2 = new ChangeableProperty <string>("initial");

            var container = new ChangeableContainer(prop1, prop2);

            Assert.IsFalse(prop1.IsTouched);
            Assert.IsFalse(prop2.IsTouched);
            Assert.IsFalse(container.IsTouched);
            Assert.IsFalse(prop1.IsDirty);
            Assert.IsFalse(prop2.IsDirty);
            Assert.IsFalse(container.IsDirty);

            prop1.CurrentValue = "other";
            Assert.IsTrue(prop1.IsTouched);
            Assert.IsFalse(prop2.IsTouched);
            Assert.IsTrue(container.IsTouched);
            Assert.IsTrue(prop1.IsDirty);
            Assert.IsFalse(prop2.IsDirty);
            Assert.IsTrue(container.IsDirty);

            prop1.CurrentValue = "initial";
            Assert.IsTrue(prop1.IsTouched);
            Assert.IsFalse(prop2.IsTouched);
            Assert.IsTrue(container.IsTouched);
            Assert.IsFalse(prop1.IsDirty);
            Assert.IsFalse(prop2.IsDirty);
            Assert.IsFalse(container.IsDirty);

            prop1.Reset(ValueResetType.Hard);
            Assert.IsFalse(prop1.IsTouched);
            Assert.IsFalse(prop2.IsTouched);
            Assert.IsFalse(container.IsTouched);
            Assert.IsFalse(prop1.IsDirty);
            Assert.IsFalse(prop2.IsDirty);
            Assert.IsFalse(container.IsDirty);

            prop2.CurrentValue = "second";
            Assert.IsFalse(prop1.IsTouched);
            Assert.IsTrue(prop2.IsTouched);
            Assert.IsTrue(container.IsTouched);
            Assert.IsFalse(prop1.IsDirty);
            Assert.IsTrue(prop2.IsDirty);
            Assert.IsTrue(container.IsDirty);

            container.Reset(ValueResetType.Hard);
            Assert.IsFalse(prop1.IsTouched);
            Assert.IsFalse(prop2.IsTouched);
            Assert.IsFalse(container.IsTouched);
            Assert.IsFalse(prop1.IsDirty);
            Assert.IsFalse(prop2.IsDirty);
            Assert.IsFalse(container.IsDirty);

            prop2.CurrentValue = "second";
            container.Commit();
            Assert.IsFalse(prop1.IsTouched);
            Assert.IsFalse(prop2.IsTouched);
            Assert.IsFalse(container.IsTouched);
            Assert.IsFalse(prop1.IsDirty);
            Assert.IsFalse(prop2.IsDirty);
            Assert.IsFalse(container.IsDirty);
        }