Exemplo n.º 1
0
        public void TestItemsDiff()
        {
            List <ItemInfo> prev = null;
            List <ItemInfo> curr = null;
            Tuple <List <ItemInfo>, List <ItemInfo> > res = null;

            // nothing old, nothing new (null version)
            res = DiffUtil.ItemsDiff(curr, prev);
            Assert.IsNull(res.Item1);
            Assert.IsNull(res.Item2);

            // nothing old, nothing new (empty list version)
            prev = new List <ItemInfo>();
            curr = new List <ItemInfo>();
            res  = DiffUtil.ItemsDiff(curr, prev);
            Assert.IsNull(res.Item1);
            Assert.IsNull(res.Item2);

            // nothing old, one new
            // -> nothing removed, one added
            curr = new List <ItemInfo>
            {
                new ItemInfo {
                    GUID = 1, Class = 1
                },
            };
            res = DiffUtil.ItemsDiff(curr, prev);
            Assert.IsNull(res.Item2);
            CollectionAssert.AreEquivalent(curr, res.Item1);

            // one old, one new
            // -> nothing removed, one added
            prev = new List <ItemInfo>
            {
                new ItemInfo {
                    GUID = 1, Class = 1
                },
            };
            curr = new List <ItemInfo>
            {
                new ItemInfo {
                    GUID = 1, Class = 1
                },
                new ItemInfo {
                    GUID = 2, Class = 2
                },
            };
            res = DiffUtil.ItemsDiff(curr, prev);
            Assert.IsNull(res.Item2);
            Assert.AreEqual(1, res.Item1.Count);
            Assert.IsTrue(ItemInfo.AreEqual(curr[1], res.Item1[0]));

            // one old, one new
            // -> one removed, one added
            prev = new List <ItemInfo>
            {
                new ItemInfo {
                    GUID = 1, Class = 1
                },
            };
            curr = new List <ItemInfo>
            {
                new ItemInfo {
                    GUID = 2, Class = 2
                },
            };
            res = DiffUtil.ItemsDiff(curr, prev);
            CollectionAssert.AreEquivalent(curr, res.Item1);
            CollectionAssert.AreEquivalent(prev, res.Item2);

            // one old, nothing new
            // -> one removed, nothing added
            prev = new List <ItemInfo>
            {
                new ItemInfo {
                    GUID = 1, Class = 1
                },
            };
            curr = new List <ItemInfo>
            {
            };
            res = DiffUtil.ItemsDiff(curr, prev);
            Assert.IsNull(res.Item1);
            CollectionAssert.AreEquivalent(prev, res.Item2);
        }