示例#1
0
        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);
        }
示例#2
0
        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_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);
        }