From 3c7a83f7f55ecd17ee179d136104544d79855a26 Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Thu, 29 Dec 2022 12:12:54 +0100 Subject: [PATCH] Add Test for IPacket & PacketIdAttribute --- Server.Tests/PacketTests.cs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Server.Tests/PacketTests.cs diff --git a/Server.Tests/PacketTests.cs b/Server.Tests/PacketTests.cs new file mode 100644 index 0000000..50c79ce --- /dev/null +++ b/Server.Tests/PacketTests.cs @@ -0,0 +1,18 @@ +using System.Reflection; + +namespace Server.Tests; + +public class PacketTests +{ + [Fact] + public void TestPacketInheritingIPacket() + { + var allTypes = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()) + .Where(x => x.IsAssignableTo(typeof(Server.Packets.IPacket)) && x.IsClass); + if (!allTypes.Any()) + true.Should().BeTrue("There have been no types found which can be checked"); + else + allTypes.All(t => t.GetCustomAttributes().Any()) + .Should().BeTrue("All types inheriting from IPacket should have the PacketIdAttribute attribute."); + } +} \ No newline at end of file