From 9378fe7db3f474ce6207002e7e233b37c0bbb74d Mon Sep 17 00:00:00 2001 From: Karim Rizk Date: Mon, 25 Dec 2023 13:28:16 +0200 Subject: [PATCH] Update dictionary serialization test --- .../DictionarySerializationTest.cs | 36 ++++++------------- ...mpleCustomType.cs => SampleCustomClass.cs} | 10 +++--- 2 files changed, 15 insertions(+), 31 deletions(-) rename NebulaTests/NebulaModel/Networking/Serialization/{SampleCustomType.cs => SampleCustomClass.cs} (75%) diff --git a/NebulaTests/NebulaModel/Networking/Serialization/DictionarySerializationTest.cs b/NebulaTests/NebulaModel/Networking/Serialization/DictionarySerializationTest.cs index dc83ed0b7..f82a823f3 100644 --- a/NebulaTests/NebulaModel/Networking/Serialization/DictionarySerializationTest.cs +++ b/NebulaTests/NebulaModel/Networking/Serialization/DictionarySerializationTest.cs @@ -8,11 +8,9 @@ public class SampleDictionaryPacket { public Dictionary SampleInts { get; set; } = new(); - public Dictionary SampleCustomTypes { get; set; } = new(); + public Dictionary SampleCustomTypes { get; set; } = new(); + public Dictionary SampleNetSerializables { get; set; } = new(); - public Dictionary SampleNetSerializableClasses { get; set; } = new(); - - public Dictionary SampleNetSerializableStructs { get; set; } = new(); // This is the one used by Assert.AreEqual, we don't need to implement the rest for now. public override bool Equals(object? obj) @@ -35,14 +33,6 @@ public override bool Equals(object? obj) return false; } - foreach (var kvp in SampleNetSerializableStructs) - { - if (!other.SampleNetSerializableStructs.ContainsKey(kvp.Key)) - return false; - if (other.SampleNetSerializableStructs[kvp.Key] != SampleNetSerializableStructs[kvp.Key]) - return false; - } - return true; } } @@ -56,23 +46,17 @@ public class DictionarySerializationTest SampleCustomTypes = new() { - { new SampleCustomType { Value = 1 }, new SampleCustomType { Value = 1 } }, - { new SampleCustomType { Value = 2 }, new SampleCustomType { Value = 2 } }, - { new SampleCustomType { Value = 3 }, new SampleCustomType { Value = 3 } } + { new SampleCustomClass { Value = 1 }, new SampleCustomClass() { Value = 2 } }, + { new SampleCustomClass { Value = 3 }, new SampleCustomClass() { Value = 4 } }, + { new SampleCustomClass { Value = 5 }, new SampleCustomClass() { Value = 6 } } }, - SampleNetSerializableClasses = + SampleNetSerializables = new() { - { new SampleNetSerializableClass { value = 1 }, new SampleNetSerializableClass { value = 1 } }, - { new SampleNetSerializableClass { value = 2 }, new SampleNetSerializableClass { value = 2 } }, - { new SampleNetSerializableClass { value = 3 }, new SampleNetSerializableClass { value = 3 } }, - }, - SampleNetSerializableStructs = new() - { - { new SampleNetSerializableStruct { value = 1 }, new SampleNetSerializableStruct { value = 1 } }, - { new SampleNetSerializableStruct { value = 2 }, new SampleNetSerializableStruct { value = 2 } }, - { new SampleNetSerializableStruct { value = 3 }, new SampleNetSerializableStruct { value = 3 } }, - } + { new SampleNetSerializableClass { value = 1 }, new SampleNetSerializableStruct { value = 1 } }, + { new SampleNetSerializableClass { value = 2 }, new SampleNetSerializableStruct { value = 2 } }, + { new SampleNetSerializableClass { value = 3 }, new SampleNetSerializableStruct { value = 3 } }, + } }; [TestMethod, Timeout(1000)] diff --git a/NebulaTests/NebulaModel/Networking/Serialization/SampleCustomType.cs b/NebulaTests/NebulaModel/Networking/Serialization/SampleCustomClass.cs similarity index 75% rename from NebulaTests/NebulaModel/Networking/Serialization/SampleCustomType.cs rename to NebulaTests/NebulaModel/Networking/Serialization/SampleCustomClass.cs index ceb816ab8..22a208206 100644 --- a/NebulaTests/NebulaModel/Networking/Serialization/SampleCustomType.cs +++ b/NebulaTests/NebulaModel/Networking/Serialization/SampleCustomClass.cs @@ -1,10 +1,10 @@ namespace NebulaTests.NebulaModel.Networking.Serialization; -public class SampleCustomType : IEquatable +public class SampleCustomClass : IEquatable { public int Value { get; set; } - public bool Equals(SampleCustomType? other) + public bool Equals(SampleCustomClass? other) { if (ReferenceEquals(null, other)) { @@ -36,7 +36,7 @@ public override bool Equals(object? obj) return false; } - return Equals((SampleCustomType)obj); + return Equals((SampleCustomClass)obj); } public override int GetHashCode() @@ -44,7 +44,7 @@ public override int GetHashCode() return Value; } - public static bool operator ==(SampleCustomType lhs, SampleCustomType rhs) + public static bool operator ==(SampleCustomClass lhs, SampleCustomClass rhs) { if (lhs is null) { @@ -60,5 +60,5 @@ public override int GetHashCode() return lhs.Equals(rhs); } - public static bool operator !=(SampleCustomType lhs, SampleCustomType rhs) => !(lhs == rhs); + public static bool operator !=(SampleCustomClass lhs, SampleCustomClass rhs) => !(lhs == rhs); } \ No newline at end of file