public static void Test_Reverse_Decorator_Can_Reverse_Strings() { //arrange ReverseStringSerializerDecorator serializer = new ReverseStringSerializerDecorator(new StringSerializerStrategy()); DefaultStreamWriterStrategy writer = new DefaultStreamWriterStrategy(); //act serializer.Write("Hello", writer); Assert.AreEqual("olleH\0", new string(Encoding.ASCII.GetChars(writer.GetBytes()))); }
public static void Test_Fixed_String_Can_Write_Proper_Length() { //arrange SizeStringSerializerDecorator stringSerializer = new SizeStringSerializerDecorator(new FixedSizeStringSizeStrategy(5), new StringSerializerStrategy(), Encoding.ASCII); DefaultStreamWriterStrategy writer = new DefaultStreamWriterStrategy(); //act stringSerializer.Write("hello", writer); //assert Assert.AreEqual(6, writer.GetBytes().Length); }
public static void Test_Reverse_Decorator_Can_Reverse_Strings(string input) { //arrange ReverseStringSerializerDecorator serializer = new ReverseStringSerializerDecorator(new StringSerializerStrategy(Encoding.UTF8)); DefaultStreamWriterStrategy writer = new DefaultStreamWriterStrategy(); //act serializer.Write(input, writer); Assert.AreEqual(new string(input.Reverse().Concat(new char[1] { '\0' }).ToArray()), new string(Encoding.UTF8.GetChars(writer.GetBytes()))); }
public static void Test_Fixed_String_Can_Read() { //arrange SizeStringSerializerDecorator stringSerializer = new SizeStringSerializerDecorator(new FixedSizeStringSizeStrategy(5), new StringSerializerStrategy(), Encoding.ASCII); DefaultStreamWriterStrategy writer = new DefaultStreamWriterStrategy(); //act stringSerializer.Write("hello", writer); string value = stringSerializer.Read(new DefaultStreamReaderStrategy(writer.GetBytes())); //assert Assert.NotNull(value); Assert.IsNotEmpty(value); Assert.AreEqual("hello", value); }
public static void Test_Send_With_Size_Can_Read() { //arrange SizeStringSerializerDecorator stringSerializer = new SizeStringSerializerDecorator(new SizeIncludedStringSizeStrategy <byte>(new GenericTypePrimitiveSharedBufferSerializerStrategy <byte>(), true), new StringSerializerStrategy(), Encoding.ASCII); DefaultStreamWriterStrategy writer = new DefaultStreamWriterStrategy(); //act stringSerializer.Write("Hello", writer); string value = stringSerializer.Read(new DefaultStreamReaderStrategy(writer.GetBytes())); //assert Assert.NotNull(value); Assert.IsNotEmpty(value); Assert.AreEqual("Hello", value); }
public static void Test_DateTime_Deserializes() { //arrange PackedDateTimeSerializerStrategyDecorator serializer = new PackedDateTimeSerializerStrategyDecorator(new GenericTypePrimitiveSharedBufferSerializerStrategy <int>()); DefaultStreamWriterStrategy writer = new DefaultStreamWriterStrategy(); DateTime testValue = DateTime.Now; //act serializer.Write(testValue, writer); byte[] bytes = writer.GetBytes(); DateTime deserializedInstance = serializer.Read(new DefaultStreamReaderStrategy(bytes)); //assert Assert.NotNull(bytes); }
public static void Test_Fixed_String_Can_Read(string input) { //arrange SizeStringSerializerDecorator stringSerializer = new SizeStringSerializerDecorator(new FixedSizeStringSizeStrategy(Encoding.UTF8.GetByteCount(input)), new StringSerializerStrategy(Encoding.UTF8), Encoding.UTF8); DefaultStreamWriterStrategy writer = new DefaultStreamWriterStrategy(); //act stringSerializer.Write(input, writer); string value = stringSerializer.Read(new DefaultStreamReaderStrategy(writer.GetBytes())); //assert Assert.NotNull(value); Assert.IsNotEmpty(value); Assert.AreEqual(input, value); }
public static void Test_DontTerminate_Serializer_Doesnt_Add_Terminator() { //arrange DontTerminateStringSerializerDecorator serializer = new DontTerminateStringSerializerDecorator(new StringSerializerStrategy(), Encoding.ASCII); DefaultStreamWriterStrategy writer = new DefaultStreamWriterStrategy(); //act serializer.Write("Hello", writer); byte[] bytes = writer.GetBytes(); //assert Assert.NotNull(bytes); Assert.IsNotEmpty(bytes); Assert.False(bytes[bytes.Length - 1] == 0); Assert.True(bytes.Length == 5); }
public static void Test_DateTime_Against_WoWPacketParserTest() { //arrange PackedDateTimeSerializerStrategyDecorator serializer = new PackedDateTimeSerializerStrategyDecorator(new GenericTypePrimitiveSharedBufferSerializerStrategy <int>()); DefaultStreamWriterStrategy writer = new DefaultStreamWriterStrategy(); new GenericTypePrimitiveSharedBufferSerializerStrategy <int>().Write(168938967, writer); DateTime dateTime = serializer.Read(new DefaultStreamReaderStrategy(writer.GetBytes())); //Assert Assert.AreEqual(23, dateTime.Minute); Assert.AreEqual(23, dateTime.Hour); Assert.AreEqual(8, dateTime.Day); Assert.AreEqual(2010, dateTime.Year); Assert.AreEqual(2, dateTime.Month); }
public static void Test_DateTime_Deserializes_To_Correct_DateTime() { //arrange PackedDateTimeSerializerStrategyDecorator serializer = new PackedDateTimeSerializerStrategyDecorator(new GenericTypePrimitiveSharedBufferSerializerStrategy <int>()); DefaultStreamWriterStrategy writer = new DefaultStreamWriterStrategy(); DateTime testValue = DateTime.Now; //act serializer.Write(testValue, writer); byte[] bytes = writer.GetBytes(); DateTime deserializedInstance = serializer.Read(new DefaultStreamReaderStrategy(bytes)); //assert Assert.NotNull(bytes); Assert.True(deserializedInstance != DateTime.MinValue); //Check values Assert.AreEqual(testValue.Minute, deserializedInstance.Minute); Assert.AreEqual(testValue.Day, deserializedInstance.Day); Assert.AreEqual(testValue.Year, deserializedInstance.Year); Assert.AreEqual(testValue.Month, deserializedInstance.Month); }
public static void Test_Fixed_String_Can_Write_Proper_Length(string input) { //arrange SizeStringSerializerDecorator stringSerializer = new SizeStringSerializerDecorator(new FixedSizeStringSizeStrategy(input.Length), new StringSerializerStrategy(Encoding.UTF8), Encoding.UTF8); DefaultStreamWriterStrategy writer = new DefaultStreamWriterStrategy(); //act stringSerializer.Write(input, writer); //assert Assert.AreEqual(Encoding.UTF8.GetByteCount(input) + NULL_TERMINATOR_SIZE, writer.GetBytes().Length); }