Пример #1
0
        public void ValidateObservableCollectionBool()
        {
            var col1          = new[] { true, true, true };
            var changeableCol = new ChangeableCollection <bool>(col1);

            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);

            changeableCol.Add(true);
            Assert.IsTrue(changeableCol.IsTouched);
            Assert.IsTrue(changeableCol.IsDirty);

            changeableCol.RemoveAt(3);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.RemoveAt(2);
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Add(true);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol[0] = false;
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol[0] = true;
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.RemoveAt(0);
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Reset(ValueResetType.Soft);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.RemoveAt(0);

            changeableCol.Reset(ValueResetType.Hard);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);

            changeableCol.Add(true);
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Commit();
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);
        }
Пример #2
0
        public void ValidateObservableCollectionString()
        {
            var col1          = new[] { "string1", "string2", "string3" };
            var changeableCol = new ChangeableCollection <string>(col1);

            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);

            changeableCol.Add("string4");
            Assert.IsTrue(changeableCol.IsTouched);
            Assert.IsTrue(changeableCol.IsDirty);

            changeableCol.Remove("string4");
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Remove("string3");
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Add("string3");
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol[0] = "string1a";
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol[0] = "string1";
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.RemoveAt(0);
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Reset(ValueResetType.Soft);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.RemoveAt(0);

            changeableCol.Reset(ValueResetType.Hard);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);

            changeableCol.Add("string4");
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Commit();
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);
        }
Пример #3
0
        public void ValidateObservableCollectionChangeables()
        {
            var col1          = new[] { "string1", "string2", "string3" };
            var changeableCol = new ChangeableCollection <ChangeableProperty <string> >(col1.Select(c => new ChangeableProperty <string>(c)));

            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);

            changeableCol.Add(new ChangeableProperty <string>("string4"));
            Assert.IsTrue(changeableCol.IsTouched);
            Assert.IsTrue(changeableCol.IsDirty);

            changeableCol.RemoveAt(3);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.RemoveAt(2);
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Add(new ChangeableProperty <string>("string3"));
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Reset(ValueResetType.Hard);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);

            changeableCol[0].CurrentValue = "string1a";
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Reset(ValueResetType.Hard);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);

            changeableCol[0].CurrentValue = "string1";
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);

            changeableCol[0].CurrentValue = "string1a";
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol[0].CurrentValue = "string1";
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol[0].Reset(ValueResetType.Hard);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched, "Resetting a single dirty item should set the dirty flag to true, but touched should remain.");

            changeableCol.Reset();
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);

            changeableCol[0].CurrentValue = "aaa";
            changeableCol[1].CurrentValue = "bbb";
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);
            changeableCol[0].Reset();
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);
            changeableCol[1].Reset();
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.RemoveAt(0);
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Reset(ValueResetType.Soft);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.RemoveAt(0);

            changeableCol.Reset(ValueResetType.Hard);
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);

            changeableCol.Add(new ChangeableProperty <string>("string4"));
            Assert.IsTrue(changeableCol.IsDirty);
            Assert.IsTrue(changeableCol.IsTouched);

            changeableCol.Commit();
            Assert.IsFalse(changeableCol.IsDirty);
            Assert.IsFalse(changeableCol.IsTouched);
        }