public void BinaryReaderUtility_ReadCollectionT_1()
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            NonNullCollection <Dummy> expected = new NonNullCollection <Dummy>
            {
                new Dummy {
                    Value = 123
                },
                new Dummy {
                    Value = 456
                },
                new Dummy {
                    Value = 789
                }
            };

            BinaryWriterUtility.Write(writer, expected);

            byte[] bytes = stream.ToArray();
            stream = new MemoryStream(bytes);
            BinaryReader reader = new BinaryReader(stream);

            NonNullCollection <Dummy> actual = new NonNullCollection <Dummy>();

            BinaryReaderUtility.ReadCollection(reader, actual);
            Assert.AreEqual(expected.Count, actual.Count);
            Assert.AreEqual(expected[0].Value, actual[0].Value);
            Assert.AreEqual(expected[1].Value, actual[1].Value);
            Assert.AreEqual(expected[2].Value, actual[2].Value);
        }
Esempio n. 2
0
        public void BinaryWriterUtility_Write_Nullable_Byte_2()
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            byte?expected = null;

            BinaryWriterUtility.Write(writer, expected);

            byte[] bytes = stream.ToArray();
            stream = new MemoryStream(bytes);
            BinaryReader reader = new BinaryReader(stream);

            byte?actual = BinaryReaderUtility.ReadNullableByte(reader);

            Assert.IsFalse(actual.HasValue);
        }
Esempio n. 3
0
        public void BinaryWriterUtility_Write_DateTime_1()
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            DateTime expected = new DateTime(2018, 2, 13, 11, 55, 0);

            BinaryWriterUtility.Write(writer, expected);

            byte[] bytes = stream.ToArray();
            stream = new MemoryStream(bytes);
            BinaryReader reader = new BinaryReader(stream);

            DateTime actual = BinaryReaderUtility.ReadDateTime(reader);

            Assert.AreEqual(expected, actual);
        }
Esempio n. 4
0
        public void BinaryWriterUtility_Write_Nullable_Int64_1()
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            long?expected = 123;

            BinaryWriterUtility.Write(writer, expected);

            byte[] bytes = stream.ToArray();
            stream = new MemoryStream(bytes);
            BinaryReader reader = new BinaryReader(stream);

            long?actual = BinaryReaderUtility.ReadNullableInt64(reader);

            Assert.IsTrue(actual.HasValue);
            Assert.AreEqual(expected.Value, actual.Value);
        }
Esempio n. 5
0
        public void BinaryWriterUtility_Write_Nullable_DateTime_1()
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            DateTime?expected = new DateTime(2018, 2, 13, 12, 8, 0);

            BinaryWriterUtility.Write(writer, expected);

            byte[] bytes = stream.ToArray();
            stream = new MemoryStream(bytes);
            BinaryReader reader = new BinaryReader(stream);

            DateTime?actual = BinaryReaderUtility.ReadNullableDateTime(reader);

            Assert.IsTrue(actual.HasValue);
            Assert.AreEqual(expected.Value, actual.Value);
        }