示例#1
0
 public void TestGetPacketType_MethodInfo_MismatchedAttribute() => Assert.Throws <ArgumentException>(
     () => PacketHandlerAttribute.GetPacketType(
         typeof(TestPacketHandlerMethods).GetMethod(
             nameof(TestPacketHandlerMethods.HandleWithMismatchedAttribute)
             )
         )
     );
示例#2
0
 public void TestIsValidHandler_MethodInfo_MismatchedAttribute() => Assert.IsFalse(
     PacketHandlerAttribute.IsValidHandler(
         typeof(TestPacketHandlerMethods).GetMethod(
             nameof(TestPacketHandlerMethods.HandleWithMismatchedAttribute)
             )
         )
     );
示例#3
0
 public void TestGetPacketType_MethodInfo_InvalidPacketParameterType() => Assert.Throws <ArgumentException>(
     () => PacketHandlerAttribute.GetPacketType(
         typeof(TestPacketHandlerMethods).GetMethod(
             nameof(TestPacketHandlerMethods.HandleInvalidPacketParameterType)
             )
         )
     );
示例#4
0
 public void TestIsValidHandler_MethodInfo_InvalidPacketParameterType() => Assert.IsFalse(
     PacketHandlerAttribute.IsValidHandler(
         typeof(TestPacketHandlerMethods).GetMethod(
             nameof(TestPacketHandlerMethods.HandleInvalidPacketParameterType)
             )
         )
     );
示例#5
0
        public void TestGetHandlerInterface_Type()
        {
            Assert.AreEqual(
                typeof(IPacketHandler <TestPacket>),
                PacketHandlerAttribute.GetHandlerInterface(typeof(TestClassPacketHandlerNoAttribute))
                );

            Assert.AreEqual(
                typeof(IPacketHandler <TestPacket>),
                PacketHandlerAttribute.GetHandlerInterface(typeof(TestClassPacketHandlerWithAttribute))
                );

            Assert.AreEqual(
                typeof(IPacketHandler <TestPacket2>),
                PacketHandlerAttribute.GetHandlerInterface(typeof(TestClassPacketHandlerWithAttribute2))
                );

            Assert.AreEqual(
                typeof(IPacketHandler <TestPacket>),
                PacketHandlerAttribute.GetHandlerInterface(typeof(TestClassPacketHandlerWithMismatchedAttribute))
                );

            // This specific handler is disallowed in the registry and filtered out elsewhere,
            // but PacketHandlerAttribute.GetHandlerInterface() allowing it is acceptable.
            Assert.AreEqual(
                typeof(IPacketHandler <IPacket>),
                PacketHandlerAttribute.GetHandlerInterface(typeof(TestClassPacketHandlerInvalidPacketType))
                );
        }
示例#6
0
        public void TestIsValidHandler_MethodInfo()
        {
            Assert.IsTrue(
                PacketHandlerAttribute.IsValidHandler(
                    typeof(TestPacketHandlerMethods).GetMethod(nameof(TestPacketHandlerMethods.HandleWithAttribute))
                    )
                );

            Assert.IsTrue(
                PacketHandlerAttribute.IsValidHandler(
                    typeof(TestPacketHandlerMethods).GetMethod(nameof(TestPacketHandlerMethods.HandleWithAttribute2))
                    )
                );
        }
示例#7
0
        public void TestGetPacketType_Type()
        {
            Assert.AreEqual(
                typeof(TestPacket), PacketHandlerAttribute.GetPacketType(typeof(TestClassPacketHandlerNoAttribute))
                );

            Assert.AreEqual(
                typeof(TestPacket), PacketHandlerAttribute.GetPacketType(typeof(TestClassPacketHandlerWithAttribute))
                );

            Assert.AreEqual(
                typeof(TestPacket2), PacketHandlerAttribute.GetPacketType(typeof(TestClassPacketHandlerWithAttribute2))
                );
        }
示例#8
0
        public void TestGetPacketType_MethodInfo()
        {
            Assert.AreEqual(
                typeof(TestPacket),
                PacketHandlerAttribute.GetPacketType(
                    typeof(TestPacketHandlerMethods).GetMethod(nameof(TestPacketHandlerMethods.HandleNoAttribute))
                    )
                );

            Assert.AreEqual(
                typeof(TestPacket),
                PacketHandlerAttribute.GetPacketType(
                    typeof(TestPacketHandlerMethods).GetMethod(nameof(TestPacketHandlerMethods.HandleWithAttribute))
                    )
                );

            Assert.AreEqual(
                typeof(TestPacket2),
                PacketHandlerAttribute.GetPacketType(
                    typeof(TestPacketHandlerMethods).GetMethod(nameof(TestPacketHandlerMethods.HandleWithAttribute2))
                    )
                );
        }
示例#9
0
 public void TestGetPacketType_Type_null() =>
 Assert.Throws <ArgumentNullException>(() => PacketHandlerAttribute.GetPacketType(default(Type)));
示例#10
0
        public void TestIsValidHandler_Type()
        {
            Assert.IsTrue(PacketHandlerAttribute.IsValidHandler(typeof(TestClassPacketHandlerWithAttribute)));

            Assert.IsTrue(PacketHandlerAttribute.IsValidHandler(typeof(TestClassPacketHandlerWithAttribute2)));
        }
示例#11
0
 public void TestGetHandlerInterface_Type_NotHandler() =>
 Assert.IsNull(PacketHandlerAttribute.GetHandlerInterface(typeof(TestClassNotPacketHandler)));
示例#12
0
 public void TestGetPacketType_Type_MismatchedAttribute() => Assert.Throws <ArgumentException>(
     () => PacketHandlerAttribute.GetPacketType(typeof(TestClassPacketHandlerWithMismatchedAttribute))
     );
示例#13
0
 public void TestIsValidHandler_Type_NoAttribute() => Assert.IsTrue(
     PacketHandlerAttribute.IsValidHandler(typeof(TestClassPacketHandlerNoAttribute))
     );
示例#14
0
 public void TestIsValidHandler_MethodInfo_NoAttribute() => Assert.IsTrue(
     PacketHandlerAttribute.IsValidHandler(
         typeof(TestPacketHandlerMethods).GetMethod(nameof(TestPacketHandlerMethods.HandleNoAttribute))
         )
     );
示例#15
0
 public void TestIsValidHandler_MethodInfo_null() =>
 Assert.Throws <ArgumentNullException>(() => PacketHandlerAttribute.GetPacketType(default(MethodInfo)));
示例#16
0
 public void TestGetPacketType_Type_NotPacketHandlerImplementation() => Assert.Throws <ArgumentException>(
     () => PacketHandlerAttribute.GetPacketType(typeof(TestClassNotPacketHandler))
     );
示例#17
0
 public void TestGetPacketType_Type_InvalidPacketType() => Assert.Throws <ArgumentException>(
     () => PacketHandlerAttribute.GetPacketType(typeof(TestClassPacketHandlerInvalidPacketType))
     );
示例#18
0
 public void TestIsValidHandler_Type_MismatchedAttribute() => Assert.IsFalse(
     PacketHandlerAttribute.IsValidHandler(typeof(TestClassPacketHandlerWithMismatchedAttribute))
     );
示例#19
0
 public void TestIsValidHandler_Type_InvalidPacketType() => Assert.IsFalse(
     PacketHandlerAttribute.IsValidHandler(typeof(TestClassPacketHandlerInvalidPacketType))
     );
示例#20
0
 public void TestGetHandlerInterface_Type_null() =>
 Assert.Throws <ArgumentNullException>(() => PacketHandlerAttribute.GetHandlerInterface(null));