Exemplo n.º 1
0
        public void LargeClassTest()
        {
            byte[] array =
            {
                0xFF, 0xFF, 0xFF, 0xFF,
                0xFF, 0xD7, 0xBF, 0xC0,
                0xC9, 0xFD, 0xA3, 0x00,
                0x00, 0x00, 0x00, 0x0D,
            };

            var reader     = new PackedBitReader(array);
            var serializer = new PackedBitSerializer(typeof(BitPackingTest));
            var result     = serializer.Deserialize(reader) as BitPackingTest;

            var trueValues = typeof(BitPackingTest).
                             GetProperties(BindingFlags.Instance | BindingFlags.Public).
                             Where(p => p.Name.StartsWith("ShouldBeTrue")).
                             Select(p => Tuple.Create(p.Name, (bool)p.GetValue(result)));

            Assert.All(trueValues, tv => tv.Item2);

            var falseValues = typeof(BitPackingTest).
                              GetProperties(BindingFlags.Instance | BindingFlags.Public).
                              Where(p => p.Name.StartsWith("ShouldBeFalse")).
                              Select(p => Tuple.Create(p.Name, (bool)p.GetValue(result)));

            Assert.All(falseValues, fv => !fv.Item2);

            Assert.Equal(result.ShouldBe0, (byte)0);
            Assert.Equal(result.ShouldBe0Second, (uint)0);
            Assert.Equal(result.ShouldBe0Third, (byte)0);
            Assert.Equal(result.ShouldBe4, (byte)4);
        }