Beispiel #1
0
        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();
        }
Beispiel #2
0
        public void TestYMapSetsYMap()
        {
            Init(users: 2);
            var map0 = Maps[Users[0]];
            var map  = new YMap();

            map0.Set("map", map);

            Assert.AreEqual(map, map0.Get("map"));
            map.Set("one", 1);
            Assert.AreEqual(1, map.Get("one"));

            CompareUsers();
        }
Beispiel #3
0
        public void TestMapHavingIterableAsConstructorParamTests()
        {
            Init(users: 1);
            var map0 = Maps[Users[0]];

            var m1 = new YMap(new Dictionary <string, object> {
                { "number", 1 }, { "string", "hello" }
            });

            map0.Set("m1", m1);
            Assert.AreEqual(1, m1.Get("number"));
            Assert.AreEqual("hello", m1.Get("string"));

            var obj = new object[] { 1 };
            var m2  = new YMap(new Dictionary <string, object> {
                { "object", obj }, { "boolean", true }
            });

            map0.Set("m2", m2);
            Assert.AreEqual(obj, m2.Get("object"));
            Assert.AreEqual(true, m2.Get("boolean"));

            CompareUsers();
        }
Beispiel #4
0
        protected void CompareYMap(YMap map1, YMap map2)
        {
            if (ReferenceEquals(map1, map2))
            {
                return;
            }

            Assert.IsTrue((map1 == null) == (map2 == null));
            Assert.AreEqual(map1.Count, map2.Count);

            foreach (var key1 in map1.Keys())
            {
                Assert.IsTrue(map2.ContainsKey(key1));
                CompareObjects(map1.Get(key1), map2.Get(key1));
            }
        }