Giuliano Paschoalino 606b841435 feat: Add ComplianceNFs.Infrastructure.Tests project and implement unit tests for various services
- Added ComplianceNFs.Infrastructure.Tests project to the solution.
- Implemented unit tests for AccessDbRepository, ArchivingService, AttachmentRepository, InvoiceIngestionService, MailListener, MonitorViewModel, and Worker.
- Enhanced existing tests with additional assertions and mock setups.
- Updated TODOs and roadmap documentation to reflect changes in service implementations and testing coverage.
- Modified ComplianceNFs.sln to include new test project and adjust solution properties.
2025-06-18 16:34:44 -03:00

43 lines
1.7 KiB
C#

using System.IO;
using System.Text.RegularExpressions;
using ComplianceNFs.Core.Entities;
using ComplianceNFs.Core.Ports;
namespace ComplianceNFs.Infrastructure.Parsers
{
public class PdfParser : IPdfParser
{
private readonly Regex CnpjCompRegex = GeneratedRegex("CNPJComp: (\\d{14})");
private readonly Regex CnpjVendRegex = GeneratedRegex("CNPJVend: (\\d{14})");
private readonly Regex MontNFRegex = GeneratedRegex("MontNF: ([\\d,.]+)");
private readonly Regex PrecNFRegex = GeneratedRegex("PrecNF: ([\\d,.]+)");
public ParsedInvoice Parse(Stream pdfStream)
{
// Minimal demo: just read bytes as text (replace with real PDF parsing in production)
using var ms = new MemoryStream();
pdfStream.CopyTo(ms);
var text = System.Text.Encoding.UTF8.GetString(ms.ToArray());
// Example: extract CNPJ and values using regex (replace with real patterns)
var cnpjComp = CnpjCompRegex.Match(text).Groups[1].Value;
var cnpjVend = CnpjVendRegex.Match(text).Groups[1].Value;
var montNF = decimal.TryParse(MontNFRegex.Match(text).Groups[1].Value, out var m) ? m : 0;
var precNF = decimal.TryParse(PrecNFRegex.Match(text).Groups[1].Value, out var p) ? p : 0;
return new ParsedInvoice
{
CnpjComp = cnpjComp,
CnpjVend = cnpjVend,
MontNF = montNF,
PrecNF = precNF
// ...fill other fields as needed
};
}
public static Regex GeneratedRegex(string pattern)
{
return new Regex(pattern);
}
}
}