Ejemplo n.º 1
0
        public void Test_SpecialLinkAttributes_Are_Marked_On_Correct_Types()
        {
            //arrange
            //Find the attribute that should be annoting these payloads
            WireDataContractBaseLinkAttribute linkAttri = typeof(GameClientPacketPayloadAttribute)
                                                          .Assembly
                                                          .GetTypes()
                                                          .Where(t => t.BaseType == typeof(WireDataContractBaseLinkAttribute))
                                                          .Select(t => Activator.CreateInstance(t, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new object[] { 5 }, null) as WireDataContractBaseLinkAttribute)
                                                          .FirstOrDefault(c => c.BaseType == typeof(TPayloadBaseType));

            if (linkAttri == null)
            {
                Assert.Fail($"Failed to get link attribute for {typeof(TPayloadBaseType).Name}.");
            }

            //check that all payloads in the assembly with this attribute derive from the basepayload type
            foreach (Type t in typeof(TTypeToReflectForAssembly).Assembly
                     .GetTypes()
                     .Where(t => t.GetCustomAttribute(linkAttri.GetType()) != null))
            {
                try
                {
                    Assert.True(typeof(TPayloadBaseType).IsAssignableFrom(t), $"Type: {t.Name} is marked with Attribute: {linkAttri.GetType().Name} but doesn't derive from Type: {linkAttri.BaseType.Name}. In derives from incorrect Type: {t.BaseType}");
                }
                catch (Exception e)
                {
                    Assert.Fail($"Failed to check the link for {t.Name} Exception: {e.Message}");
                }
            }
        }
Ejemplo n.º 2
0
        public void Test_No_Other_Packet_Shares_BaseType_And_OpCode(Type t)
        {
            //arrange
            WireDataContractBaseLinkAttribute attri = t.GetCustomAttribute <WireDataContractBaseLinkAttribute>();

            foreach (Type payloadType in PayloadTypes)
            {
                if (payloadType == t)
                {
                    continue;
                }

                //If it is the same base type we should check opcode
                if (payloadType.BaseType != t.BaseType)
                {
                    continue;
                }

                //Check for non-duplicate opcode on same basetype
                Assert.AreNotEqual(attri.Index, payloadType.GetCustomAttribute <WireDataContractBaseLinkAttribute>().Index, $"Found duplicate OpCode: 0x{attri.Index:X} on Type: {t.Name} and Type: {payloadType.Name}.");
            }
        }