public static void Test_Fixed_String_Can_Write() { //arrange SizeStringSerializerDecorator stringSerializer = new SizeStringSerializerDecorator(new FixedSizeStringSizeStrategy(5), new StringSerializerStrategy(), Encoding.ASCII); stringSerializer.Write("hello", new DefaultStreamWriterStrategy()); }
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_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); }
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_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); }