public void DeserializeThrowsWhenBufferIsWrongSize(int badSize) { Int32Serializer serializer = new Int32Serializer(); Assert.ThrowsException <ArgumentException>(() => { serializer.Deserialize(new byte[badSize]); }); }
public void DeserializeThrowsWhenBufferIsNull() { Int32Serializer serializer = new Int32Serializer(); Assert.ThrowsException <ArgumentNullException>(() => { serializer.Deserialize(null); }); }
public void SerializeThenDeserializeWorks(bool littleEndian) { int[] numbers = new int[] { int.MinValue, int.MinValue + 1, int.MinValue + 2, int.MinValue + 3, int.MinValue / 2, -65537, -65536, -65535, -65534, -257, -256, -255, -254 - 126, -127, -128 - 5, -4, -3, -2, -1, 0, int.MaxValue, int.MaxValue - 1, int.MaxValue - 2, int.MaxValue - 3, int.MaxValue / 2, 65537, 65536, 65535, 65534, 257, 256, 255, 254, 126, 127, 128, 5, 4, 3, 2, 1, }; Int32Serializer serializer = new Int32Serializer(littleEndian); for (int i = 0; i < numbers.Length; i++) { byte[] buffer = new byte[serializer.DataSize]; serializer.Serialize(numbers[i], buffer); Assert.AreEqual(numbers[i], serializer.Deserialize(buffer)); } }
public void SerializeAndDeserializeToTheSameObject(int originalValue) { Serializer <int> serializer = new Int32Serializer(); byte[] serializedValue = serializer.Serialize(originalValue); int deserializedValue = serializer.Deserialize(serializedValue); Assert.Equal(originalValue, deserializedValue); }
public void ShouldThrowIfDeserializingLessThanFourBytes(byte[] data) { Serializer <int> serializer = new Int32Serializer(); Assert.Throws <ArgumentOutOfRangeException>(() => serializer.Deserialize(data)); }
public void ShouldThrowIfDeserializingNull() { Serializer <int> serializer = new Int32Serializer(); Assert.Throws <ArgumentNullException>(() => serializer.Deserialize(null)); }
public override ReplaceMeIntId Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args) { var number = _intSerializer.Deserialize(context, args); return(ReplaceMeIntId.FromInt(number)); }