- Created ComplianceNFs.Core project with domain entities and ports - Implemented BuyingRecord, EnergyInvoice, ParsedInvoice entities - Defined domain interfaces for mail listening, XML and PDF parsing, and repository access - Established ComplianceNFs.Infrastructure project with file archiving, mail listening, and data access implementations - Developed PDF and XML parsers for invoice data extraction - Set up AccessDbRepository and AttachmentRepository for data retrieval and storage - Created ComplianceNFs.Service project for background processing and service orchestration - Implemented Worker service for periodic tasks - Established ComplianceNFs.Monitor project with WPF UI for monitoring invoice statuses - Added ViewModel for UI data binding and command handling - Configured project files for .NET 9.0 and necessary package references - Created initial appsettings.json for configuration management - Added TODOs and roadmap for future development
76 lines
2.3 KiB
C#
76 lines
2.3 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
using ComplianceNFs.Core.Entities;
|
|
using ComplianceNFs.Infrastructure.Archiving;
|
|
using Xunit;
|
|
|
|
namespace ComplianceNFs.Infrastructure.Tests
|
|
{
|
|
public class FileArchiverTests : IDisposable
|
|
{
|
|
private readonly string _testBasePath;
|
|
public FileArchiverTests()
|
|
{
|
|
_testBasePath = Path.Combine(Path.GetTempPath(), "ComplianceNFsTestArchive");
|
|
if (Directory.Exists(_testBasePath))
|
|
Directory.Delete(_testBasePath, true);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ArchiveAsync_CreatesFolderAndWritesFile()
|
|
{
|
|
var archiver = new FileArchiver(_testBasePath);
|
|
var invoice = new EnergyInvoice
|
|
{
|
|
Filename = "testfile.txt",
|
|
Status = InvoiceStatus.Validated
|
|
};
|
|
var data = new byte[] { 1, 2, 3, 4 };
|
|
|
|
await archiver.ArchiveAsync(invoice, data);
|
|
|
|
var expectedFolder = Path.Combine(_testBasePath, "Validated");
|
|
var expectedFile = Path.Combine(expectedFolder, "testfile.txt");
|
|
Assert.True(Directory.Exists(expectedFolder));
|
|
Assert.True(File.Exists(expectedFile));
|
|
var fileData = await File.ReadAllBytesAsync(expectedFile);
|
|
Assert.Equal(data, fileData);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ArchiveAsync_OverwritesExistingFile()
|
|
{
|
|
var archiver = new FileArchiver(_testBasePath);
|
|
var invoice = new EnergyInvoice
|
|
{
|
|
Filename = "testfile.txt",
|
|
Status = InvoiceStatus.Validated
|
|
};
|
|
var data1 = new byte[] { 1, 2, 3 };
|
|
var data2 = new byte[] { 9, 8, 7 };
|
|
|
|
await archiver.ArchiveAsync(invoice, data1);
|
|
await archiver.ArchiveAsync(invoice, data2);
|
|
|
|
var expectedFile = Path.Combine(_testBasePath, "Validated", "testfile.txt");
|
|
var fileData = await File.ReadAllBytesAsync(expectedFile);
|
|
Assert.Equal(data2, fileData);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (Directory.Exists(_testBasePath))
|
|
Directory.Delete(_testBasePath, true);
|
|
}
|
|
}
|
|
|
|
public class UnitTest1
|
|
{
|
|
[Fact]
|
|
public void Test1()
|
|
{
|
|
|
|
}
|
|
}
|
|
} |