コード例 #1
0
        public void DeserializeThrowsWhenBufferIsWrongSize(int badSize)
        {
            Int32Serializer serializer = new Int32Serializer();

            Assert.ThrowsException <ArgumentException>(() => {
                serializer.Deserialize(new byte[badSize]);
            });
        }
コード例 #2
0
        public void DeserializeThrowsWhenBufferIsNull()
        {
            Int32Serializer serializer = new Int32Serializer();

            Assert.ThrowsException <ArgumentNullException>(() => {
                serializer.Deserialize(null);
            });
        }
コード例 #3
0
        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));
            }
        }
コード例 #4
0
        public void SerializeAndDeserializeToTheSameObject(int originalValue)
        {
            Serializer <int> serializer = new Int32Serializer();

            byte[] serializedValue   = serializer.Serialize(originalValue);
            int    deserializedValue = serializer.Deserialize(serializedValue);

            Assert.Equal(originalValue, deserializedValue);
        }
コード例 #5
0
        public void ShouldThrowIfDeserializingLessThanFourBytes(byte[] data)
        {
            Serializer <int> serializer = new Int32Serializer();

            Assert.Throws <ArgumentOutOfRangeException>(() => serializer.Deserialize(data));
        }
コード例 #6
0
        public void ShouldThrowIfDeserializingNull()
        {
            Serializer <int> serializer = new Int32Serializer();

            Assert.Throws <ArgumentNullException>(() => serializer.Deserialize(null));
        }
コード例 #7
0
        public override ReplaceMeIntId Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
        {
            var number = _intSerializer.Deserialize(context, args);

            return(ReplaceMeIntId.FromInt(number));
        }