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 = @"X:\Back\Controle NFs\NFs\temp\99451152,9268928 - procNFE52250318384740000134550020000065021906003771.xml", Status = InvoiceStatus.Validated, // Add required fields for null safety ReceivedDate = DateTime.Now, InvoiceId = 1 }; var data = await File.ReadAllBytesAsync(invoice.Filename); archiver.ArchiveAsync(invoice); var expectedFolder = Path.Combine(_testBasePath, "Validated"); var expectedFile = Path.Combine(expectedFolder, @"X:\Back\Controle NFs\NFs\temp\99451152,9268928 - procNFE52250318384740000134550020000065021906003771.xml"); 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 = @"X:\Back\Controle NFs\NFs\temp\99451152,9268928 - procNFE52250318384740000134550020000065021906003771.xml", Status = InvoiceStatus.Validated, // Add required fields for null safety ReceivedDate = DateTime.Now, InvoiceId = 1 }; var data2 = await File.ReadAllBytesAsync(invoice.Filename); archiver.ArchiveAsync(invoice); archiver.ArchiveAsync(invoice); var expectedFile = Path.Combine(_testBasePath, "Validated", @"X:\Back\Controle NFs\NFs\temp\99451152,9268928 - procNFE52250318384740000134550020000065021906003771.xml"); var fileData = await File.ReadAllBytesAsync(expectedFile); Assert.Equal(data2, fileData); } public void Dispose() { if (Directory.Exists(_testBasePath)) Directory.Delete(_testBasePath, true); GC.SuppressFinalize(this); } } public class UnitTest1 { [Fact] public void Test1() { } } }