chore(SyncDictionaryTest): Improved tests

This commit is contained in:
MrGadget 2024-03-21 10:53:42 -04:00
parent 0b8b11e78f
commit 05d68f91af

View File

@ -79,6 +79,7 @@ public void CurlyBracesConstructor()
[Test] [Test]
public void TestAdd() public void TestAdd()
{ {
// Adds a new entry with index of 4 using .Add method
serverSyncDictionary.Add(4, "yay"); serverSyncDictionary.Add(4, "yay");
SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary); SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
Assert.That(clientSyncDictionary.ContainsKey(4)); Assert.That(clientSyncDictionary.ContainsKey(4));
@ -96,19 +97,45 @@ public void TestClear()
[Test] [Test]
public void TestSet() public void TestSet()
{ {
// Overwrites an existing entry
bool called = false;
clientSyncDictionary.Callback = (op, index, item) =>
{
called = true;
Assert.That(op, Is.EqualTo(SyncDictionary<int, string>.Operation.OP_SET));
Assert.That(index, Is.EqualTo(1));
Assert.That(item, Is.EqualTo("yay"));
Assert.That(clientSyncDictionary[index], Is.EqualTo("yay"));
};
serverSyncDictionary[1] = "yay"; serverSyncDictionary[1] = "yay";
SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary); SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
Assert.That(clientSyncDictionary.ContainsKey(1)); Assert.That(clientSyncDictionary.ContainsKey(1));
Assert.That(clientSyncDictionary[1], Is.EqualTo("yay")); Assert.That(clientSyncDictionary[1], Is.EqualTo("yay"));
Assert.That(called, Is.True);
} }
[Test] [Test]
public void TestBareSet() public void TestBareSet()
{ {
// Adds a new entry with index of 4 without using .Add method
bool called = false;
clientSyncDictionary.Callback = (op, index, item) =>
{
called = true;
Assert.That(op, Is.EqualTo(SyncDictionary<int, string>.Operation.OP_ADD));
Assert.That(index, Is.EqualTo(4));
Assert.That(item, Is.EqualTo("yay"));
Assert.That(clientSyncDictionary[index], Is.EqualTo("yay"));
};
serverSyncDictionary[4] = "yay"; serverSyncDictionary[4] = "yay";
SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary); SerializeDeltaTo(serverSyncDictionary, clientSyncDictionary);
Assert.That(clientSyncDictionary.ContainsKey(4)); Assert.That(clientSyncDictionary.ContainsKey(4));
Assert.That(clientSyncDictionary[4], Is.EqualTo("yay")); Assert.That(clientSyncDictionary[4], Is.EqualTo("yay"));
Assert.That(called, Is.True);
} }
[Test] [Test]
@ -173,7 +200,7 @@ public void TestContains()
public void CallbackTest() public void CallbackTest()
{ {
bool called = false; bool called = false;
clientSyncDictionary.Callback += (op, index, item) => clientSyncDictionary.Callback = (op, index, item) =>
{ {
called = true; called = true;
@ -192,7 +219,7 @@ public void CallbackTest()
public void ServerCallbackTest() public void ServerCallbackTest()
{ {
bool called = false; bool called = false;
serverSyncDictionary.Callback += (op, index, item) => serverSyncDictionary.Callback = (op, index, item) =>
{ {
called = true; called = true;
@ -209,7 +236,7 @@ public void ServerCallbackTest()
public void CallbackRemoveTest() public void CallbackRemoveTest()
{ {
bool called = false; bool called = false;
clientSyncDictionary.Callback += (op, key, item) => clientSyncDictionary.Callback = (op, key, item) =>
{ {
called = true; called = true;
Assert.That(op, Is.EqualTo(SyncDictionary<int, string>.Operation.OP_REMOVE)); Assert.That(op, Is.EqualTo(SyncDictionary<int, string>.Operation.OP_REMOVE));