-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from DashNY/feature-ledgerbal
Add support for LedgerBalance. Better data type conversion. Unit Tests Thank you Alec @DashNY
- Loading branch information
Showing
13 changed files
with
315 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace QFXparser.Testing | ||
{ | ||
public class ParsingTest | ||
{ | ||
[Fact] | ||
public void TestSimple() | ||
{ | ||
var parser = new FileParser("test.qfx"); | ||
var statement = parser.BuildStatement(); | ||
var transactions = statement.Transactions.ToList(); | ||
Assert.Equal(3, transactions.Count); | ||
Assert.Equal(-768.33m, statement.LedgerBalance.Amount); | ||
Assert.Equal(new DateTime(2018, 5, 25, 0, 0, 0, DateTimeKind.Utc), statement.LedgerBalance.AsOf); | ||
Assert.Equal(-27.18m, transactions[0].Amount); | ||
Assert.Equal("AMAZON.COM AMZN.COM/BILL AMZN.CO", transactions[0].Memo); | ||
Assert.Equal(new DateTime(2018, 4, 27, 16, 0, 0, DateTimeKind.Utc), transactions[0].PostedOn); | ||
Assert.Equal(0m, transactions[2].Amount); // test for default value if invalid in .qfx | ||
} | ||
|
||
[Fact] | ||
public void TestDateTimeNoTimeZoneAssumesUtc() | ||
{ | ||
Assert.Equal(new DateTime(2018, 5, 25, 0, 0, 0, DateTimeKind.Utc), ParsingHelper.ParseDate("20180525000000")); | ||
} | ||
|
||
[Fact] | ||
public void TestDateTimeWithUtcTimeZone() | ||
{ | ||
Assert.Equal(new DateTime(2018, 5, 25, 0, 0, 0, DateTimeKind.Utc), ParsingHelper.ParseDate("20180525000000[0:UTC]")); | ||
} | ||
|
||
[Fact] | ||
public void TestDateTimeWithMstTimeZone() | ||
{ | ||
Assert.Equal(new DateTime(2018, 1, 19, 0, 0, 0, DateTimeKind.Utc), ParsingHelper.ParseDate("20180119000000.000[-7:MST]")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" /> | ||
<PackageReference Include="xunit" Version="2.4.0" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\QFXparser\QFXparser.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="test.qfx"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
OFXHEADER:100 | ||
DATA:OFXSGML | ||
VERSION:102 | ||
SECURITY:NONE | ||
ENCODING:USASCII | ||
CHARSET:1252 | ||
COMPRESSION:NONE | ||
OLDFILEUID:NONE | ||
NEWFILEUID:NONE | ||
|
||
<OFX> | ||
<SIGNONMSGSRSV1> | ||
<SONRS> | ||
<STATUS> | ||
<CODE>0 | ||
<SEVERITY>INFO | ||
</STATUS> | ||
<DTSERVER>20180708011545[0:UTC] | ||
<LANGUAGE>ENG | ||
<FI> | ||
<ORG>Bank of America | ||
<FID>9876 | ||
</FI> | ||
<INTU.BID>3456 | ||
</SONRS> | ||
</SIGNONMSGSRSV1> | ||
<CREDITCARDMSGSRSV1> | ||
<CCSTMTTRNRS> | ||
<TRNUID>20180708011545[0:UTC] | ||
<STATUS> | ||
<CODE>0 | ||
<SEVERITY>INFO | ||
</STATUS> | ||
<CCSTMTRS> | ||
<CURDEF>USD | ||
<CCACCTFROM> | ||
<ACCTID>1234123409870987 | ||
</CCACCTFROM> | ||
<BANKTRANLIST> | ||
<DTSTART>20180427160000[0:UTC] | ||
<DTEND>20180525160000[0:UTC] | ||
<STMTTRN> | ||
<TRNTYPE>PAYMENT | ||
<DTPOSTED>20180427160000[0:UTC] | ||
<TRNAMT>-27.18 | ||
<FITID>555444 | ||
<CORRECTFITID>555444 | ||
<CORRECTACTION>REPLACE | ||
<NAME>AMAZON.COM AMZN.COM/BILL AMZN.CO | ||
<MEMO>AMAZON.COM AMZN.COM/BILL AMZN.CO | ||
</STMTTRN> | ||
<STMTTRN> | ||
<TRNTYPE>PAYMENT | ||
<DTPOSTED>20180430160000[0:UTC] | ||
<TRNAMT>-25.00 | ||
<FITID>666876 | ||
<CORRECTFITID>666876 | ||
<CORRECTACTION>REPLACE | ||
<NAME>NEW JERSEY E-ZPASS 888-288-6865 | ||
<MEMO>NEW JERSEY E-ZPASS 888-288-6865 | ||
</STMTTRN> | ||
<STMTTRN> | ||
<TRNTYPE>CREDIT | ||
<DTPOSTED>20180501160000[0:UTC] | ||
<TRNAMT>56.77invalid | ||
<FITID>46576 | ||
<CORRECTFITID>46576 | ||
<CORRECTACTION>REPLACE | ||
<NAME>PMT FROM BILL PAYER SERVICE | ||
</STMTTRN> | ||
</BANKTRANLIST> | ||
<LEDGERBAL> | ||
<BALAMT>-768.33 | ||
<DTASOF>20180525000000[0:UTC] | ||
</LEDGERBAL> | ||
</CCSTMTRS> | ||
</CCSTMTTRNRS> | ||
</CREDITCARDMSGSRSV1> | ||
</OFX> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Runtime.CompilerServices; | ||
|
||
[assembly: InternalsVisibleTo("QFXparser.Testing")] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using System; | ||
|
||
namespace QFXparser | ||
{ | ||
public class LedgerBalance | ||
{ | ||
public decimal Amount { get; set; } | ||
|
||
public DateTime AsOf { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace QFXparser | ||
{ | ||
internal static class ParsingHelper | ||
{ | ||
private static readonly Regex _dateTimeRegex = new Regex( | ||
"^(?<year>\\d{4})(?<month>\\d{2})(?<day>\\d{2})(?<hour>\\d{2})(?<min>\\d{2})(?<sec>\\d{2})(\\[(?<tzId>\\d+):(?<timezone>\\w{3})\\])?"); | ||
|
||
public static DateTime? ParseDate(string content) | ||
{ | ||
DateTime? result; | ||
var match = _dateTimeRegex.Match(content); | ||
if (!match.Success) | ||
{ | ||
result = null; | ||
} | ||
else | ||
{ | ||
var groups = match.Groups; | ||
var year = int.Parse(groups["year"].Value); | ||
var month = int.Parse(groups["month"].Value); | ||
var day = int.Parse(groups["day"].Value); | ||
var hour = int.Parse(groups["hour"].Value); | ||
var minute = int.Parse(groups["min"].Value); | ||
var second = int.Parse(groups["sec"].Value); | ||
var timeZone = groups["timezone"].Success ? groups["timezone"].Value : "UTC"; | ||
|
||
var timeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZone); | ||
result = new DateTimeOffset(year, month, day, hour, minute, second, timeZoneInfo.BaseUtcOffset).ToUniversalTime().DateTime; | ||
} | ||
return result; | ||
} | ||
} | ||
} |
Oops, something went wrong.