public static void Test_Uf16_UsesNullTerminator_When_BeingReserialized_DontTerminate(string testString) { //arrange SerializerService serializer = new SerializerService(); serializer.RegisterType <UTF8StringTestWithTerminator>(); serializer.Compile(); //act byte[] reserialized = serializer.SerializeAsync(serializer.DeserializeAsync <UTF8StringTestWithTerminator>(serializer.SerializeAsync(new UTF8StringTestWithTerminator(testString)).Result).Result).Result; Assert.AreEqual(8 + Encoding.UTF8.GetBytes(testString).Length + NULL_TERMINATOR_SIZE, reserialized.Length); Assert.AreEqual(0, reserialized.Last()); }
public static void Test_Uf16_UsesNullTerminator_When_BeingReserialized_DontTerminate(string testString) { //arrange SerializerService serializer = new SerializerService(); serializer.RegisterType <Utf16StringTestWithTerminator>(); serializer.Compile(); //act byte[] reserialized = serializer.SerializeAsync(serializer.DeserializeAsync <Utf16StringTestWithTerminator>(serializer.SerializeAsync(new Utf16StringTestWithTerminator(testString)).Result).Result).Result; Assert.AreEqual(8 + testString.Length * 2 + 2, reserialized.Length); Assert.AreEqual(0, reserialized.Last()); Assert.AreEqual(0, reserialized.Reverse().Skip(1).First()); }
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 })); }
public void Test_Can_Deserialize_OneByteSized_Type() { //arrange SerializerService serializer = new SerializerService(); serializer.RegisterType <TestOneSizedByteArray>(); serializer.Compile(); //act TestOneSizedByteArray result = serializer.DeserializeAsync <TestOneSizedByteArray>(new byte[3] { 0, 1, 7 }).Result; //assert Assert.NotNull(result); Assert.IsNotEmpty(result.Bytes); Assert.AreEqual(1, result.Bytes.Length); Assert.AreEqual(7, result.Bytes[0]); }
public void Test_Can_Deserialize_Async() { //arrange SerializerService serializer = new SerializerService(); serializer.RegisterType <TestSerializableType>(); serializer.Compile(); //act byte[] bytesTask = serializer.SerializeAsync(new TestSerializableType(50, "Hello!")).Result; TestSerializableType result = serializer.DeserializeAsync <TestSerializableType>(new AsyncWireReaderBytesReadableAdapter(new BytesReadableTest(bytesTask))).Result; //assert Assert.NotNull(bytesTask); Assert.IsNotEmpty(bytesTask); Assert.NotNull(result); Assert.AreEqual(50, result.TestInt); Assert.AreEqual("Hello!", result.TestString); }
public async static Task Test_Can_Deserialize_From_RealWorld_Bytes() { //arrange SerializerService service = new SerializerService(); service.RegisterType <AuthRealmListResponse>(); service.Compile(); //act AuthRealmListResponse response = await service.DeserializeAsync <AuthRealmListResponse>(new DefaultStreamReaderStrategyAsync(new AsyncRandomlyBlockingStream(realworldBytes))); byte[] bytes = await service.SerializeAsync(response, new DefaultStreamWriterStrategyAsync(new AsyncRandomlyBlockingStream())); //assert Assert.True(response.Realms.Count() == 1); Assert.True(response.Realms.First().isLocked == false); Assert.True(response.Realms.First().Information.Flags == RealmFlags.None); Assert.AreEqual(response.Realms.First().Information.RealmString, "Trinity"); Assert.AreEqual(response.Realms.First().Information.RealmAddress.RealmAddress.Value.ToString(), "127.0.0.1"); }
public void Test_Can_Serialize_RemovedSize_Array_Type() { //arrange SerializerService serializer = new SerializerService(); serializer.RegisterType <TestRemovedSizeArrayType>(); serializer.Compile(); RefInt[] values = new RefInt[] { new RefInt(5), new RefInt(16) }; //act byte[] bytes = serializer.SerializeAsync(new TestRemovedSizeArrayType(values)).Result; TestRemovedSizeArrayType deserialized = serializer.DeserializeAsync <TestRemovedSizeArrayType>(bytes).Result; //assert Assert.AreEqual(values.Length * sizeof(int) + sizeof(int), bytes.Length, "Bytes size"); Assert.AreEqual(bytes[0], values.Length + 1); for (int i = 0; i < values.Length; i++) { Assert.AreEqual(values[i].Value, deserialized.Values[i].Value); } }
public void Test_Can_Deserialize_Async_One_Sized_Array() { //arrange SerializerService serializer = new SerializerService(); serializer.RegisterType <TestSerializableType2>(); serializer.Compile(); //act byte[] bytesTask = serializer.SerializeAsync(new TestSerializableType2(TestSerializableType2.TestEnum.One, new byte[1] { 7 })).Result; Assert.NotNull(bytesTask); Assert.IsNotEmpty(bytesTask); TestSerializableType2 result = serializer.DeserializeAsync <TestSerializableType2>(new AsyncWireReaderBytesReadableAdapter(new BytesReadableTest(bytesTask))).Result; //assert Assert.NotNull(result); Assert.True(result.TestOneSizedArray.Length == 1); Assert.AreEqual(TestSerializableType2.TestEnum.One, result.EnumVal); Assert.AreEqual(7, result.TestOneSizedArray[0]); }