protected bool CompareItemIds(Item a, Item b) { var result = a == b || (a != null && b != null & ID.Equals(a.Id, b.Id)); Assert.IsTrue(result); return(result); }
public bool Equals(RelativePosition other) { if (ReferenceEquals(this, other)) { return(true); } return(other != null && string.Equals(TName, other.TName) && ID.Equals(Item, other.Item) && ID.Equals(TypeId, other.TypeId)); }
public void TestObserveDeepProperties() { Init(users: 4); var map0 = Maps[Users[0]]; var map1 = Maps[Users[1]]; var map2 = Maps[Users[2]]; var map3 = Maps[Users[3]]; var _map1 = new YMap(); map1.Set("map", _map1); int calls = 0; ID? dmapId = null; map1.DeepEventHandler += (s, e) => { foreach (var evt in e.Events) { calls++; Assert.IsTrue(evt.Changes.Keys.ContainsKey("deepmap")); Assert.AreEqual(1, evt.Path.Count); Assert.AreEqual("map", evt.Path.First()); dmapId = ((evt.Target as YMap).Get("deepmap") as YMap)._item?.Id; } }; Connector.FlushAllMessages(); var _map3 = map3.Get("map") as YMap; _map3.Set("deepmap", new YMap()); Connector.FlushAllMessages(); var _map2 = map2.Get("map") as YMap; _map2.Set("deepmap", new YMap()); Connector.FlushAllMessages(); var dmap1 = _map1.Get("deepmap") as YMap; var dmap2 = _map2.Get("deepmap") as YMap; var dmap3 = _map3.Get("deepmap") as YMap; Assert.IsTrue(calls > 0); Assert.IsTrue(ID.Equals(dmap1._item?.Id, dmap2._item?.Id)); Assert.IsTrue(ID.Equals(dmap1._item?.Id, dmap3._item?.Id)); Assert.IsTrue(ID.Equals(dmap1._item?.Id, dmapId)); CompareUsers(); }
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); } } } }