Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
leandromoh committed Nov 11, 2023
1 parent 93c5970 commit 12bab6b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions RecordParser.Test/FileReaderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,21 @@ public class Quoted
}

[Theory]
[InlineData(800_000, false)]
[InlineData(1_000_000, true)]
public void Doo(int innerRecords, bool shouldThrow)
// note: since new line is \n on unix and \r\n on windows
// string length will not be the same. so depending of the
// values passed, result may differ depending of the OS.
// current values passes in both.
[InlineData(900_000, true)]
[InlineData(1_100_000, false)]
public void Given_record_is_too_large_for_default_buffer_size_then_exception_should_be_throw(int innerRecords, bool enoughBuffer)
{
// Arrange

// construct a CSV with a header row
// and a *single* data row, where the 4th column contains a large inlined, CSV file enclosed in quotes.
// this is an extreme case, but is a valid CSV according to the spec.
var tw = new StringWriter();
var header = "A,B,C,D";
tw.WriteLine(header);
tw.WriteLine("A,B,C,D");
tw.Write("1,2,3,\"");

for (int i = 0; i < innerRecords; i++)
Expand Down Expand Up @@ -84,13 +87,9 @@ public void Doo(int innerRecords, bool shouldThrow)

// Assert

var neededBuffer = fileContent.Length - header.Length;
var enoughBuffer = ReaderCommon.Length >= neededBuffer;
enoughBuffer.Should().Be(!shouldThrow);

if (shouldThrow)
if (enoughBuffer == false)
{
act.Should().Throw<RecordTooLargeException>().WithMessage("Record found is too large.");
act.Should().Throw<RecordTooLargeException>().WithMessage("Record is too large.");
return;
}

Expand All @@ -113,7 +112,7 @@ public void Doo(int innerRecords, bool shouldThrow)
[InlineData(13, 5)]
[InlineData(14, 7)]
[InlineData(15, 7)]
public void Given_record_is_too_large_to_fit_in_buffer_then_exception_should_be_throw(int bufferSize, int canRead)
public void Given_record_is_too_large_for_custom_buffer_size_then_exception_should_be_throw(int bufferSize, int canRead)

Check warning on line 115 in RecordParser.Test/FileReaderTest.cs

View workflow job for this annotation

GitHub Actions / dotnet test

Theory method 'Given_record_is_too_large_for_custom_buffer_size_then_exception_should_be_throw' on test class 'FileReaderTest' does not use parameter 'bufferSize'. (https://xunit.github.io/xunit.analyzers/rules/xUnit1026)

Check warning on line 115 in RecordParser.Test/FileReaderTest.cs

View workflow job for this annotation

GitHub Actions / dotnet test

Theory method 'Given_record_is_too_large_for_custom_buffer_size_then_exception_should_be_throw' on test class 'FileReaderTest' does not use parameter 'bufferSize'. (https://xunit.github.io/xunit.analyzers/rules/xUnit1026)
{
// Arrange

Expand Down Expand Up @@ -170,7 +169,7 @@ public void Given_record_is_too_large_to_fit_in_buffer_then_exception_should_be_
if (bufferLargeEnoughToReadAll)
act();
else
act.Should().Throw<RecordTooLargeException>().WithMessage("Record found is too large.");
act.Should().Throw<RecordTooLargeException>().WithMessage("Record is too large.");

results.Should().BeEquivalentTo(expected.Take(canRead));
}
Expand Down
2 changes: 1 addition & 1 deletion RecordParser/Extensions/FileReader/RowReaders/RowBy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public int FillBuffer()
if (initial == false)
{
if (len == buffer.Length)
throw new RecordTooLargeException("Record found is too large.");
throw new RecordTooLargeException("Record is too large.");

Array.Copy(buffer, j, buffer, 0, len);
}
Expand Down

0 comments on commit 12bab6b

Please sign in to comment.