Пример #1
0
        public void TestEditableCollectionAndEditableCollection()
        {
            var sampleData       = GenerateSampleData(10);
            var sourceCollection = new EditableCollection <int>();
            IEditableCollection <int> targetCollection = new EditableCollection <int>();

            var syncer = targetCollection.SyncWith(sourceCollection, (itemB) => itemB);

            sourceCollection.AddRange(sampleData);

            CollectionAssert.AreEqual(sourceCollection, targetCollection);

            sourceCollection.Remove(sampleData[0]);

            CollectionAssert.AreEqual(sourceCollection, targetCollection);

            sourceCollection.Clear();

            CollectionAssert.AreEqual(sourceCollection, targetCollection);
        }
Пример #2
0
        public void TestSyncerChain()
        {
            var sampleData = GenerateSampleData(10);
            IEditableCollection <int> sourceCollection = new EditableCollection <int>();
            IEditableCollection <int> interCollection  = new EditableCollection <int>();
            IEditableCollection <int> targetCollection = new EditableCollection <int>();

            var syncer1 = targetCollection.SyncWith(interCollection, (itemB) => itemB);
            var syncer2 = interCollection.SyncWith(sourceCollection, (itemB) => itemB);

            sourceCollection.BeginUpdate();
            sourceCollection.Add(sampleData[0]);
            sourceCollection.Add(sampleData[1]);
            sourceCollection.Add(sampleData[2]);

            CollectionAssert.AreNotEqual(sourceCollection, targetCollection);

            sourceCollection.Remove(sampleData[0]);

            CollectionAssert.AreNotEqual(sourceCollection, targetCollection);

            bool eventFired = false;

            syncer1.Synced += delegate(object sender, SyncEventArgs <int, int> args) { eventFired = true; };

            sourceCollection.EndUpdate();

            Assert.AreEqual(true, eventFired);
            CollectionAssert.AreEqual(sourceCollection, targetCollection);

            sourceCollection.AddRange(sampleData);
            CollectionAssert.AreEqual(sourceCollection, targetCollection);

            sourceCollection.Clear();
            CollectionAssert.AreEqual(sourceCollection, targetCollection);
        }