Ejemplo n.º 1
0
        public void TestMethod_TestAfterInitialize(string order)
        {
            SourceObvListA = getSampleSourceList();
            DestObvListA   = new ObservableList <DestItemA>();

            ObvListSyncA = new ObservableListSynchronizerFunc <SourceItemA, DestItemA>(
                (sourceItem) => new DestItemA {
                MyNum = sourceItem.MyNum.ToString(), MyStringUpper = sourceItem.MyStringLower.ToUpper()
            },
                (destItem) => new SourceItemA {
                MyNum = int.Parse(destItem.MyNum), MyStringLower = destItem.MyStringUpper.ToLower()
            }
                );

            //Tests several order with same boiler plate code.
            if (order == "SourceFirst")
            {
                ObvListSyncA.SourceObservableList      = SourceObvListA;
                ObvListSyncA.DestinationObservableList = DestObvListA;
            }

            if (order == "DestFirst")
            {
                ObvListSyncA.DestinationObservableList = DestObvListA;
                ObvListSyncA.SourceObservableList      = SourceObvListA;
            }


            Assert.AreEqual(SourceObvListA.Count, DestObvListA.Count);
            for (var index = 0; index < 3; index++)
            {
                Assert.AreEqual(SourceObvListA[index].MyNum.ToString(), DestObvListA[index].MyNum);
                Assert.AreEqual(SourceObvListA[index].MyStringLower.ToUpper(), DestObvListA[index].MyStringUpper);
            }
        }
Ejemplo n.º 2
0
        public void TestMethod_AddSubtractOneWaySync()
        {
            SourceObvListA = new ObservableList <SourceItemA>();
            DestObvListA   = new ObservableList <DestItemA>();

            ObvListSyncA = new ObservableListSynchronizerFunc <SourceItemA, DestItemA>(
                (sourceItem) => new DestItemA {
                MyNum = sourceItem.MyNum.ToString(), MyStringUpper = sourceItem.MyStringLower.ToUpper()
            },
                (destItem) => new SourceItemA {
                MyNum = int.Parse(destItem.MyNum), MyStringLower = destItem.MyStringUpper.ToLower()
            },
                SourceObvListA,
                DestObvListA
                );

            ObvListSyncA.IsSyncSourceToDestCollection = true;
            ObvListSyncA.IsSyncDestToSourceCollection = false;

            var item1 = new SourceItemA {
                MyNum = 10, MyStringLower = "x"
            };
            var item2 = new SourceItemA {
                MyNum = 15, MyStringLower = "y"
            };
            var item3 = new DestItemA {
                MyNum = "1000", MyStringUpper = "A"
            };
            var item4 = new DestItemA {
                MyNum = "2000", MyStringUpper = "B"
            };

            SourceObvListA.Add(item1);
            SourceObvListA.Add(item2);

            DestObvListA.Add(item3);
            DestObvListA.Add(item4);


            Assert.AreEqual(SourceObvListA.Count, 2);
            Assert.AreEqual(DestObvListA.Count, 4);

            for (var index = 0; index < SourceObvListA.Count; index++)
            {
                Assert.AreEqual(SourceObvListA[index].MyNum.ToString(), DestObvListA[index].MyNum);
                Assert.AreEqual(SourceObvListA[index].MyStringLower.ToUpper(), DestObvListA[index].MyStringUpper);
                Console.WriteLine("Source: " + SourceObvListA[index].MyStringLower + "  Dest: " + DestObvListA[index].MyStringUpper);
            }

            Assert.AreEqual(SourceObvListA[0], item1);
            Assert.AreEqual(SourceObvListA[1], item2);

            Assert.AreEqual(DestObvListA[0], ObvListSyncA.ConvertSourceToDestination(item1));
            Assert.AreEqual(DestObvListA[1], ObvListSyncA.ConvertSourceToDestination(item2));

            Assert.AreEqual(DestObvListA[2], item3);
            Assert.AreEqual(DestObvListA[3], item4);
        }
Ejemplo n.º 3
0
        public void TestMethod_TestAfterInitializeReplace(int firstCommand, int secondCommand, string result)
        {
            SourceObvListA = getSampleSourceList();
            DestObvListA   = getSampleDestList();

            var sourceItemCheck = SourceObvListA[0].MyStringLower;
            var destItemCheck   = DestObvListA[0].MyStringUpper;

            ObvListSyncA = new ObservableListSynchronizerFunc <SourceItemA, DestItemA>(
                (sourceItem) => new DestItemA {
                MyNum = sourceItem.MyNum.ToString(), MyStringUpper = sourceItem.MyStringLower.ToUpper()
            },
                (destItem) => new SourceItemA {
                MyNum = int.Parse(destItem.MyNum), MyStringLower = destItem.MyStringUpper.ToLower()
            }
                );

            List <Action> actionList = new List <Action>();

            actionList.Insert(0, () => ObvListSyncA.ReplaceSource_SyncToDestination(SourceObvListA));
            actionList.Insert(1, () => ObvListSyncA.ReplaceSource_SyncFromDestination(SourceObvListA));

            actionList.Insert(2, () => ObvListSyncA.ReplaceDestination_SyncToSource(DestObvListA));
            actionList.Insert(3, () => ObvListSyncA.ReplaceDestination_SyncFromSource(DestObvListA));

            actionList[firstCommand].Invoke();
            actionList[secondCommand].Invoke();


            ///Both lists are cleared
            if (result == "Clear")
            {
                Assert.AreEqual(SourceObvListA.Count, DestObvListA.Count);
                Assert.AreEqual(SourceObvListA.Count, 0);
                return;
            }

            ///Test that lists are synced
            Assert.AreEqual(SourceObvListA.Count, DestObvListA.Count);
            for (var index = 0; index < 3; index++)
            {
                Assert.AreEqual(SourceObvListA[index].MyNum.ToString(), DestObvListA[index].MyNum);
                Assert.AreEqual(SourceObvListA[index].MyStringLower.ToUpper(), DestObvListA[index].MyStringUpper);
                Console.WriteLine("Source: " + SourceObvListA[index].MyStringLower + "  Dest: " + DestObvListA[index].MyStringUpper);
            }

            if (result == "Source")
            {
                Assert.AreEqual(sourceItemCheck, SourceObvListA[0].MyStringLower);                      // Source list is preserved
            }
            if (result == "Dest")
            {
                Assert.AreEqual(destItemCheck, DestObvListA[0].MyStringUpper);                   // Dest list is preserved
            }
        }
Ejemplo n.º 4
0
        public void TestMethod_PropertyNotify()
        {
            SourceObvListB = new ObservableList <SourceItemB>();
            DestObvListB   = new ObservableList <DestItemB>();

            ObvListSyncB = new ObservableListSynchronizerFunc <SourceItemB, DestItemB>(
                (sourceItem) => new DestItemB(sourceItem),
                (destItem) => destItem.SourceItem,
                SourceObvListB,
                DestObvListB,
                true,
                true
                );

            var item1 = new SourceItemB {
                MyNum = 10, MyStringLower = "x"
            };
            var item2 = new DestItemB {
                MyNum = "1000", MyStringUpper = "A"
            };


            SourceObvListB.Add(item1);
            DestObvListB.Add(item2);

            SourceObvListB[0].PropertyChanged += (sender, args) => AssertEvent.Call("source[0] event");
            DestObvListB[0].PropertyChanged   += (sender, args) => AssertEvent.Call("dest[0] event");
            SourceObvListB[1].PropertyChanged += (sender, args) => AssertEvent.Call("source[1] event");
            DestObvListB[1].PropertyChanged   += (sender, args) => AssertEvent.Call("dest[1] event");


            var string1 = "TEST STRING";
            var string2 = "TEST STRING AGAIN";

            SourceObvListB[0].MyNum       = -1;
            DestObvListB[1].MyStringUpper = string1;
            DestObvListB[1].MyStringUpper = string2;

            Assert.AreEqual(string2, DestObvListB[1].MyStringUpper);
            Assert.AreEqual(string2.ToLower(), SourceObvListB[1].MyStringLower);

            MockEvent.Verify(m => m.Call("source[0] event"), Times.Exactly(1));
            MockEvent.Verify(m => m.Call("dest[0] event"), Times.Exactly(1));
            MockEvent.Verify(m => m.Call("source[1] event"), Times.Exactly(2));
            MockEvent.Verify(m => m.Call("dest[1] event"), Times.Exactly(2));
        }
Ejemplo n.º 5
0
        public void TestMethod_CopyOnInitialize()
        {
            SourceObvListA = getSampleSourceList();
            DestObvListA   = new ObservableList <DestItemA>();

            ObvListSyncA = new ObservableListSynchronizerFunc <SourceItemA, DestItemA>(
                (sourceItem) => new DestItemA {
                MyNum = sourceItem.MyNum.ToString(), MyStringUpper = sourceItem.MyStringLower.ToUpper()
            },
                (destItem) => new SourceItemA {
                MyNum = int.Parse(destItem.MyNum), MyStringLower = destItem.MyStringUpper.ToLower()
            },
                SourceObvListA,
                DestObvListA
                );

            Assert.AreEqual(SourceObvListA.Count, DestObvListA.Count);
            for (var index = 0; index < 3; index++)
            {
                Assert.AreEqual(SourceObvListA[index].MyNum.ToString(), DestObvListA[index].MyNum);
                Assert.AreEqual(SourceObvListA[index].MyStringLower.ToUpper(), DestObvListA[index].MyStringUpper);
            }
        }