示例#1
0
        public static void Test_Serializer_Doesnt_Throw_On_EnumString_Serializer_Building_When_A_String_Serializer_Is_Avaliable()
        {
            //arrange
            SerializerService service = new SerializerService();

            service.RegisterType <ClassWithStringToMakeStringSerializerAvailable>();
            Assert.Throws <Exception>(() => service.RegisterType <TestEnumStringFault>());           //this was causing problems when you tried to register multiple enumstrings due to fault with key lookup
        }
        public static void Test_Serializer_Doesnt_Throw_On_Contextual_Field_Multiple_Register_Containing_Type()
        {
            //This was causing exceptions. We were registering a field's type multiple times if it was contextual. That's bad.
            //arrange
            SerializerService service = new SerializerService();

            service.RegisterType <TestArrayWithFixedSize>();
            Assert.DoesNotThrow(() => service.RegisterType <TestArrayWithFixedSize>());
        }
        private static ISerializerService CreateNewSerializer()
        {
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <MapDatFormatGenericBodyModel <MapDataFormatObjectEntry> >();
            serializer.RegisterType <NRelSectionsChunkModel>();
            serializer.Compile();

            return(serializer);
        }
示例#4
0
        public void Test_Can_Register_Payload()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType(typeof(PSOBBPatchPacketPayloadServer));
            serializer.RegisterType(typeof(PSOBBPatchPacketPayloadServer));
            serializer.RegisterType(typeof(PSOBBPatchPacketPayloadServer));
            serializer.RegisterType(typeof(PSOBBPatchPacketPayloadServer));
        }
        //TODO: We should use seperate assemblies that can build the desired serializers
        private static INetworkSerializationService BuildServerSerializer()
        {
            SerializerService serializer = new SerializerService();

            //This is slightly complicated
            //But we need to register all the vanilla DTOs
            //but we should also register all the wotlk DTOs that we don't have vanilla DTOs for
            //This design will change in the future so that there is: wotlk, vanilla and shared libraries
            //But right now this is how we have to do it until then
            IReadOnlyCollection <NetworkOperationCode> codes     = VanillaGamePacketMetadataMarker.UnimplementedOperationCodes.Value;
            HashSet <NetworkOperationCode>             opcodeSet = new HashSet <NetworkOperationCode>();

            foreach (var opcode in codes)
            {
                opcodeSet.Add(opcode);
            }

            GamePacketStubMetadataMarker
            .GamePacketPayloadStubTypes
            .Where(t =>
            {
                NetworkOperationCode code = t.Attribute <GamePayloadOperationCodeAttribute>().OperationCode;

                //if it's not a vanilla or shared packet
                return(opcodeSet.Contains(code) && GamePacketMetadataMarker.UnimplementedOperationCodes.Value.Contains(code));
            })
            .Concat(GamePacketMetadataMarker.GamePacketPayloadTypes.Where(t => opcodeSet.Contains(t.Attribute <GamePayloadOperationCodeAttribute>().OperationCode)))
            .Concat(VanillaGamePacketMetadataMarker.VanillaGamePacketPayloadTypes)
            //TODO: Disable this when you need
            .Where(t => t != typeof(SMSG_CONTACT_LIST_PAYLOAD) && t != typeof(SMSG_SPELL_GO_Payload))
            .ToList()
            .ForEach(t =>
            {
                if (!(typeof(IUnimplementedGamePacketPayload).IsAssignableFrom(t)))
                {
                    Console.WriteLine($"Registering Type: {t.Name}");
                }

                serializer.RegisterType(t);
            });

            //Also the header types
            serializer.RegisterType <ServerPacketHeader>();
            serializer.RegisterType <OutgoingClientPacketHeader>();

            //TODO: Uncomment for dumping
            //serializer.RegisterType(typeof(SMSG_COMPRESSED_UPDATE_OBJECT_DTO_PROXY));
            //serializer.RegisterType(typeof(SMSG_UPDATE_OBJECT_DTO_PROXY));
            serializer.RegisterType <SMSG_CONTACT_LIST_DTO_PROXY>();
            serializer.RegisterType <SMSG_SPELL_GO_DTO_PROXY>();

            serializer.Compile();

            return(new FreecraftCoreGladNetSerializerAdapter(serializer));
        }
        public static void Test_Serializer_Can_Register_WireType_With_Nested_Complex_Type_Empty()
        {
            //arrange
            SerializerService service = new SerializerService();

            //act
            Assert.DoesNotThrow(() => service.RegisterType <TestClassMarked>());
            Assert.DoesNotThrow(() => service.RegisterType <TestClassMarkedWithComplexMember>());
            Assert.DoesNotThrow(() => service.RegisterType <TestClassMarkedWithComplexMember>());
            Assert.DoesNotThrow(() => service.RegisterType <TestClassMarked>());
            Assert.True(service.isTypeRegistered <TestClassMarkedWithComplexMember>());
        }
示例#7
0
        public static void Test_Can_Deserialize_SeperatedCollection_Type()
        {
            Assert.Warn("TODO You must fix and reimplement seperated collection. It's not working fully as intended.");
            return;

            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestSeperatedCollection>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestSeperatedCollection("Hello meep56!", 123456, new[] { 55523, 90, 2445, 63432, 6969 }));
            TestSeperatedCollection deserialized = serializer.Deserialize <TestSeperatedCollection>(bytes);

            //assert
            Assert.NotNull(deserialized);
            Assert.NotNull(deserialized.IntsChars);

            Assert.AreEqual(5, deserialized.Size, "Expected the size to be the original collection size");
            Assert.AreEqual(5, deserialized.IntsChars.Length, $"Expected the length of the collection to be the original length");

            Assert.AreEqual("Hello meep56!", deserialized.TestString);
            Assert.AreEqual(123456, deserialized.AnotherValue);
        }
示例#8
0
        public static void Test_Can_Register_SeperatedCollection_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            Assert.DoesNotThrow(() => serializer.RegisterType <TestSeperatedCollection>());
        }
示例#9
0
        public static void Test_Can_Regiser_Multilevel_Polymorphic_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            Assert.DoesNotThrow(() => serializer.RegisterType <TestBaseClass>());
        }
        public void Test_Can_Serialize_Then_Deserializer_AuthSessionChallengeEvent_Vanilla_Payload()
        {
            //arrange
            SerializerService otherService = new SerializerService();

            otherService.RegisterType <SessionAuthChallengeEvent>();

            SerializerService serializer = new SerializerService();

            serializer.RegisterType <SessionAuthChallengeEvent_Vanilla>();
            serializer.Compile();
            otherService.Compile();

            SerializerService lastserializer = new SerializerService();

            lastserializer.RegisterType <SessionAuthChallengeEvent_Vanilla>();
            lastserializer.Compile();

            //act
            byte[] bytes = lastserializer.Serialize(new SessionAuthChallengeEvent_Vanilla(new SessionAuthChallengeEventData(55, new byte[32])));
            SessionAuthChallengeEvent_Vanilla payload = serializer.Deserialize <SessionAuthChallengeEvent_Vanilla>(bytes);

            //assert
            Assert.NotNull(bytes);
        }
示例#11
0
        public static void Test_Can_Serializer_Then_Deserialize_Most_Complex_Test_Possible()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            TestEnum[] arrayOne = new TestEnum[] { TestEnum.Zero, TestEnum.One };
            TestEnum[] arrayTwo = new TestEnum[3] {
                TestEnum.Two, TestEnum.One, TestEnum.Zero
            };
            BasicWireDataContract WireDataContractNested = new BasicWireDataContract(8);

            //act
            serializer.RegisterType <VeryComplexType>();
            serializer.Compile();

            byte[] bytes = serializer.Serialize(new VeryComplexType(6, WireDataContractNested, arrayOne, arrayTwo));
            Assert.NotNull(bytes);
            Assert.False(bytes.Length == 0);
            VeryComplexType message = serializer.Deserialize <VeryComplexType>(bytes);

            //assert
            Assert.NotNull(message);

            //check fields
            for (int i = 0; i < arrayOne.Length; i++)
            {
                Assert.AreEqual(arrayOne[i], message.testEnums[i], $"Failed for index {i}.");
            }

            for (int i = 0; i < arrayTwo.Length; i++)
            {
                Assert.AreEqual(arrayTwo[i], message.testEnumsAnother[i], $"Failed for index {i}.");
            }
        }
        public void Test_Can_Deserialize_ReadToEnd_String_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <ReadToEndStringType>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new ReadToEndStringType(5, TestStrings));
            ReadToEndStringType deserializer = serializer.Deserialize <ReadToEndStringType>(bytes);

            Assert.NotNull(deserializer);
            Assert.IsNotEmpty(deserializer.Strings);
            Assert.AreEqual(5, deserializer.I);
            Assert.AreEqual(TestStrings.Length, deserializer.Strings.Length);

            //Check that there are null terminators
            Assert.AreEqual(TestStrings.Length, bytes.Skip(4).Count(b => b == 0));

            for (int i = 0; i < TestStrings.Length; i++)
            {
                Assert.AreEqual(TestStrings[i], deserializer.Strings[i]);
            }
        }
        public static async Task Test_Can_Deserialize_AuthLogonProofResponse()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <AuthPacketBaseTest>();
            serializer.RegisterType <AuthLogonProofResponse>();
            serializer.Link <AuthLogonProofResponse, AuthPacketBaseTest>();

            serializer.Compile();
            //act
            AuthPacketBaseTest test = await serializer.DeserializeAsync <AuthPacketBaseTest>(new DefaultStreamReaderStrategyAsync(realWorldBytes.Skip(1).ToArray())
                                                                                             .PeekWithBufferingAsync()
                                                                                             .PreprendWithBytesAsync(new byte[] { 0x01 })
                                                                                             .PreprendWithBytesAsync(new byte[] { 2 }));
        }
示例#14
0
        public void Test_Can_Serialize_Type_With_Complex_Array_Ignored_And_SendSize_Array_Succedding(int[] intArray)
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestComplexOptionalFieldWithDisable>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestComplexOptionalFieldWithDisable(intArray));
            TestComplexOptionalFieldWithDisable deserializerData = serializer.Deserialize <TestComplexOptionalFieldWithDisable>(bytes);

            //assert
            Assert.NotNull(bytes);
            Assert.True(bytes.Length != 0);

            //Check it's sizeof the element * length + the sendsize
            Assert.True(bytes.Length == intArray.Length * sizeof(int) + sizeof(int));

            Assert.NotNull(deserializerData);

            for (int i = 0; i < intArray.Length; i++)
            {
                Assert.AreEqual(intArray[i], deserializerData.TestInts[i]);
            }
        }
示例#15
0
        private static async Task AsyncMain()
        {
            //While they're typing this let's build the serializer.
            Task serializerReady = Task.Factory.StartNew(() =>
            {
                serializer.RegisterType <AdtFile>();
                serializer.Compile();
            }, TaskCreationOptions.LongRunning);

            string adtName = Console.ReadLine();

            if (String.IsNullOrEmpty(adtName) || !File.Exists(adtName))
            {
                throw new ArgumentException($"No adt file named {adtName} found in the directory.");
            }

            byte[] bytes = File.ReadAllBytes(adtName);

            //wait for the serializer to compile
            await serializerReady;

            AdtFile adtFile = serializer.Deserialize <AdtFile>(bytes);

            foreach (var chunk in adtFile)
            {
                Console.WriteLine(chunk.ToString());
            }

            Console.ReadKey();
        }
        public void Test_Can_Register_All_Concrete_Models(Type t)
        {
            //We have to do abit of a hack if it's a generic type
            //We need a closed generic. DBCs usually are generic if they have strings
            if (t.IsGenericTypeDefinition)
            {
                //TODO: Handle contraints better, causes throw and this is a hack to catch
                //TODO: Support closing multiple type arg generics
                //Assuming this can work, assuming all 1 generic param for now.
                try
                {
                    t = t.MakeGenericType(typeof(StringDBCReference));
                }
                catch (Exception e)
                {
                    Assert.Inconclusive($"Cannot test Type: {t.Name} because closed generic could not be made. Maybe caused by constaints. Error: {e.Message}");
                }
            }

            //arrange
            SerializerService serializer = new SerializerService();

            //assert
            Assert.DoesNotThrow(() => serializer.RegisterType(t));
            Assert.DoesNotThrow(() => serializer.Compile());

            Assert.True(serializer.isTypeRegistered(t), $"Failed to register Type: {t.Name}");
        }
        public static void Test_Register_Complex_RealWorld_Type_Doesnt_Throw()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            Assert.DoesNotThrow(() => serializer.RegisterType <AuthLogonChallengeRequest>());
        }
示例#18
0
 private static void NewMethod(Stopwatch watch, SerializerService serializer)
 {
     watch.Start();
     serializer.RegisterType <PlayerCharacterDataModel>();
     serializer.Compile();
     watch.Stop();
 }
        public static void Test_Can_Register_Child_of_Expected_Runtime_BaseType()
        {
            //arrange
            SerializerService serivce = new SerializerService();

            Assert.DoesNotThrow(() => serivce.RegisterType <ChildType>());
        }
        public static void Test_Can_Register_Compression_Marked_Class()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestInt32ArrayCompression>();
            serializer.Compile();
        }
        public static void Test_Serializer_Throws_On_Non_Wiretype_Registerations()
        {
            //arrange
            SerializerService service = new SerializerService();

            //assert
            Assert.Throws <InvalidOperationException>(() => service.RegisterType <TestClassUnmarked>());
        }
        //TODO: Can't remember why this isn't worknig, can't remember if needs fixing?
        //[Test]
        public static void Test_Serializer_Auth_Token()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <AuthenticationToken>();
            serializer.RegisterType <AuthRealmListPacketTest.AuthRealmListResponse>();
            serializer.Compile();

            //act
            AuthRealmListPacketTest.AuthRealmListResponse response = serializer.Deserialize <AuthRealmListPacketTest.AuthRealmListResponse>(new DefaultStreamReaderStrategy(realworldBytes));

            //act
            AuthenticationToken token = serializer.Deserialize <AuthenticationToken>(Encoding.UTF8.GetBytes(realWorldBytestring));

            Assert.AreEqual("GLADER", token.AccountName);
        }
示例#23
0
        public void Test_Can_Register_PatchingLoginRequestPayload()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType(typeof(PatchingLoginRequestPayload));
            serializer.Compile();
        }
        public static void Test_Serializer_Throws_On_Registering_Type_With_Duplicate_Wiremember_Numbers()
        {
            //arrange
            SerializerService service = new SerializerService();

            //assert
            Assert.Throws <Exception>(() => service.RegisterType <TestCannotRegisterTypeWithMultipleSameFields>());
        }
        public static void Test_Can_Register_ReverseFixedByteArray_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            //assert
            Assert.DoesNotThrow(() => serializer.RegisterType <ReverseArrayByteTest>());
        }
        public void Test_Can_Register_AddedSize_String_Type()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestAddedSizeStringType>();
            serializer.Compile();
        }
        public static void Test_Serializer_Can_Register_WireType_Empty()
        {
            //arrange
            SerializerService service = new SerializerService();

            //act
            Assert.DoesNotThrow(() => service.RegisterType <TestClassMarked>());
            Assert.True(service.isTypeRegistered(typeof(TestClassMarked)));
        }
示例#28
0
        public static void Test_Serializer_Can_Register_WireType_With_EnumString_Field()
        {
            //arrange
            SerializerService service = new SerializerService();

            //act
            Assert.DoesNotThrow(() => service.RegisterType <WireDataContractWithStringEnum>());
            Assert.True(service.isTypeRegistered <WireDataContractWithStringEnum>());
        }
        private ISerializerService CreateSerializer()
        {
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <RealmListContainer>();

            typeof(AuthLogonChallengeRequest).Assembly
            .GetTypes()
            .Where(t => typeof(AuthenticationServerPayload).IsAssignableFrom(t) || typeof(AuthenticationClientPayload).IsAssignableFrom(t))
            .ToList()
            .ForEach(t =>
            {
                serializer.RegisterType(t);
            });

            serializer.Compile();

            return(serializer);
        }
        public static void Test_Can_Deserialize_Complex_Compressed_Class()
        {
            //arrange
            SerializerService serializer = new SerializerService();

            serializer.RegisterType <TestComplexTypeWithCompressedComplex>();
            serializer.RegisterType <TestComplexType>();
            serializer.Compile();

            //act
            byte[] bytes = serializer.Serialize(new TestComplexTypeWithCompressedComplex(new TestComplexType(5, 50)));
            TestComplexTypeWithCompressedComplex obj = serializer.Deserialize <TestComplexTypeWithCompressedComplex>(bytes);

            byte[] justTestComplexBytes = serializer.Serialize(new TestComplexType(65, 50));

            //assert
            Assert.True(bytes.Length < 40 * sizeof(int));             //might be longer with header/footer
            Assert.AreEqual(50, obj.CompressedComplex.testValues.Length);
        }