feat: Basic core feature implementation.
- Add Database integrated test. - Fix AudioFileScannerTests.cs namepsace.
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
namespace OCES.Resonance.Core.Tests;
|
using OCES.Resonance.Core;
|
||||||
|
|
||||||
|
namespace Core.Tests;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// AudioFileScanner 单元测试
|
/// AudioFileScanner 单元测试
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
using System.Data.SQLite;
|
||||||
|
using Dapper;
|
||||||
|
using OCES.Resonance.Core;
|
||||||
|
|
||||||
|
namespace Core.Tests;
|
||||||
|
|
||||||
|
public class IntegratedTest
|
||||||
|
{
|
||||||
|
private static readonly string _dataSourceRoot = "/Volumes/Library/Boom Library/Boom Library - Alien Life/Alien_Life_DS";
|
||||||
|
|
||||||
|
private static string GetWavDir(string vendor)
|
||||||
|
{
|
||||||
|
string dir = Path.Combine(_dataSourceRoot, vendor);
|
||||||
|
return Directory.Exists(dir) ? dir : string.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetDefaultDbPath() =>
|
||||||
|
Path.Combine(PreferencesManager.GetDefaultDatabasePath(), "default.rdb");
|
||||||
|
|
||||||
|
private static void DeleteTestEntries(params string[] uniqueIds)
|
||||||
|
{
|
||||||
|
using var conn = new SQLiteConnection($"Data Source={GetDefaultDbPath()};Version=3;");
|
||||||
|
conn.Open();
|
||||||
|
foreach (var uid in uniqueIds)
|
||||||
|
conn.Execute("DELETE FROM audio_files WHERE unique_id = @UniqueId", new { UniqueId = uid });
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ScanReadWritePipeline_ShouldGenerateDatabase()
|
||||||
|
{
|
||||||
|
string sourceDir = _dataSourceRoot;
|
||||||
|
if (string.IsNullOrEmpty(sourceDir))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var scanner = new AudioFileScanner();
|
||||||
|
var reader = new AudioMetadataReader();
|
||||||
|
string[] wavFiles = scanner.ScanDirectory(sourceDir, recursive: true)
|
||||||
|
.Where(f => f.EndsWith(".wav", StringComparison.OrdinalIgnoreCase))
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
if (wavFiles.Length == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var metaList = wavFiles.Select(f => reader.ReadMetadata(new FileInfo(f))).ToList();
|
||||||
|
|
||||||
|
Database.InitializeDatabase();
|
||||||
|
int insertedCount = Database.AddEntries(metaList);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Assert.Equal(wavFiles.Length, insertedCount);
|
||||||
|
|
||||||
|
foreach (var meta in metaList)
|
||||||
|
{
|
||||||
|
var retrieved = Database.GetEntryByUniqueId(meta.UniqueId);
|
||||||
|
Assert.NotNull(retrieved);
|
||||||
|
|
||||||
|
Assert.Equal(meta.Md5, retrieved!.Md5);
|
||||||
|
Assert.Equal(meta.Path, retrieved.Path);
|
||||||
|
Assert.Equal(meta.Filename, retrieved.Filename);
|
||||||
|
Assert.Equal(meta.Duration, retrieved.Duration);
|
||||||
|
Assert.Equal(meta.BitDepth, retrieved.BitDepth);
|
||||||
|
Assert.Equal(meta.Channels, retrieved.Channels);
|
||||||
|
Assert.Equal(meta.SampleRate, retrieved.SampleRate);
|
||||||
|
Assert.Equal(meta.Type, retrieved.Type);
|
||||||
|
|
||||||
|
if (meta.Artwork != null)
|
||||||
|
Assert.NotNull(retrieved.Artwork);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
DeleteTestEntries(metaList.Select(m => m.UniqueId).ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -20,5 +20,7 @@
|
|||||||
<TestId>xUnit::24F92458-FB39-44BE-A32F-41275183AF1B::net10.0::Core.Tests.DatabaseTests.InitializeDatabase_ShouldCreateAudioFilesTable</TestId>
|
<TestId>xUnit::24F92458-FB39-44BE-A32F-41275183AF1B::net10.0::Core.Tests.DatabaseTests.InitializeDatabase_ShouldCreateAudioFilesTable</TestId>
|
||||||
<TestId>xUnit::24F92458-FB39-44BE-A32F-41275183AF1B::net10.0::Core.Tests.DatabaseTests.InitializeDatabase_ShouldBeIdempotent</TestId>
|
<TestId>xUnit::24F92458-FB39-44BE-A32F-41275183AF1B::net10.0::Core.Tests.DatabaseTests.InitializeDatabase_ShouldBeIdempotent</TestId>
|
||||||
<TestId>xUnit::24F92458-FB39-44BE-A32F-41275183AF1B::net10.0::Core.Tests.DatabaseTests</TestId>
|
<TestId>xUnit::24F92458-FB39-44BE-A32F-41275183AF1B::net10.0::Core.Tests.DatabaseTests</TestId>
|
||||||
|
<TestId>xUnit::24F92458-FB39-44BE-A32F-41275183AF1B::net10.0::Core.Tests.IntegratedTest.ScanReadWritePipeline_ShouldGenerateDatabase</TestId>
|
||||||
|
<TestId>xUnit::24F92458-FB39-44BE-A32F-41275183AF1B::net10.0::Core.Tests.IntegratedTest</TestId>
|
||||||
</TestAncestor>
|
</TestAncestor>
|
||||||
</SessionState></s:String></wpf:ResourceDictionary>
|
</SessionState></s:String></wpf:ResourceDictionary>
|
||||||
Reference in New Issue
Block a user