Skip to content

Commit

Permalink
Adding Test
Browse files Browse the repository at this point in the history
  • Loading branch information
João Velasques committed Dec 3, 2018
1 parent df72152 commit 67bcd63
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion tests/FlatMapper.Tests/DelimitedFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ public class DelimitedFileTests

private IList<TestObject> objects;

private int _headerLinesCount;


public DelimitedFileTests()
{
_headerLinesCount = 2;
layout = new Layout<TestObject>.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'))
Expand Down Expand Up @@ -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<TestObject>(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;
Expand Down

0 comments on commit 67bcd63

Please sign in to comment.