Beispiel #1
0
        public void TryReadRecord_HeaderAndFooterWithInvalidRecordLength_ExceptionIsThrown()
        {
            var records = new byte[][]
            {
                new byte[] { 0x1 },
                new byte[] { 0x2, 0x3 },
                new byte[] { 0x4, 0x5, 0x6 },
                new byte[] { 0x7 }
            };
            var recordsBuffer = BuildRecordsBuffer(records);

            bool couldReadRecord;
            IEnumerable <FieldFailure> failures;

            using (var stream = new MemoryStream(recordsBuffer))
                using (var dataReader = new FixedWidthBinaryStreamReader(stream))
                {
                    dataReader.RecordSize = 2;
                    dataReader.HeaderSize = 1;
                    dataReader.FooterSize = 1;

                    dataReader.Open();

                    do
                    {
                        couldReadRecord = dataReader.TryReadRecord(out var record, out failures);
                    }while (couldReadRecord || failures?.Count() > 0);
                }
        }
Beispiel #2
0
        public void TryReadRecord_NoHeaderOrFooterWithTwoRecords_AllRecordsAreRead()
        {
            var records = new byte[][]
            {
                new byte[] { 0x1, 0x2 },
                new byte[] { 0x3, 0x4 }
            };
            var recordsBuffer = BuildRecordsBuffer(records);
            var recordsRead   = 0;

            bool couldReadRecord;
            IEnumerable <FieldFailure> failures;

            using (var stream = new MemoryStream(recordsBuffer))
                using (var dataReader = new FixedWidthBinaryStreamReader(stream))
                {
                    dataReader.RecordSize = 2;
                    dataReader.HeaderSize = 0;
                    dataReader.FooterSize = 0;

                    dataReader.Open();

                    do
                    {
                        couldReadRecord = dataReader.TryReadRecord(out var record, out failures);

                        if (couldReadRecord)
                        {
                            Assert.IsTrue(((byte[])record).SequenceEqual(records[++recordsRead - 1]));
                        }
                    }while (couldReadRecord || failures?.Count() > 0);

                    Assert.AreEqual(2, recordsRead);
                }
        }
Beispiel #3
0
        public void TryReadRecord_FooterMissingAndNoHeaderWithZeroRecords_ExceptionIsThrown()
        {
            var records = new byte[] { };

            using (var stream = new MemoryStream(records))
                using (var dataReader = new FixedWidthBinaryStreamReader(stream))
                {
                    dataReader.RecordSize = 2;
                    dataReader.HeaderSize = 0;
                    dataReader.FooterSize = 1;

                    dataReader.Open();

                    dataReader.TryReadRecord(out var record, out var failures);
                }
        }
Beispiel #4
0
        public void TryReadRecord_HeaderAndFooterWithZeroRecords_NoRecordsAreRead()
        {
            var records = new byte[] { 0x1, 0x2 };

            using (var stream = new MemoryStream(records))
                using (var dataReader = new FixedWidthBinaryStreamReader(stream))
                {
                    dataReader.RecordSize = 2;
                    dataReader.HeaderSize = 1;
                    dataReader.FooterSize = 1;

                    dataReader.Open();

                    var couldReadRecord = dataReader.TryReadRecord(out var record, out var failures);

                    Assert.IsFalse(couldReadRecord);
                }
        }