88 lines
2.8 KiB
C#
88 lines
2.8 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 };
|
|
|
|
archiver.ArchiveAsync(invoice);
|
|
|
|
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 data2 = new byte[] { 9, 8, 7 };
|
|
|
|
archiver.ArchiveAsync(invoice);
|
|
archiver.ArchiveAsync(invoice);
|
|
|
|
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);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|
|
|
|
public class UnitTest1
|
|
{
|
|
[Fact]
|
|
public void Test1()
|
|
{
|
|
|
|
}
|
|
}
|
|
} |