public ReceiptFormat ParseReceiptFormat(ReceiptDataIn receipt) { if (receipt == null) { throw new ArgumentNullException("receipt"); } if (string.IsNullOrWhiteSpace(receipt.RawText)) { throw new ArgumentException("receipt.RawText is null or white space"); } var rawText = receipt.RawText; string[] lines = rawText.Split('\n'); if (lines.Length >= 3) { if (lines[0].StartsWith("ABC") && lines[2].StartsWith("KORTTIAUTOMAATTI")) { return(ReceiptFormat.Fuel_Abc); } } return(ReceiptFormat.Unknown); }
public void UnknownReceiptTwo_ShouldParseFormat() { var input = new ReceiptDataIn(_testCtx.Unknown_Smarket_Kaukajarvi_2016_10_19.Receipt); var actual = _parser.ParseReceiptFormat(input); Assert.AreEqual(ReceiptFormat.Unknown, actual); }
public void UnknownReceipt_ShouldParseFormat() { var input = new ReceiptDataIn(_testCtx.Unknown_Prisma_Kaleva_Tampere_2016_10_21.Receipt); var actual = _parser.ParseReceiptFormat(input); Assert.AreEqual(ReceiptFormat.Unknown, actual); }
public void KnownReceipt_ShouldParse_Date() { var testData = _testCtx.Fuel_Abc_Prisma_Kaleva_Tampere_2016_10_19; var input = new ReceiptDataIn(_testCtx.Fuel_Abc_Prisma_Kaleva_Tampere_2016_10_19.Receipt); var actual = _parser.ParseReceipt(input); Assert.AreEqual(testData.Date, actual.Date); }
public void KnownReceipt_ShouldParse_Price() { var testData = _testCtx.Fuel_Abc_Prisma_Kaleva_Tampere_2016_10_19; var input = new ReceiptDataIn(_testCtx.Fuel_Abc_Prisma_Kaleva_Tampere_2016_10_19.Receipt); var actual = _parser.ParseReceipt(input); AssertWithEpsilon(testData.Price.Value, actual.Eur.Value, _epsilon); }
public ParseResult ProcessBytes(byte[] bytes) { var pdfAsText = ParseBytesAsPdf(_ctx, bytes); var receiptInput = new ReceiptDataIn(pdfAsText.RawText); var format = ParseReceiptFormat(_ctx, receiptInput); var receiptData = ParseReceipt(_ctx, format, receiptInput); return(new ParseResult(pdfAsText, receiptData)); }
public FuelReceiptData ParseReceipt(ReceiptDataIn receipt) { if (receipt == null) { throw new ArgumentNullException("receipt"); } if (string.IsNullOrWhiteSpace(receipt.RawText)) { throw new ArgumentException("receipt.RawText is null or white space"); } var rawTextNormalizedSpaces = _utfNonBreakingSpace.Replace(receipt.RawText, " "); string[] lines = rawTextNormalizedSpaces.Split('\n'); if (lines.Length < 11) { throw new ArgumentException("receipt content incomplete or unrecognized format"); } FuelReceiptData data = ParseReceiptLines(lines); return(data); }
public void EmptyReceipt_ShouldThrow() { var emptyReceipt = new ReceiptDataIn(""); Assert.Throws <ArgumentException>(() => _parser.ParseReceiptFormat(emptyReceipt)); }
public void NotSupportedReceipt_CompletelyDifferent_ShouldThrow() { var input = new ReceiptDataIn(_testCtx.Unknown_Smarket_Kaukajarvi_2016_10_19.Receipt); Assert.Throws <ReceiptParseException>(() => _parser.ParseReceipt(input)); }
public void NotSupportedReceipt_Similar_ShouldThrow() { var input = new ReceiptDataIn(_testCtx.Unknown_Prisma_Kaleva_Tampere_2016_10_21.Receipt); Assert.Throws <ReceiptParseException>(() => _parser.ParseReceipt(input)); }
private static FuelReceiptData ParseReceipt(Context ctx, ReceiptFormat format, ReceiptDataIn receiptInput) { switch (format) { case ReceiptFormat.Fuel_Abc: return(ctx.FuelReceiptParser.ParseReceipt(receiptInput)); default: throw new Exception(string.Format( "Unsupported receipt format. Input:\n{0}", receiptInput.RawText)); } }
private static ReceiptFormat ParseReceiptFormat(Context ctx, ReceiptDataIn receiptInput) { return(ctx.ReceiptFormatParser.ParseReceiptFormat(receiptInput)); }