38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using NfProcessorApp.Services;
|
|
using Xunit;
|
|
|
|
namespace NfProcessorApp.Tests.Services
|
|
{
|
|
public class FileScannerTests
|
|
{
|
|
private readonly FileScanner _scanner = new();
|
|
|
|
[Fact]
|
|
public void ListFiles_InvalidFolder_ThrowsDirectoryNotFoundException()
|
|
{
|
|
Assert.Throws<DirectoryNotFoundException>(() => _scanner.ListFiles("nonexistent", [".xml"]).ToList());
|
|
}
|
|
|
|
[Fact]
|
|
public void ListFiles_FiltersByExtension_OnlyReturnsMatchingFiles()
|
|
{
|
|
// Arrange: create temporary folder with files
|
|
var temp = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
|
|
Directory.CreateDirectory(temp);
|
|
File.WriteAllText(Path.Combine(temp, "a.xml"), "");
|
|
File.WriteAllText(Path.Combine(temp, "b.pdf"), "");
|
|
File.WriteAllText(Path.Combine(temp, "c.txt"), "");
|
|
|
|
// Act
|
|
var result = _scanner.ListFiles(temp, [".xml", ".pdf"]).ToList();
|
|
|
|
// Assert
|
|
Assert.Contains(Path.Combine(temp, "a.xml"), result);
|
|
Assert.Contains(Path.Combine(temp, "b.pdf"), result);
|
|
Assert.DoesNotContain(Path.Combine(temp, "c.txt"), result);
|
|
|
|
// Cleanup
|
|
Directory.Delete(temp, true);
|
|
}
|
|
}
|
|
} |