Beispiel #1
0
        public void Should_TestForSkip_When_TestForSkipObjectIsDefined()
        {
            // Arrange
            var layout = new LayoutDescriptor <DummyStringModel>()
                         .WithSkipDefinition(new DummyRowSkipper())
                         .AppendField(x => x.Id, 5)
                         .AppendField(x => x.Field1, 15)
                         .AppendField(x => x.Field2, 15)
                         .AppendField(x => x.Field3, 15);
            var parser = new FixedWidthFileParser <DummyStringModel>(layout, GetFilePath("TestForSkip.dat"));

            // Act
            var model = parser.ParseFile();

            // Assert
            CollectionAssert.AreEqual(GetExpectedRows().ToList(), model.ToList());
        }
Beispiel #2
0
        public void Should_SkipHeaderRow_When_SkipHeaderSettingIsEnabled()
        {
            // Arrange
            var layout = new LayoutDescriptor <DummyStringModel>()
                         .AppendField(x => x.Id, 5)
                         .AppendField(x => x.Field1, 15)
                         .AppendField(x => x.Field2, 15)
                         .AppendField(x => x.Field3, 15)
                         .WithSkipDefinition(new SkipFirstRow());
            var parser = new FixedWidthFileParser <DummyStringModel>(layout, GetFilePath("SkipHeaderRow.dat"));

            // Act
            var model = parser.ParseFile();

            // Assert
            CollectionAssert.AreEqual(GetExpectedRows().ToList(), model.ToList());
        }
Beispiel #3
0
        public void Should_SkipIgnoredField_When_AppendIgnoredFieldIsUsed()
        {
            // Arrange
            var layout = new LayoutDescriptor <DummyStringModel>()
                         .AppendField(x => x.Id, 5)
                         .AppendField(x => x.Field1, 15)
                         .AppendField(x => x.Field2, 15)
                         .AppendIgnoredField(30)
                         .AppendField(x => x.Field3, 15);
            var parser = new FixedWidthFileParser <DummyStringModel>(layout, GetFilePath("SkipColumns.dat"));

            // Act
            var model = parser.ParseFile();

            // Assert
            CollectionAssert.AreEqual(GetExpectedRows().ToList(), model.ToList());
        }
Beispiel #4
0
        public void Should_SkipAllDefinedRows_When_CollectionOfSkipDefinitionsIsUsed()
        {
            // Arrange
            var layout = new LayoutDescriptor <DummyStringModel>()
                         .AppendField(x => x.Id, 5)
                         .AppendField(x => x.Field1, 15)
                         .AppendField(x => x.Field2, 15)
                         .AppendField(x => x.Field3, 15)
                         .WithSkipDefinition(new SkipBlankRows())
                         .WithSkipDefinition(new SkipFirstRow());
            var parser = new FixedWidthFileParser <DummyStringModel>(layout, GetFilePath("SkipMultiple.dat"));

            // Act
            var model = parser.ParseFile();

            // Assert
            CollectionAssert.AreEqual(GetExpectedRows().ToList(), model.ToList());
        }
        private ICollection <T> ParseTestFile()
        {
            var parser = new FixedWidthFileParser <T>(GetLayout(), GetFilePath());

            return(parser.ParseFile());
        }