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

88 lines
2.9 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
{
MailId = "test-mail-id",
ConversationId = "test-conv-id",
SupplierEmail = "test@supplier.com",
Filename = "testfile.txt",
Status = InvoiceStatus.Validated,
// Add required fields for null safety
ReceivedDate = DateTime.Now,
InvoiceId = 1
};
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
{
MailId = "test-mail-id",
ConversationId = "test-conv-id",
SupplierEmail = "test@supplier.com",
Filename = "testfile.txt",
Status = InvoiceStatus.Validated,
// Add required fields for null safety
ReceivedDate = DateTime.Now,
InvoiceId = 1
};
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()
{
}
}
}