feat: add rename format registry
This commit is contained in:
1 parent
d6677b323b
commit
c0c6e0a38f
2 files changed
+282
No files matched your search
@@ -0,0 +1,146 @@
|
||||
using SongTidy.Models;
|
||||
|
||||
namespace SongTidy.Tests;
|
||||
|
||||
/// <summary>
|
||||
/// Contains tests for <see cref="RenameFormats"/>.
|
||||
/// </summary>
|
||||
[TestClass]
|
||||
public sealed class RenameFormatsTests {
|
||||
#region Artist-first format
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the artist-first layout when both optional fields are present.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GeneratesArtistFirstWithArtistAndComment() {
|
||||
AssertStem(RenameFormat.ArtistFirst, "Artist", "Title", "Live", "Artist - Title (Live)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the artist-first layout when only the artist is present.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GeneratesArtistFirstWithArtistOnly() {
|
||||
AssertStem(RenameFormat.ArtistFirst, "Artist", "Title", string.Empty, "Artist - Title");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the artist-first layout when only the comment is present.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GeneratesArtistFirstWithCommentOnly() {
|
||||
AssertStem(RenameFormat.ArtistFirst, string.Empty, "Title", "Live", "Title (Live)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the artist-first layout when neither optional field is present.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GeneratesArtistFirstWithTitleOnly() {
|
||||
AssertStem(RenameFormat.ArtistFirst, string.Empty, "Title", string.Empty, "Title");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Title-first format
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the title-first layout when both optional fields are present.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GeneratesTitleFirstWithArtistAndComment() {
|
||||
AssertStem(RenameFormat.TitleFirst, "Artist", "Title", "Live", "Title (Live) - Artist");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the title-first layout when only the artist is present.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GeneratesTitleFirstWithArtistOnly() {
|
||||
AssertStem(RenameFormat.TitleFirst, "Artist", "Title", string.Empty, "Title - Artist");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the title-first layout when only the comment is present.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GeneratesTitleFirstWithCommentOnly() {
|
||||
AssertStem(RenameFormat.TitleFirst, string.Empty, "Title", "Live", "Title (Live)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the title-first layout when neither optional field is present.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void GeneratesTitleFirstWithTitleOnly() {
|
||||
AssertStem(RenameFormat.TitleFirst, string.Empty, "Title", string.Empty, "Title");
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Registry
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that every enum member has a registered format definition.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void RegistersEveryFormat() {
|
||||
foreach (RenameFormat format in Enum.GetValues<RenameFormat>()) {
|
||||
Assert.IsTrue(
|
||||
RenameFormats.Definitions.ContainsKey(format),
|
||||
$"Missing definition for {format}.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that an unregistered enum value is rejected.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void ThrowsForUnregisteredFormat() {
|
||||
Assert.Throws<ArgumentOutOfRangeException>(
|
||||
() => RenameFormats.GenerateStem((RenameFormat)999, "Artist", "Title", "Live"));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Edge cases
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that whitespace-only optional fields are treated as missing.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void TreatsWhitespaceOnlyOptionalFieldsAsMissing() {
|
||||
AssertStem(RenameFormat.ArtistFirst, " ", "Title", "\t", "Title");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies that a null title is rejected.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
public void ThrowsForNullTitle() {
|
||||
Assert.Throws<ArgumentNullException>(
|
||||
() => RenameFormats.GenerateStem(RenameFormat.ArtistFirst, "Artist", null!, "Live"));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Generates a file name stem and asserts the result.
|
||||
/// </summary>
|
||||
/// <param name="format">The format to apply.</param>
|
||||
/// <param name="artist">The artist value.</param>
|
||||
/// <param name="title">The title value.</param>
|
||||
/// <param name="comment">The comment value.</param>
|
||||
/// <param name="expected">The expected generated stem.</param>
|
||||
private static void AssertStem(
|
||||
RenameFormat format,
|
||||
string artist,
|
||||
string title,
|
||||
string comment,
|
||||
string expected) {
|
||||
string actual = RenameFormats.GenerateStem(format, artist, title, comment);
|
||||
|
||||
Assert.AreEqual(expected, actual, $"Unexpected stem for {format}.");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user