From 8cf164055ba6d1f7c5c26f61f01846716f22f3e4 Mon Sep 17 00:00:00 2001 From: MrGadget <9826063+MrGadget1024@users.noreply.github.com> Date: Fri, 20 Sep 2024 01:32:08 -0400 Subject: [PATCH] chore(Tests): Improved Sync Collection tests --- .../Tests/Editor/SyncCollections/SyncDictionaryTest.cs | 2 ++ .../Tests/Editor/SyncCollections/SyncListTest.cs | 8 ++++++-- .../Mirror/Tests/Editor/SyncCollections/SyncSetTest.cs | 10 ++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Assets/Mirror/Tests/Editor/SyncCollections/SyncDictionaryTest.cs b/Assets/Mirror/Tests/Editor/SyncCollections/SyncDictionaryTest.cs index 6aaec21fa..da0ebecdc 100644 --- a/Assets/Mirror/Tests/Editor/SyncCollections/SyncDictionaryTest.cs +++ b/Assets/Mirror/Tests/Editor/SyncCollections/SyncDictionaryTest.cs @@ -463,11 +463,13 @@ public void DirtyTest() // nothing to send Assert.That(serverSyncDictionaryDirtyCalled, Is.EqualTo(0)); + Assert.That(clientSyncDictionaryDirtyCalled, Is.EqualTo(0)); // something has changed serverSyncDictionary.Add(15, "yay"); Assert.That(serverSyncDictionaryDirtyCalled, Is.EqualTo(1)); SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary); + Assert.That(clientSyncDictionaryDirtyCalled, Is.EqualTo(1)); } [Test] diff --git a/Assets/Mirror/Tests/Editor/SyncCollections/SyncListTest.cs b/Assets/Mirror/Tests/Editor/SyncCollections/SyncListTest.cs index c87da8cc4..845865387 100644 --- a/Assets/Mirror/Tests/Editor/SyncCollections/SyncListTest.cs +++ b/Assets/Mirror/Tests/Editor/SyncCollections/SyncListTest.cs @@ -464,12 +464,13 @@ public void CallbackTest() }; bool changeActionCalled = false; - clientSyncList.OnChange = (op, index, oldItem) => + clientSyncList.OnChange = (op, index, newItem) => { changeActionCalled = true; Assert.That(op, Is.EqualTo(SyncList.Operation.OP_ADD)); Assert.That(index, Is.EqualTo(3)); - Assert.That(oldItem, Is.EqualTo("yay")); + Assert.That(newItem, Is.EqualTo("yay")); + Assert.That(clientSyncList[index], Is.EqualTo("yay")); }; serverSyncList.Add("yay"); @@ -581,15 +582,18 @@ public void DirtyTest() { // Sync Delta to clear dirty Assert.That(serverSyncListDirtyCalled, Is.EqualTo(0)); + Assert.That(clientSyncListDirtyCalled, Is.EqualTo(0)); SerializeDeltaTo(serverSyncList, clientSyncList); // nothing to send Assert.That(serverSyncListDirtyCalled, Is.EqualTo(0)); + Assert.That(clientSyncListDirtyCalled, Is.EqualTo(0)); // something has changed serverSyncList.Add("1"); Assert.That(serverSyncListDirtyCalled, Is.EqualTo(1)); SerializeDeltaTo(serverSyncList, clientSyncList); + Assert.That(clientSyncListDirtyCalled, Is.EqualTo(1)); } [Test] diff --git a/Assets/Mirror/Tests/Editor/SyncCollections/SyncSetTest.cs b/Assets/Mirror/Tests/Editor/SyncCollections/SyncSetTest.cs index 6c56ed9bc..5fdb10122 100644 --- a/Assets/Mirror/Tests/Editor/SyncCollections/SyncSetTest.cs +++ b/Assets/Mirror/Tests/Editor/SyncCollections/SyncSetTest.cs @@ -77,6 +77,7 @@ public void TestAdd() Assert.That(serverSyncSetDirtyCalled, Is.EqualTo(1)); SerializeDeltaTo(serverSyncSet, clientSyncSet); Assert.That(clientSyncSet, Is.EquivalentTo(new[] { "Hello", "World", "!", "yay" })); + Assert.That(clientSyncSetDirtyCalled, Is.EqualTo(1)); } [Test] @@ -86,6 +87,7 @@ public void TestRemove() Assert.That(serverSyncSetDirtyCalled, Is.EqualTo(1)); SerializeDeltaTo(serverSyncSet, clientSyncSet); Assert.That(clientSyncSet, Is.EquivalentTo(new[] { "Hello", "!" })); + Assert.That(clientSyncSetDirtyCalled, Is.EqualTo(1)); } [Test] @@ -158,11 +160,11 @@ public void CallbackTest() }; bool changeActionCalled = false; - clientSyncSet.OnChange = (op, item) => + clientSyncSet.OnChange = (op, newItem) => { changeActionCalled = true; Assert.That(op, Is.EqualTo(SyncHashSet.Operation.OP_ADD)); - Assert.That(item, Is.EqualTo("yay")); + Assert.That(newItem, Is.EqualTo("yay")); }; serverSyncSet.Add("yay"); @@ -194,11 +196,11 @@ public void CallbackRemoveTest() }; bool changeActionCalled = false; - clientSyncSet.OnChange = (op, item) => + clientSyncSet.OnChange = (op, oldItem) => { changeActionCalled = true; Assert.That(op, Is.EqualTo(SyncHashSet.Operation.OP_REMOVE)); - Assert.That(item, Is.EqualTo("World")); + Assert.That(oldItem, Is.EqualTo("World")); }; serverSyncSet.Remove("World");