refactor: organize test project structure
This commit is contained in:
1 parent
996c0a9515
commit
c6d16fd108
8 files changed
+106
-94
No files matched your search
@@ -0,0 +1,65 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using SongTidy.Services;
|
||||
using SongTidy.Tests.TestUtilities;
|
||||
|
||||
namespace SongTidy.Tests.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Contains tests for <see cref="AudioFileScanner"/>.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed class AudioFileScannerTests {
|
||||
private readonly TempDirectory _tempDirectory = new();
|
||||
|
||||
/// <summary>
|
||||
/// Removes the temporary directory created for the current test.
|
||||
/// </summary>
|
||||
[TestCleanup]
|
||||
public void Cleanup() {
|
||||
_tempDirectory.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that supported extensions are matched case-insensitively and others are ignored.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void ScansSupportedExtensionsCaseInsensitively() {
|
||||
CreateFile("a.mp3");
|
||||
CreateFile("b.FLAC");
|
||||
CreateFile("c.txt");
|
||||
|
||||
IReadOnlyList<string> files = AudioFileScanner.Scan(_tempDirectory.FullPath);
|
||||
|
||||
Assert.HasCount(2, files);
|
||||
Assert.IsTrue(files.Any(file => file.EndsWith("a.mp3", StringComparison.OrdinalIgnoreCase)));
|
||||
Assert.IsTrue(files.Any(file => file.EndsWith("b.FLAC", StringComparison.OrdinalIgnoreCase)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that subdirectories are not scanned.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void DoesNotScanSubdirectories() {
|
||||
CreateFile("root.mp3");
|
||||
CreateFile(Path.Combine("sub", "nested.wav"));
|
||||
|
||||
IReadOnlyList<string> files = AudioFileScanner.Scan(_tempDirectory.FullPath);
|
||||
|
||||
Assert.HasCount(1, files);
|
||||
Assert.IsTrue(files[0].EndsWith("root.mp3", StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates an empty file inside the test directory.
|
||||
/// </summary>
|
||||
/// <param name="fileName">The relative file name, which may include a subdirectory.</param>
|
||||
private void CreateFile(string fileName) {
|
||||
string path = Path.Combine(_tempDirectory.FullPath, fileName);
|
||||
string directory = Path.GetDirectoryName(path) ?? _tempDirectory.FullPath;
|
||||
|
||||
Directory.CreateDirectory(directory);
|
||||
File.WriteAllText(path, string.Empty);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user