diff --git a/tests/FlatMapper.Tests/DelimitedFileTests.cs b/tests/FlatMapper.Tests/DelimitedFileTests.cs index 014e164..be01780 100644 --- a/tests/FlatMapper.Tests/DelimitedFileTests.cs +++ b/tests/FlatMapper.Tests/DelimitedFileTests.cs @@ -16,13 +16,16 @@ public class DelimitedFileTests private IList objects; + private int _headerLinesCount; + public DelimitedFileTests() { + _headerLinesCount = 2; layout = new Layout.DelimitedLayout() .WithDelimiter(";") .WithQuote("\"") - .HeaderLines(2) + .HeaderLines(_headerLinesCount) .WithMember(o => o.Id, set => set.WithLength(5).WithLeftPadding('0')) .WithMember(o => o.Description, set => set.WithLength(25).WithRightPadding(' ')) .WithMember(o => o.NullableInt, set => set.WithLength(5).AllowNull("=Null").WithLeftPadding('0')) @@ -59,6 +62,33 @@ public void can_write_read_stream() } } + [Fact] + public void doesnt_write_header_multiple_times() + { + using (var memory = new MemoryStream()) + { + var flatFile = new FlatFile(layout, memory, HandleEntryReadError); + + flatFile.Write(objects); + flatFile.Write(objects); + + memory.Seek(0, SeekOrigin.Begin); + var headerLines = 0; + using (StreamReader streamReader = new StreamReader(memory)) + { + string line = ""; + while((line = streamReader.ReadLine()) != null) + { + if(line.Contains(nameof(TestObject.NullableEnum))) + { + headerLines++; + } + } + } + Assert.True(headerLines == _headerLinesCount); + } + } + private bool HandleEntryReadError(ParserErrorInfo errorInfo, Exception exception) { return false;