Beispiel #1
0
        public void TestYMapSetsYArray()
        {
            Init(users: 2);
            var map0 = Maps[Users[0]];

            var array = new YArray();

            map0.Set("array", array);
            Assert.AreEqual(array, map0.Get("array"));

            array.Insert(0, new object[] { 1, 2, 3 });
            CollectionAssert.AreEqual(new object[] { 1, 2, 3 }, (ICollection)(map0.Get("array") as YArray).ToArray());

            CompareUsers();
        }
Beispiel #2
0
        protected void CompareYArray(YArray arr1, YArray arr2)
        {
            if (ReferenceEquals(arr1, arr2))
            {
                return;
            }

            Assert.IsTrue((arr1 == null) == (arr2 == null));
            Assert.AreEqual(arr1.Length, arr1.Length);

            for (int i = 0; i < arr1.Length; i++)
            {
                CompareObjects(arr1.Get(i), arr2.Get(i));
            }
        }
Beispiel #3
0
        internal static ContentType Read(IUpdateDecoder decoder)
        {
            var typeRef = decoder.ReadTypeRef();

            switch (typeRef)
            {
            case YArray.YArrayRefId:
                var arr = YArray.Read(decoder);
                return(new ContentType(arr));

            case YMap.YMapRefId:
                var map = YMap.Read(decoder);
                return(new ContentType(map));

            case YText.YTextRefId:
                var text = YText.Read(decoder);
                return(new ContentType(text));

            default:
                throw new NotImplementedException($"Type {typeRef} not implemented");
            }
        }
Beispiel #4
0
        public void TestChangeEvent()
        {
            Init(users: 2);

            var array0 = Arrays[Users[0]];
            ChangesCollection changes = null;

            array0.EventHandler += (s, e) =>
            {
                changes = e.Event.Changes;
            };

            var newArr = new YArray();

            array0.Insert(0, new object[] { newArr, 4, "dtrn" });
            Assert.IsNotNull(changes);
            Assert.AreEqual(2, changes.Added.Count);
            Assert.AreEqual(0, changes.Deleted.Count);
            Assert.AreEqual(1, changes.Delta.Count);
            CollectionAssert.AreEqual(new object[] { newArr, 4, "dtrn" }, (ICollection)changes.Delta[0].Insert);
            changes = null;

            array0.Delete(0, 2);
            Assert.IsNotNull(changes);
            Assert.AreEqual(0, changes.Added.Count);
            Assert.AreEqual(2, changes.Deleted.Count);
            Assert.AreEqual(2, changes.Delta[0].Delete);
            changes = null;

            array0.Insert(1, new object[] { 0.1 });
            Assert.IsNotNull(changes);
            Assert.AreEqual(1, changes.Added.Count);
            Assert.AreEqual(0, changes.Deleted.Count);
            Assert.AreEqual(2, changes.Delta.Count);
            Assert.AreEqual(1, changes.Delta[0].Retain);
            CollectionAssert.AreEqual(new object[] { 0.1 }, (ICollection)changes.Delta[1].Insert);

            CompareUsers();
        }
Beispiel #5
0
 internal YArrayEvent(YArray arr, Transaction transaction)
     : base(arr, transaction)
 {
     // Do nothing.
 }