namespace OCES.Resonance.Core.Tests;

/// <summary>
/// AudioFileScanner 单元测试
/// </summary>
public class AudioFileScannerTests
{
    [Theory]
    [InlineData("test.wav", true)]
    [InlineData("test.WAV", true)]
    [InlineData("test.mp3", true)]
    [InlineData("test.txt", false)]
    [InlineData("", false)]
    [InlineData("test.xlsx", false)]
    public void IsSupportedAudioFile_ShouldWork(string input, bool expected)
    {
        AudioFileScanner scanner = new();

        bool result = scanner.IsSupportedAudioFile(input);

        Assert.Equal(expected, result);
    }
    
    [Fact]
    public void ScanDirectory_ShouldWork()
    {
        string tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
        Directory.CreateDirectory(tempDir);

        try
        {
            // 构造真实文件
            File.WriteAllText(Path.Combine(tempDir, "a.wav"), "");
            File.WriteAllText(Path.Combine(tempDir, "b.MP3"), "");
            File.WriteAllText(Path.Combine(tempDir, "c.txt"), "");
            File.WriteAllText(Path.Combine(tempDir, "d.xlsx"), "");
            File.WriteAllText(Path.Combine(tempDir, "e.WAV"), "");

            AudioFileScanner scanner = new();

            List<string> result = scanner.ScanDirectory(tempDir).ToList();

            Assert.Equal(3, result.Count);
        }
        finally
        {
            Directory.Delete(tempDir, true);
        }
    }
    
    [Fact]
    public void ScanDirectory_ShouldThrow_WhenDirectoryDoesNotExist()
    { 
        AudioFileScanner scanner = new();
        string nonExistentPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
        
        Assert.Throws<DirectoryNotFoundException>(() => scanner.ScanDirectory(nonExistentPath));
    }
}
