Esempio n. 1
0
 public void BinaryBlockSerializer_MismatchTypeReadAndWrite()
 {
     using (SerializationContext context = new SerializationContext(new MemoryStream()))
     {
         int singleLength = BinaryBlockSerializer.Write(context, (int)500);
         context.Stream.Seek(-singleLength, SeekOrigin.Current);
         Verify.Exception <IOException>(
             () => { ushort wrongType = BinaryBlockSerializer.Read <ushort>(context); }
             );
     }
 }
Esempio n. 2
0
        public void ReadBinary(ISerializationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            _itemCount = context.Reader.ReadUInt16();
            _default   = BinaryBlockSerializer.Read <T>(context);
            _values    = BinaryBlockSerializer.ReadArray <T>(context);
        }
Esempio n. 3
0
        public void BinaryBlockSerializer_ByteArrayAsSingle()
        {
            byte[] value = new byte[] { 0, 127, 128, 255 };

            using (SerializationContext context = new SerializationContext(new MemoryStream()))
            {
                int singleLength = BinaryBlockSerializer.Write(context, value);
                context.Stream.Seek(-singleLength, SeekOrigin.Current);
                byte[] readValue = BinaryBlockSerializer.Read <byte[]>(context);
                Assert.AreEqual(String.Join(", ", value), String.Join(", ", readValue));
            }
        }
Esempio n. 4
0
        private static void RoundTrip <T>(SerializationContext context, T value)
        {
            // Test Array Reading
            int arrayLength = BinaryBlockSerializer.WriteArray <T>(context, new T[] { value });

            context.Stream.Seek(-arrayLength, SeekOrigin.Current);
            T[] readArray = BinaryBlockSerializer.ReadArray <T>(context);
            Assert.AreEqual(value, readArray[0]);

            // Test Single Reading
            int singleLength = BinaryBlockSerializer.Write(context, value);

            context.Stream.Seek(-singleLength, SeekOrigin.Current);
            T readValue = BinaryBlockSerializer.Read <T>(context);

            Assert.AreEqual(value, readValue);
        }
Esempio n. 5
0
 public void BinaryBlockSerializer_Read_UnsupportedType()
 {
     Verify.Exception <IOException>(
         () => { BinaryBlockSerializerTests me = BinaryBlockSerializer.Read <BinaryBlockSerializerTests>(new SerializationContext(new MemoryStream())); }
         );
 }