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)); }
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", "!" })); }
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"))); }
public void TestAdd() { serverSyncDictionary.Add(4, "yay"); SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary); Assert.That(clientSyncDictionary.ContainsKey(4)); Assert.That(clientSyncDictionary[4], Is.EqualTo("yay")); }
public void TestNullSet() { serverSyncDictionary[1] = null; SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary); Assert.That(clientSyncDictionary.ContainsKey(1)); Assert.That(clientSyncDictionary[1], Is.Null); }
public void TestSet() { serverSyncDictionary[1] = "yay"; SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary); Assert.That(clientSyncDictionary.ContainsKey(1)); Assert.That(clientSyncDictionary[1], Is.EqualTo("yay")); }
public void TestConsecutiveSet() { serverSyncDictionary[1] = "yay"; serverSyncDictionary[1] = "world"; SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary); Assert.That(clientSyncDictionary[1], Is.EqualTo("world")); }
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); }
public void TestIntersectWithSet() { serverSyncSet.IntersectWith(new HashSet <string> { "World", "Hello" }); SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet); Assert.That(clientSyncSet, Is.EquivalentTo(new[] { "World", "Hello" })); }
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); }
public void TestUnionWith() { serverSyncSet.UnionWith(new HashSet <string> { "Hello", "is" }); SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet); Assert.That(clientSyncSet, Is.EquivalentTo(new[] { "World", "Hello", "is", "!" })); }
public void RemoveClientCallbackTest() { var callback = Substitute.For <Action <string> >(); clientSyncSet.OnRemove += callback; serverSyncSet.Remove("World"); SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet); callback.Received().Invoke("World"); }
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"); }
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" })); }
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"); }
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"); }
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"); }
public void ClearClientCallbackTest() { Action callback = Substitute.For <Action>(); clientSyncDictionary.OnClear += callback; serverSyncDictionary.Clear(); SerializeHelper.SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary); callback.Received().Invoke(); }
public void AddClientCallbackTest() { var callback = Substitute.For <Action <string> >(); clientSyncSet.OnAdd += callback; serverSyncSet.Add("yay"); SerializeHelper.SerializeDeltaTo(serverSyncSet, clientSyncSet); callback.Received().Invoke("yay"); }
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"); }
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(); }
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(); }
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 })); }
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 })); }
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")); }
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 })); }
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 })); }
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); }
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); }
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); }