Esempio n. 1
0
        public void ClearShouldClearAll()
        {
            var serverList = new SyncList <TestObject>();
            var clientList = new SyncList <TestObject>();

            SerializeHelper.SerializeAllTo(serverList, clientList);

            // add some items
            var item1 = new TestObject {
                id = 1, text = "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nostrum ullam aliquid perferendis, aut nihil sunt quod ipsum corporis a. Cupiditate, alias. Commodi, molestiae distinctio repellendus dolor similique delectus inventore eum."
            };

            serverList.Add(item1);
            var item2 = new TestObject {
                id = 2, text = "Lorem ipsum dolor sit, amet consectetur adipisicing elit. Nostrum ullam aliquid perferendis, aut nihil sunt quod ipsum corporis a. Cupiditate, alias. Commodi, molestiae distinctio repellendus dolor similique delectus inventore eum."
            };

            serverList.Add(item2);

            // sync
            SerializeHelper.SerializeDeltaTo(serverList, clientList);

            // clear all items
            serverList.Clear();

            // sync
            SerializeHelper.SerializeDeltaTo(serverList, clientList);

            Assert.That(clientList.Count, Is.Zero);

            Assert.IsFalse(clientList.Any(x => x.id == item1.id));
            Assert.IsFalse(clientList.Any(x => x.id == item2.id));
        }
Esempio n. 2
0
 public void TestSet()
 {
     serverSyncList[1] = "yay";
     SerializeHelper.SerializeDeltaTo(serverSyncList, clientSyncList);
     Assert.That(clientSyncList[1], Is.EqualTo("yay"));
     Assert.That(clientSyncList, Is.EquivalentTo(new[] { "Hello", "yay", "!" }));
 }
Esempio n. 3
0
 public void TestContains()
 {
     Assert.That(!clientSyncDictionary.Contains(new KeyValuePair <int, string>(2, "Hello")));
     serverSyncDictionary[2] = "Hello";
     SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
     Assert.That(clientSyncDictionary.Contains(new KeyValuePair <int, string>(2, "Hello")));
 }
Esempio n. 4
0
 public void TestAdd()
 {
     serverSyncDictionary.Add(4, "yay");
     SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
     Assert.That(clientSyncDictionary.ContainsKey(4));
     Assert.That(clientSyncDictionary[4], Is.EqualTo("yay"));
 }
Esempio n. 5
0
 public void TestNullSet()
 {
     serverSyncDictionary[1] = null;
     SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
     Assert.That(clientSyncDictionary.ContainsKey(1));
     Assert.That(clientSyncDictionary[1], Is.Null);
 }
Esempio n. 6
0
 public void TestSet()
 {
     serverSyncDictionary[1] = "yay";
     SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
     Assert.That(clientSyncDictionary.ContainsKey(1));
     Assert.That(clientSyncDictionary[1], Is.EqualTo("yay"));
 }
Esempio n. 7
0
 public void TestConsecutiveSet()
 {
     serverSyncDictionary[1] = "yay";
     serverSyncDictionary[1] = "world";
     SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
     Assert.That(clientSyncDictionary[1], Is.EqualTo("world"));
 }
Esempio n. 8
0
 public void TestRemove()
 {
     serverSyncSet.Remove("World");
     Assert.That(serverSyncSet.IsDirty, Is.True);
     SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet);
     Assert.That(clientSyncSet, Is.EquivalentTo(new[] { "Hello", "!" }));
     Assert.That(serverSyncSet.IsDirty, Is.False);
 }
Esempio n. 9
0
 public void TestIntersectWithSet()
 {
     serverSyncSet.IntersectWith(new HashSet <string> {
         "World", "Hello"
     });
     SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet);
     Assert.That(clientSyncSet, Is.EquivalentTo(new[] { "World", "Hello" }));
 }
Esempio n. 10
0
 public void TestClear()
 {
     serverSyncSet.Clear();
     Assert.That(serverSyncSet.IsDirty, Is.True);
     SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet);
     Assert.That(clientSyncSet, Is.EquivalentTo(new string[] { }));
     Assert.That(serverSyncSet.IsDirty, Is.False);
 }
Esempio n. 11
0
 public void TestUnionWith()
 {
     serverSyncSet.UnionWith(new HashSet <string> {
         "Hello", "is"
     });
     SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet);
     Assert.That(clientSyncSet, Is.EquivalentTo(new[] { "World", "Hello", "is", "!" }));
 }
Esempio n. 12
0
        public void RemoveClientCallbackTest()
        {
            var callback = Substitute.For <Action <string> >();

            clientSyncSet.OnRemove += callback;
            serverSyncSet.Remove("World");
            SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet);
            callback.Received().Invoke("World");
        }
Esempio n. 13
0
        public void SetClientCallbackTest()
        {
            var callback = Substitute.For <Action <int, string, string> >();

            clientSyncList.OnSet += callback;
            serverSyncList[1]     = "yo mama";
            SerializeHelper.SerializeDeltaTo(serverSyncList, clientSyncList);
            callback.Received().Invoke(1, "World", "yo mama");
        }
Esempio n. 14
0
 public void TestMultSync()
 {
     serverSyncSet.Add("1");
     SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet);
     // add some delta and see if it applies
     serverSyncSet.Add("2");
     SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet);
     Assert.That(clientSyncSet, Is.EquivalentTo(new[] { "Hello", "World", "!", "1", "2" }));
 }
Esempio n. 15
0
        public void InsertClientCallbackTest()
        {
            var callback = Substitute.For <Action <int, string> >();

            clientSyncList.OnInsert += callback;
            serverSyncList.Insert(1, "yay");
            SerializeHelper.SerializeDeltaTo(serverSyncList, clientSyncList);
            callback.Received().Invoke(1, "yay");
        }
Esempio n. 16
0
        public void RemoveClientCallbackTest()
        {
            Action <int, string> callback = Substitute.For <Action <int, string> >();

            clientSyncDictionary.OnRemove += callback;
            serverSyncDictionary.Remove(1);
            SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
            callback.Received().Invoke(1, "World");
        }
Esempio n. 17
0
        public void SetClientCallbackTest()
        {
            Action <int, string, string> callback = Substitute.For <Action <int, string, string> >();

            clientSyncDictionary.OnSet += callback;
            serverSyncDictionary[0]     = "yay";
            SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
            callback.Received().Invoke(0, "Hello", "yay");
        }
Esempio n. 18
0
        public void ClearClientCallbackTest()
        {
            Action callback = Substitute.For <Action>();

            clientSyncDictionary.OnClear += callback;
            serverSyncDictionary.Clear();
            SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
            callback.Received().Invoke();
        }
Esempio n. 19
0
        public void AddClientCallbackTest()
        {
            var callback = Substitute.For <Action <string> >();

            clientSyncSet.OnAdd += callback;
            serverSyncSet.Add("yay");
            SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet);
            callback.Received().Invoke("yay");
        }
Esempio n. 20
0
        public void AddServerCallbackTest()
        {
            Action <int, string> callback = Substitute.For <Action <int, string> >();

            serverSyncDictionary.OnInsert += callback;
            serverSyncDictionary.Add(3, "yay");
            SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
            callback.Received().Invoke(3, "yay");
        }
Esempio n. 21
0
        public void ChangeClientCallbackTest()
        {
            Action callback = Substitute.For <Action>();

            clientSyncDictionary.OnChange += callback;
            serverSyncDictionary.Add(3, "1");
            serverSyncDictionary.Add(4, "1");
            SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
            callback.Received(1).Invoke();
        }
Esempio n. 22
0
        public void ChangeClientCallbackTest()
        {
            var callback = Substitute.For <Action>();

            clientSyncSet.OnChange += callback;
            serverSyncSet.Add("1");
            serverSyncSet.Add("2");
            SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet);
            callback.Received(1).Invoke();
        }
Esempio n. 23
0
        public void SyncListBoolTest()
        {
            var serverList = new SyncList <bool>();
            var clientList = new SyncList <bool>();

            serverList.Add(true);
            serverList.Add(false);
            serverList.Add(true);
            SerializeHelper.SerializeDeltaTo(serverList, clientList);

            Assert.That(clientList, Is.EquivalentTo(new[] { true, false, true }));
        }
Esempio n. 24
0
        public void SyncListFloatTest()
        {
            var serverList = new SyncList <float>();
            var clientList = new SyncList <float>();

            serverList.Add(1.0F);
            serverList.Add(2.0F);
            serverList.Add(3.0F);
            SerializeHelper.SerializeDeltaTo(serverList, clientList);

            Assert.That(clientList, Is.EquivalentTo(new[] { 1.0F, 2.0F, 3.0F }));
        }
Esempio n. 25
0
 public void TestMultSync()
 {
     serverSyncDictionary.Add(10, "1");
     SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
     // add some delta and see if it applies
     serverSyncDictionary.Add(11, "2");
     SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
     Assert.That(clientSyncDictionary.ContainsKey(10));
     Assert.That(clientSyncDictionary[10], Is.EqualTo("1"));
     Assert.That(clientSyncDictionary.ContainsKey(11));
     Assert.That(clientSyncDictionary[11], Is.EqualTo("2"));
 }
Esempio n. 26
0
        public void SyncListUIntTest()
        {
            var serverList = new SyncList <uint>();
            var clientList = new SyncList <uint>();

            serverList.Add(1U);
            serverList.Add(2U);
            serverList.Add(3U);
            SerializeHelper.SerializeDeltaTo(serverList, clientList);

            Assert.That(clientList, Is.EquivalentTo(new[] { 1U, 2U, 3U }));
        }
Esempio n. 27
0
        public void SyncListIntest()
        {
            var serverList = new SyncList <int>();
            var clientList = new SyncList <int>();

            serverList.Add(1);
            serverList.Add(2);
            serverList.Add(3);
            SerializeHelper.SerializeDeltaTo(serverList, clientList);

            Assert.That(clientList, Is.EquivalentTo(new[] { 1, 2, 3 }));
        }
Esempio n. 28
0
        public void ObjectCanBeReusedAfterReset()
        {
            clientSyncDictionary.Reset();

            // make old client the host
            SyncDictionaryIntString hostList = clientSyncDictionary;
            var clientList2 = new SyncDictionaryIntString();

            Assert.That(hostList.IsReadOnly, Is.False);

            // Check Add and Sync without errors
            hostList.Add(30, "hello");
            hostList.Add(35, "world");
            SerializeHelper.SerializeDeltaTo(hostList, clientList2);
        }
Esempio n. 29
0
        public void ObjectCanBeReusedAfterReset()
        {
            clientSyncList.Reset();

            // make old client the host
            var hostList    = clientSyncList;
            var clientList2 = new SyncList <string>();

            Assert.That(hostList.IsReadOnly, Is.False);

            // Check Add and Sync without errors
            hostList.Add("hello");
            hostList.Add("world");
            SerializeHelper.SerializeDeltaTo(hostList, clientList2);
        }
Esempio n. 30
0
        public void DirtyTest()
        {
            // Sync Delta to clear dirty
            SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);

            // nothing to send
            Assert.That(serverSyncDictionary.IsDirty, Is.False);

            // something has changed
            serverSyncDictionary.Add(15, "yay");
            Assert.That(serverSyncDictionary.IsDirty, Is.True);
            SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);

            // data has been flushed,  should go back to clear
            Assert.That(serverSyncDictionary.IsDirty, Is.False);
        }