예제 #1
0
파일: YTestBase.cs 프로젝트: alex521/ycs
        internal void CompareStructStores(StructStore ss1, StructStore ss2)
        {
            Assert.AreEqual(ss1.Clients.Count, ss2.Clients.Count);

            foreach (var kvp in ss1.Clients)
            {
                var client   = kvp.Key;
                var structs1 = kvp.Value;

                Assert.IsTrue(ss2.Clients.TryGetValue(client, out var structs2));
                Assert.AreEqual(structs1.Count, structs2.Count);

                for (int i = 0; i < structs1.Count; i++)
                {
                    var s1 = structs1[i];
                    var s2 = structs2[i];

                    // Checks for abstract struct.
                    if (!s1.GetType().IsAssignableFrom(s2.GetType()) ||
                        !ID.Equals(s1.Id, s2.Id) ||
                        s1.Deleted != s2.Deleted ||
                        s1.Length != s2.Length)
                    {
                        Assert.Fail("Structs don't match");
                    }

                    if (s1 is Item s1Item)
                    {
                        if (!(s2 is Item s2Item) ||
                            !((s1Item.Left == null && s2Item.Left == null) || (s1Item.Left != null && s2Item.Left != null && ID.Equals((s1Item.Left as Item)?.LastId, (s2Item.Left as Item)?.LastId))) ||
                            !CompareItemIds(s1Item.Right as Item, s2Item.Right as Item) ||
                            !ID.Equals(s1Item.LeftOrigin, s2Item.LeftOrigin) ||
                            !ID.Equals(s1Item.RightOrigin, s2Item.RightOrigin) ||
                            !string.Equals(s1Item.ParentSub, s2Item.ParentSub))
                        {
                            Assert.Fail("Items don't match");
                        }

                        // Make sure that items are connected correctly.
                        Assert.IsTrue(s1Item.Left == null || (s1Item.Left as Item)?.Right == s1Item);
                        Assert.IsTrue(s1Item.Right == null || (s1Item.Right as Item)?.Left == s1Item);
                        Assert.IsTrue((s2 as Item).Left == null || ((s2 as Item).Left as Item).Right == s2);
                        Assert.IsTrue((s2 as Item).Right == null || ((s2 as Item).Right as Item).Left == s2);
                    }
                }
            }
        }