Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Negative Values not parsed correctly with default converters #2

Closed
bytefish opened this issue Dec 13, 2015 · 0 comments
Closed

Negative Values not parsed correctly with default converters #2

bytefish opened this issue Dec 13, 2015 · 0 comments
Labels

Comments

@bytefish
Copy link
Collaborator

The Number converters are using the wrong NumberStyle as Default value. The default constructors need to use the correct NumberStyle.

The following Unit Test must succeed.

public class NegativeValueEntity
{
    public int Value { get; set; }
}

private class NegativeValueEntityMapping : CsvMapping<NegativeValueEntity>
{
    public NegativeValueEntityMapping()
    {
        MapProperty(0, x => x.Value);
    }
}

[Test]
public void NegativeValueTest()
{
    CsvParserOptions csvParserOptions = new CsvParserOptions(true, new[] { ';' });
    CsvReaderOptions csvReaderOptions = new CsvReaderOptions(new[] { Environment.NewLine });
    NegativeValueEntityMapping csvMapper = new NegativeValueEntityMapping();
    CsvParser<NegativeValueEntity> csvParser = new CsvParser<NegativeValueEntity>(csvParserOptions, csvMapper);

    var stringBuilder = new StringBuilder()
        .AppendLine("Value")
        .AppendLine("-1");

    var result = csvParser
        .ReadFromString(csvReaderOptions, stringBuilder.ToString())
        .ToList();

    Assert.AreEqual(1, result.Count);
    Assert.IsTrue(result.All(x => x.IsValid));
    Assert.AreEqual(-1, result.First().Result.Value);

    // Asserts ...
}
bytefish pushed a commit that referenced this issue Dec 13, 2015
Switched Default NumberStyles
bytefish pushed a commit that referenced this issue Dec 14, 2015
Added a Testcase for Issue #2 again.
@bytefish bytefish added the bug label Apr 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant