Example #1
0
        public void WriteObject1DArrayTest()
        {
            List <InnerClass> values = new List <InnerClass>()
            {
                new InnerClass()
                {
                    m_bool = true, m_double = 0.1, m_float = 150
                },
                new InnerClass()
                {
                    m_bool = false, m_double = 2.1, m_float = 150e5F
                },
            };

            SerializedStreamBuilder builder = new SerializedStreamBuilder()
                                              .Size((byte)2);

            foreach (InnerClass innerClass in values)
            {
                builder
                .Float(innerClass.m_float)
                .Double(innerClass.m_double)
                .Boolean(innerClass.m_bool);
            }

            System.IO.MemoryStream actual = new System.IO.MemoryStream();

            BinaryWriter writer = new BinaryWriter(actual, BinaryWriterTest.CannedVersion);

            writer.WriteObjectArray <InnerClass>(string.Empty, values, false, 1);

            TestHelper.AssertCollectionEquals <byte>(builder.ToArray(), actual.ToArray());
        }
Example #2
0
        public void ReadObject1DArrayTest()
        {
            List <InnerClass> values = new List <InnerClass>()
            {
                new InnerClass()
                {
                    m_bool = true, m_double = 0.1, m_float = 150
                },
                new InnerClass()
                {
                    m_bool = false, m_double = 2.1, m_float = 150e5F
                },
            };

            SerializedStreamBuilder builder = new SerializedStreamBuilder()
                                              .Size((byte)2);

            foreach (InnerClass innerClass in values)
            {
                builder
                .Float(innerClass.m_float)
                .Double(innerClass.m_double)
                .Boolean(innerClass.m_bool);
            }

            BinaryReader reader = new BinaryReader(builder.ToStream(), DeserializationHelper.CannedVersion);

            List <InnerClass> actual = (List <InnerClass>)reader.ReadObjectArray <InnerClass>(string.Empty, false, 1);

            Assert.IsNotNull(actual);

            TestHelper.AssertCollectionEquals <InnerClass>(values, actual);
        }