Beispiel #1
0
        public void ShouldThrowExceptionIfDataDoesNotCorrespondToRecordLength()
        {
            StreamReader streamReader = CreateStreamReader("123451234");
            int          recordLength = 5;
            List <int>   fieldLengths = new List <int> {
                1, 1, 1, 1, 1
            };
            var fixedFormatDefinition = CreateFixedFormatDefinition(recordLength, fieldLengths);

            FixedFormatReader reader = new FixedFormatReader(streamReader, fixedFormatDefinition);

            reader.GetNextValue();
            Assert.Throws <IOException>(() => reader.GetNextValue());
        }
Beispiel #2
0
        public void ShouldReadEmptyString()
        {
            StreamReader streamReader          = CreateStreamReader("");
            int          recordLength          = 0;
            List <int>   fieldLengths          = new List <int>();
            var          fixedFormatDefinition = CreateFixedFormatDefinition(recordLength, fieldLengths);

            FixedFormatReader reader = new FixedFormatReader(streamReader, fixedFormatDefinition);

            reader.HasMoreRecords().Should().BeFalse();
            var value = reader.GetNextValue();

            reader.HasMoreRecords().Should().BeFalse();

            value.Item1.Should().Be("");
            value.Item2.Should().BeEmpty();
        }
Beispiel #3
0
        public void ShouldReadStringWithRecordLength5AndFieldLength1()
        {
            StreamReader streamReader = CreateStreamReader("123451234512345");
            int          recordLength = 5;
            List <int>   fieldLengths = new List <int> {
                1, 1, 1, 1, 1
            };
            var fixedFormatDefinition = CreateFixedFormatDefinition(recordLength, fieldLengths);

            FixedFormatReader reader = new FixedFormatReader(streamReader, fixedFormatDefinition);

            for (int i = 0; i < 3; i++)
            {
                reader.HasMoreRecords().Should().BeTrue();
                var value = reader.GetNextValue();
                value.Item1.Should().Be("");
                value.Item2.Should().Equal(new List <string> {
                    "1", "2", "3", "4", "5"
                });
            }
            reader.HasMoreRecords().Should().BeFalse();
        }
Beispiel #4
0
        public void ShouldReadStringWithDifferentFieldLengths()
        {
            StreamReader streamReader = CreateStreamReader("122333444455555122333444455555122333444455555");
            int          recordLength = 15;
            List <int>   fieldLengths = new List <int> {
                1, 2, 3, 4, 5
            };
            var fixedFormatDefinition = CreateFixedFormatDefinition(recordLength, fieldLengths);

            FixedFormatReader reader = new FixedFormatReader(streamReader, fixedFormatDefinition);

            for (int i = 0; i < 3; i++)
            {
                reader.HasMoreRecords().Should().BeTrue();
                var value = reader.GetNextValue();
                value.Item1.Should().Be("");
                value.Item2.Should().Equal(new List <string> {
                    "1", "22", "333", "4444", "55555"
                });
            }
            reader.HasMoreRecords().Should().BeFalse();
        }