From a2124c35223151a3108cc3c380a85acfb2a207a6 Mon Sep 17 00:00:00 2001 From: James Frowen Date: Wed, 19 Aug 2020 02:18:20 +0100 Subject: [PATCH] Renaming tests and namespaces (#2167) * renaming test * renaming test file * removing test suffix from methods * changing test namesapce --- .../{MessageTests.cs => BuiltInMessages.cs} | 40 +++++----- ...eTests.cs.meta => BuiltInMessages.cs.meta} | 0 .../Mirror/Tests/Editor/MessageBaseTests.cs | 21 +++--- .../Tests/Editor/MessageInheritanceTest.cs | 2 +- .../Mirror/Tests/Editor/NetworkServerTest.cs | 73 ++++++++++++++----- 5 files changed, 88 insertions(+), 48 deletions(-) rename Assets/Mirror/Tests/Editor/{MessageTests.cs => BuiltInMessages.cs} (92%) rename Assets/Mirror/Tests/Editor/{MessageTests.cs.meta => BuiltInMessages.cs.meta} (100%) diff --git a/Assets/Mirror/Tests/Editor/MessageTests.cs b/Assets/Mirror/Tests/Editor/BuiltInMessages.cs similarity index 92% rename from Assets/Mirror/Tests/Editor/MessageTests.cs rename to Assets/Mirror/Tests/Editor/BuiltInMessages.cs index e9a6a66d6..68a5ed1da 100644 --- a/Assets/Mirror/Tests/Editor/MessageTests.cs +++ b/Assets/Mirror/Tests/Editor/BuiltInMessages.cs @@ -1,13 +1,13 @@ -using System; +using System; using NUnit.Framework; -namespace Mirror.Tests +namespace Mirror.Tests.MessageTests { [TestFixture] - public class MessageTests + public class BuiltInMessages { [Test] - public void CommandMessageTest() + public void CommandMessage() { // try setting value with constructor CommandMessage message = new CommandMessage @@ -31,7 +31,7 @@ public void CommandMessageTest() } [Test] - public void ConnectMessageTest() + public void ConnectMessage() { // try setting value with constructor ConnectMessage message = new ConnectMessage(); @@ -43,7 +43,7 @@ public void ConnectMessageTest() } [Test] - public void DisconnectMessageTest() + public void DisconnectMessage() { // try setting value with constructor DisconnectMessage message = new DisconnectMessage(); @@ -55,7 +55,7 @@ public void DisconnectMessageTest() } [Test] - public void ErrorMessageTest() + public void ErrorMessage() { // try setting value with constructor ErrorMessage message = new ErrorMessage(42); @@ -65,7 +65,7 @@ public void ErrorMessageTest() } [Test] - public void NetworkPingMessageTest() + public void NetworkPingMessage() { // try setting value with constructor NetworkPingMessage message = new NetworkPingMessage(DateTime.Now.ToOADate()); @@ -75,7 +75,7 @@ public void NetworkPingMessageTest() } [Test] - public void NetworkPongMessageTest() + public void NetworkPongMessage() { // try setting value with constructor NetworkPongMessage message = new NetworkPongMessage @@ -90,7 +90,7 @@ public void NetworkPongMessageTest() } [Test] - public void NotReadyMessageTest() + public void NotReadyMessage() { // try setting value with constructor NotReadyMessage message = new NotReadyMessage(); @@ -102,7 +102,7 @@ public void NotReadyMessageTest() } [Test] - public void ObjectDestroyMessageTest() + public void ObjectDestroyMessage() { // try setting value with constructor ObjectDestroyMessage message = new ObjectDestroyMessage @@ -115,7 +115,7 @@ public void ObjectDestroyMessageTest() } [Test] - public void ObjectHideMessageTest() + public void ObjectHideMessage() { // try setting value with constructor ObjectHideMessage message = new ObjectHideMessage @@ -128,7 +128,7 @@ public void ObjectHideMessageTest() } [Test] - public void ObjectSpawnFinishedMessageTest() + public void ObjectSpawnFinishedMessage() { // try setting value with constructor ObjectSpawnFinishedMessage message = new ObjectSpawnFinishedMessage(); @@ -140,7 +140,7 @@ public void ObjectSpawnFinishedMessageTest() } [Test] - public void ObjectSpawnStartedMessageTest() + public void ObjectSpawnStartedMessage() { // try setting value with constructor ObjectSpawnStartedMessage message = new ObjectSpawnStartedMessage(); @@ -152,7 +152,7 @@ public void ObjectSpawnStartedMessageTest() } [Test] - public void ReadyMessageTest() + public void ReadyMessage() { // try setting value with constructor ReadyMessage message = new ReadyMessage(); @@ -165,7 +165,7 @@ public void ReadyMessageTest() [Test] [Obsolete("RemovePlayerMessage is Obsolete")] - public void RemovePlayerMessageTest() + public void RemovePlayerMessage() { // try setting value with constructor RemovePlayerMessage message = new RemovePlayerMessage(); @@ -177,7 +177,7 @@ public void RemovePlayerMessageTest() } [Test] - public void RpcMessageTest() + public void RpcMessage() { // try setting value with constructor RpcMessage message = new RpcMessage @@ -199,7 +199,7 @@ public void RpcMessageTest() } [Test] - public void SpawnMessageTest() + public void SpawnMessage() { DoTest(0); DoTest(42); @@ -238,7 +238,7 @@ void DoTest(ulong testSceneId) } [Test] - public void SyncEventMessageTest() + public void SyncEventMessage() { // try setting value with constructor SyncEventMessage message = new SyncEventMessage @@ -261,7 +261,7 @@ public void SyncEventMessageTest() } [Test] - public void UpdateVarsMessageTest() + public void UpdateVarsMessage() { // try setting value with constructor UpdateVarsMessage message = new UpdateVarsMessage diff --git a/Assets/Mirror/Tests/Editor/MessageTests.cs.meta b/Assets/Mirror/Tests/Editor/BuiltInMessages.cs.meta similarity index 100% rename from Assets/Mirror/Tests/Editor/MessageTests.cs.meta rename to Assets/Mirror/Tests/Editor/BuiltInMessages.cs.meta diff --git a/Assets/Mirror/Tests/Editor/MessageBaseTests.cs b/Assets/Mirror/Tests/Editor/MessageBaseTests.cs index 63fdaba12..ef6b75838 100644 --- a/Assets/Mirror/Tests/Editor/MessageBaseTests.cs +++ b/Assets/Mirror/Tests/Editor/MessageBaseTests.cs @@ -1,6 +1,6 @@ using NUnit.Framework; -namespace Mirror.Tests +namespace Mirror.Tests.MessageTests { struct TestMessage : IMessageBase { @@ -30,17 +30,18 @@ public void Serialize(NetworkWriter writer) } } - struct WovenTestMessage : IMessageBase + struct StructWithEmptyMethodMessage : IMessageBase { public int IntValue; public string StringValue; public double DoubleValue; + // Mirror will fill out these empty methods public void Deserialize(NetworkReader reader) { } public void Serialize(NetworkWriter writer) { } } - class ArrayIntIMessage : IMessageBase + class ClassWithoutBaseMessage : IMessageBase { public int[] array; @@ -86,7 +87,7 @@ class Layer3Message : Layer2Message public class MessageBaseTests { [Test] - public void Roundtrip() + public void StructWithMethods() { byte[] arr = MessagePacker.Pack(new TestMessage(1, "2", 3.3)); TestMessage t = MessagePacker.Unpack(arr); @@ -95,10 +96,10 @@ public void Roundtrip() } [Test] - public void WovenSerializationBodyRoundtrip() + public void StructWithEmptyMethods() { - byte[] arr = MessagePacker.Pack(new WovenTestMessage { IntValue = 1, StringValue = "2", DoubleValue = 3.3 }); - WovenTestMessage t = MessagePacker.Unpack(arr); + byte[] arr = MessagePacker.Pack(new StructWithEmptyMethodMessage { IntValue = 1, StringValue = "2", DoubleValue = 3.3 }); + StructWithEmptyMethodMessage t = MessagePacker.Unpack(arr); Assert.AreEqual(1, t.IntValue); Assert.AreEqual("2", t.StringValue); @@ -106,16 +107,16 @@ public void WovenSerializationBodyRoundtrip() } [Test] - public void TestIntArrayInIMessageBase() + public void ClassWithEmptyMethods() { - ArrayIntIMessage intMessage = new ArrayIntIMessage + ClassWithoutBaseMessage intMessage = new ClassWithoutBaseMessage { array = new[] { 3, 4, 5 } }; byte[] data = MessagePacker.Pack(intMessage); - ArrayIntIMessage unpacked = MessagePacker.Unpack(data); + ClassWithoutBaseMessage unpacked = MessagePacker.Unpack(data); Assert.That(unpacked.array, Is.EquivalentTo(new int[] { 3, 4, 5 })); } diff --git a/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs b/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs index e62a36ed7..39c88fc45 100644 --- a/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs +++ b/Assets/Mirror/Tests/Editor/MessageInheritanceTest.cs @@ -1,6 +1,6 @@ using NUnit.Framework; -namespace Mirror.Tests.MessageInheritance +namespace Mirror.Tests.MessageTests { class ParentMessage : MessageBase { diff --git a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs index ed3d40bd4..54c9500c7 100644 --- a/Assets/Mirror/Tests/Editor/NetworkServerTest.cs +++ b/Assets/Mirror/Tests/Editor/NetworkServerTest.cs @@ -7,6 +7,45 @@ namespace Mirror.Tests { + struct TestMessage1 : IMessageBase + { + public int IntValue; + public string StringValue; + public double DoubleValue; + + public TestMessage1(int i, string s, double d) + { + IntValue = i; + StringValue = s; + DoubleValue = d; + } + + public void Deserialize(NetworkReader reader) + { + IntValue = reader.ReadInt32(); + StringValue = reader.ReadString(); + DoubleValue = reader.ReadDouble(); + } + + public void Serialize(NetworkWriter writer) + { + writer.WriteInt32(IntValue); + writer.WriteString(StringValue); + writer.WriteDouble(DoubleValue); + } + } + + struct TestMessage2 : IMessageBase + { + public int IntValue; + public string StringValue; + public double DoubleValue; + + // Mirror will fill out these empty methods + public void Deserialize(NetworkReader reader) { } + public void Serialize(NetworkWriter writer) { } + } + public class CommandTestNetworkBehaviour : NetworkBehaviour { // counter to make sure that it's called exactly once @@ -413,8 +452,8 @@ public void OnDataReceivedTest() // add one custom message handler bool wasReceived = false; NetworkConnection connectionReceived = null; - TestMessage messageReceived = new TestMessage(); - NetworkServer.RegisterHandler((conn, msg) => + TestMessage1 messageReceived = new TestMessage1(); + NetworkServer.RegisterHandler((conn, msg) => { wasReceived = true; connectionReceived = conn; @@ -431,7 +470,7 @@ public void OnDataReceivedTest() Assert.That(NetworkServer.connections.Count, Is.EqualTo(1)); // serialize a test message into an arraysegment - TestMessage testMessage = new TestMessage { IntValue = 13, DoubleValue = 14, StringValue = "15" }; + TestMessage1 testMessage = new TestMessage1 { IntValue = 13, DoubleValue = 14, StringValue = "15" }; NetworkWriter writer = new NetworkWriter(); MessagePacker.Pack(testMessage, writer); ArraySegment segment = writer.ToArraySegment(); @@ -459,8 +498,8 @@ public void OnDataReceivedInvalidConnectionIdTest() // add one custom message handler bool wasReceived = false; NetworkConnection connectionReceived = null; - TestMessage messageReceived = new TestMessage(); - NetworkServer.RegisterHandler((conn, msg) => + TestMessage1 messageReceived = new TestMessage1(); + NetworkServer.RegisterHandler((conn, msg) => { wasReceived = true; connectionReceived = conn; @@ -472,7 +511,7 @@ public void OnDataReceivedInvalidConnectionIdTest() Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); // serialize a test message into an arraysegment - TestMessage testMessage = new TestMessage { IntValue = 13, DoubleValue = 14, StringValue = "15" }; + TestMessage1 testMessage = new TestMessage1 { IntValue = 13, DoubleValue = 14, StringValue = "15" }; NetworkWriter writer = new NetworkWriter(); MessagePacker.Pack(testMessage, writer); ArraySegment segment = writer.ToArraySegment(); @@ -711,12 +750,12 @@ public void SendToAllTest() int called = 0; connection.connectionToServer.SetHandlers(new Dictionary() { - { MessagePacker.GetId(), ((conn, reader, channelId) => ++called) } + { MessagePacker.GetId(), ((conn, reader, channelId) => ++called) } }); NetworkServer.AddConnection(connection); // create a message - TestMessage message = new TestMessage { IntValue = 1, DoubleValue = 2, StringValue = "3" }; + TestMessage1 message = new TestMessage1 { IntValue = 1, DoubleValue = 2, StringValue = "3" }; // send it to all bool result = NetworkServer.SendToAll(message); @@ -740,11 +779,11 @@ public void RegisterUnregisterClearHandlerTest() // RegisterHandler(conn, msg) variant int variant1Called = 0; - NetworkServer.RegisterHandler((conn, msg) => { ++variant1Called; }, false); + NetworkServer.RegisterHandler((conn, msg) => { ++variant1Called; }, false); // RegisterHandler(msg) variant int variant2Called = 0; - NetworkServer.RegisterHandler(msg => { ++variant2Called; }, false); + NetworkServer.RegisterHandler(msg => { ++variant2Called; }, false); // listen NetworkServer.Listen(1); @@ -757,20 +796,20 @@ public void RegisterUnregisterClearHandlerTest() // serialize first message, send it to server, check if it was handled NetworkWriter writer = new NetworkWriter(); - MessagePacker.Pack(new TestMessage(), writer); + MessagePacker.Pack(new TestMessage1(), writer); Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0); Assert.That(variant1Called, Is.EqualTo(1)); // serialize second message, send it to server, check if it was handled writer = new NetworkWriter(); - MessagePacker.Pack(new WovenTestMessage(), writer); + MessagePacker.Pack(new TestMessage2(), writer); Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0); Assert.That(variant2Called, Is.EqualTo(1)); // unregister first handler, send, should fail - NetworkServer.UnregisterHandler(); + NetworkServer.UnregisterHandler(); writer = new NetworkWriter(); - MessagePacker.Pack(new TestMessage(), writer); + MessagePacker.Pack(new TestMessage1(), writer); // log error messages are expected LogAssert.ignoreFailingMessages = true; Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0); @@ -783,7 +822,7 @@ public void RegisterUnregisterClearHandlerTest() // (only add this one to avoid disconnect error) NetworkServer.RegisterHandler((conn, msg) => { }, false); writer = new NetworkWriter(); - MessagePacker.Pack(new TestMessage(), writer); + MessagePacker.Pack(new TestMessage1(), writer); // log error messages are expected LogAssert.ignoreFailingMessages = true; Transport.activeTransport.OnServerDataReceived.Invoke(42, writer.ToArraySegment(), 0); @@ -811,12 +850,12 @@ public void SendToClientOfPlayer() int called = 0; connection.connectionToServer.SetHandlers(new Dictionary() { - { MessagePacker.GetId(), ((conn, reader, channelId) => ++called) } + { MessagePacker.GetId(), ((conn, reader, channelId) => ++called) } }); NetworkServer.AddConnection(connection); // create a message - TestMessage message = new TestMessage { IntValue = 1, DoubleValue = 2, StringValue = "3" }; + TestMessage1 message = new TestMessage1 { IntValue = 1, DoubleValue = 2, StringValue = "3" }; // create a gameobject and networkidentity NetworkIdentity identity = new GameObject().AddComponent();