Renaming tests and namespaces (#2167)

* renaming test

* renaming test file

* removing test suffix from methods

* changing test namesapce
This commit is contained in:
James Frowen 2020-08-19 02:18:20 +01:00 committed by GitHub
parent 0c790e339d
commit a2124c3522
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 88 additions and 48 deletions

View File

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

View File

@ -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<TestMessage>(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<WovenTestMessage>(arr);
byte[] arr = MessagePacker.Pack(new StructWithEmptyMethodMessage { IntValue = 1, StringValue = "2", DoubleValue = 3.3 });
StructWithEmptyMethodMessage t = MessagePacker.Unpack<StructWithEmptyMethodMessage>(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<ArrayIntIMessage>(data);
ClassWithoutBaseMessage unpacked = MessagePacker.Unpack<ClassWithoutBaseMessage>(data);
Assert.That(unpacked.array, Is.EquivalentTo(new int[] { 3, 4, 5 }));
}

View File

@ -1,6 +1,6 @@
using NUnit.Framework;
namespace Mirror.Tests.MessageInheritance
namespace Mirror.Tests.MessageTests
{
class ParentMessage : MessageBase
{

View File

@ -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<TestMessage>((conn, msg) =>
TestMessage1 messageReceived = new TestMessage1();
NetworkServer.RegisterHandler<TestMessage1>((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<byte> 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<TestMessage>((conn, msg) =>
TestMessage1 messageReceived = new TestMessage1();
NetworkServer.RegisterHandler<TestMessage1>((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<byte> segment = writer.ToArraySegment();
@ -711,12 +750,12 @@ public void SendToAllTest()
int called = 0;
connection.connectionToServer.SetHandlers(new Dictionary<int, NetworkMessageDelegate>()
{
{ MessagePacker.GetId<TestMessage>(), ((conn, reader, channelId) => ++called) }
{ MessagePacker.GetId<TestMessage1>(), ((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<TestMessage>((conn, msg) => { ++variant1Called; }, false);
NetworkServer.RegisterHandler<TestMessage1>((conn, msg) => { ++variant1Called; }, false);
// RegisterHandler(msg) variant
int variant2Called = 0;
NetworkServer.RegisterHandler<WovenTestMessage>(msg => { ++variant2Called; }, false);
NetworkServer.RegisterHandler<TestMessage2>(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<TestMessage>();
NetworkServer.UnregisterHandler<TestMessage1>();
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<DisconnectMessage>((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<int, NetworkMessageDelegate>()
{
{ MessagePacker.GetId<TestMessage>(), ((conn, reader, channelId) => ++called) }
{ MessagePacker.GetId<TestMessage1>(), ((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<NetworkIdentity>();