Exemple #1
0
 public void TestGetPacketType_MethodInfo_MismatchedAttribute() => Assert.Throws <ArgumentException>(
     () => PacketHandlerAttribute.GetPacketType(
         typeof(TestPacketHandlerMethods).GetMethod(
             nameof(TestPacketHandlerMethods.HandleWithMismatchedAttribute)
             )
         )
     );
Exemple #2
0
 public void TestIsValidHandler_MethodInfo_MismatchedAttribute() => Assert.IsFalse(
     PacketHandlerAttribute.IsValidHandler(
         typeof(TestPacketHandlerMethods).GetMethod(
             nameof(TestPacketHandlerMethods.HandleWithMismatchedAttribute)
             )
         )
     );
Exemple #3
0
 public void TestGetPacketType_MethodInfo_InvalidPacketParameterType() => Assert.Throws <ArgumentException>(
     () => PacketHandlerAttribute.GetPacketType(
         typeof(TestPacketHandlerMethods).GetMethod(
             nameof(TestPacketHandlerMethods.HandleInvalidPacketParameterType)
             )
         )
     );
Exemple #4
0
 public void TestIsValidHandler_MethodInfo_InvalidPacketParameterType() => Assert.IsFalse(
     PacketHandlerAttribute.IsValidHandler(
         typeof(TestPacketHandlerMethods).GetMethod(
             nameof(TestPacketHandlerMethods.HandleInvalidPacketParameterType)
             )
         )
     );
Exemple #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))
                );
        }
Exemple #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))
                    )
                );
        }
Exemple #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))
                );
        }
Exemple #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))
                    )
                );
        }
Exemple #9
0
 public void TestGetPacketType_Type_null() =>
 Assert.Throws <ArgumentNullException>(() => PacketHandlerAttribute.GetPacketType(default(Type)));
Exemple #10
0
        public void TestIsValidHandler_Type()
        {
            Assert.IsTrue(PacketHandlerAttribute.IsValidHandler(typeof(TestClassPacketHandlerWithAttribute)));

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