public void Test_TryParseDecimal_InvalidFormat(string jsonData) { decimal value; bool res = CsvValueParser.TryParseDecimal(jsonData, out value); Assert.That(res, Is.False); }
public void Test_TryParseInt_InvalidFormat(string jsonData) { int value; bool res = CsvValueParser.TryParseInt(jsonData, out value); Assert.That(res, Is.False); }
public void Test_TryParseInt_Valid(string jsonData, int expectedData) { int value; bool res = CsvValueParser.TryParseInt(jsonData, out value); Assert.That(res, Is.True); Assert.That(value, Is.EqualTo(expectedData)); }
public void Test_TryParseBool_Valid(string jsonData, bool expectedData) { bool value; bool res = CsvValueParser.TryParseBool(jsonData, out value); Assert.That(res, Is.True); Assert.That(value, Is.EqualTo(expectedData)); }
public void Test_TryParseDateTime_InvalidFormat(string jsonData) { DateTime value; TimeZoneInfo info = TimeZoneInfo.Local; bool res = CsvValueParser.TryParseDateTime(jsonData, info, out value); Assert.That(res, Is.False); }
public void Test_TryParseDecimal_Valid(string jsonData, double expectedData) { decimal expected = (decimal)expectedData; decimal value; bool res = CsvValueParser.TryParseDecimal(jsonData, out value); Assert.That(res, Is.True); Assert.That(value, Is.EqualTo(expected)); }
public void Test_TryParseTime_Valid(string jsonData, string expectedData) { DateTime value; DateTime expected = DateTime.Parse(expectedData, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal); bool res = CsvValueParser.TryParseTime(jsonData, out value); Assert.That(res, Is.True); Assert.That(value, Is.EqualTo(expected)); Assert.That(value.Kind, Is.EqualTo(DateTimeKind.Utc)); }
public StatementEntryWithSourceData Parse(string[] csvRow) { if (csvRow == null) { throw new ArgumentNullException(nameof(csvRow)); } // TODO: error/null value handling return(new StatementEntryWithSourceData { Date = CsvValueParser.ParseDateOrThrow(csvRow[columnMapping.Date], dateFormat).Date, Amount = CsvValueParser.ParseDecimalOrThrow(csvRow[columnMapping.Amount]), Details = csvRow[columnMapping.Details], SourceData = csvRow }); }
public ExpenseReportEntryWithSourceData Parse(string[] csvRow) { if (csvRow == null) { throw new ArgumentNullException(nameof(csvRow)); } // TODO: error/null value handling return(new ExpenseReportEntryWithSourceData { Date = CsvValueParser.ParseDateOrThrow(csvRow[columnMapping.Date], dateFormat).Date, Amount = CsvValueParser.ParseDecimalOrThrow(csvRow[columnMapping.Amount]), IsPayPal = CsvValueParser.ParseBoolOrThrow(csvRow[columnMapping.IsPayPal]), Merchant = csvRow[columnMapping.Merchant], SourceData = csvRow }); }
public void Test_TryParseDateTime_Valid(bool provideTimeZone, string csvData, string expectedData) { // If csvData contains a timezone, then that timezone is used // Otherwise, if provideTimeZone=true, then the test timezone of +1 is used // Otherwise, if provideTimeZone=false, then the value is assumed to be UTC already TimeZoneInfo tz = null; if (provideTimeZone) { string displayName = "(GMT+01:00) ReadiNow/PlusOne"; string standardName = "Hammer Time"; TimeSpan offset = new TimeSpan(1, 00, 00); tz = TimeZoneInfo.CreateCustomTimeZone(standardName, offset, displayName, standardName); } DateTime value; DateTime expected = DateTime.Parse(expectedData, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal); bool res = CsvValueParser.TryParseDateTime(csvData, tz, out value); Assert.That(res, Is.True); Assert.That(value, Is.EqualTo(expected)); Assert.That(value.Kind, Is.EqualTo(DateTimeKind.Utc)); }