chore(Tests): Improved Sync Collection tests

This commit is contained in:
MrGadget 2024-09-20 01:32:08 -04:00
parent 264737302a
commit 049c8e1486
3 changed files with 14 additions and 6 deletions

View File

@ -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]

View File

@ -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<string>.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]

View File

@ -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<string>.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<string>.Operation.OP_REMOVE));
Assert.That(item, Is.EqualTo("World"));
Assert.That(oldItem, Is.EqualTo("World"));
};
serverSyncSet.Remove("World");