using SongTidy.Models;
namespace SongTidy.Tests.Models;
///
/// Contains tests for .
///
[TestClass]
public sealed class RenameFormatsTests {
#region Artist-first format
///
/// Verifies the artist-first layout when both optional fields are present.
///
[TestMethod]
public void GeneratesArtistFirstWithArtistAndComment() {
AssertStem(RenameFormat.ArtistFirst, "Artist", "Title", "Live", "Artist - Title (Live)");
}
///
/// Verifies the artist-first layout when only the artist is present.
///
[TestMethod]
public void GeneratesArtistFirstWithArtistOnly() {
AssertStem(RenameFormat.ArtistFirst, "Artist", "Title", string.Empty, "Artist - Title");
}
///
/// Verifies the artist-first layout when only the comment is present.
///
[TestMethod]
public void GeneratesArtistFirstWithCommentOnly() {
AssertStem(RenameFormat.ArtistFirst, string.Empty, "Title", "Live", "Title (Live)");
}
///
/// Verifies the artist-first layout when neither optional field is present.
///
[TestMethod]
public void GeneratesArtistFirstWithTitleOnly() {
AssertStem(RenameFormat.ArtistFirst, string.Empty, "Title", string.Empty, "Title");
}
#endregion
#region Title-first format
///
/// Verifies the title-first layout when both optional fields are present.
///
[TestMethod]
public void GeneratesTitleFirstWithArtistAndComment() {
AssertStem(RenameFormat.TitleFirst, "Artist", "Title", "Live", "Title (Live) - Artist");
}
///
/// Verifies the title-first layout when only the artist is present.
///
[TestMethod]
public void GeneratesTitleFirstWithArtistOnly() {
AssertStem(RenameFormat.TitleFirst, "Artist", "Title", string.Empty, "Title - Artist");
}
///
/// Verifies the title-first layout when only the comment is present.
///
[TestMethod]
public void GeneratesTitleFirstWithCommentOnly() {
AssertStem(RenameFormat.TitleFirst, string.Empty, "Title", "Live", "Title (Live)");
}
///
/// Verifies the title-first layout when neither optional field is present.
///
[TestMethod]
public void GeneratesTitleFirstWithTitleOnly() {
AssertStem(RenameFormat.TitleFirst, string.Empty, "Title", string.Empty, "Title");
}
#endregion
#region Registry
///
/// Verifies that every enum member has a registered format definition.
///
[TestMethod]
public void RegistersEveryFormat() {
foreach (RenameFormat format in Enum.GetValues()) {
Assert.IsTrue(
RenameFormats.Definitions.ContainsKey(format),
$"Missing definition for {format}.");
}
}
///
/// Verifies that an unregistered enum value is rejected.
///
[TestMethod]
public void ThrowsForUnregisteredFormat() {
Assert.Throws(
() => RenameFormats.GenerateStem((RenameFormat)999, "Artist", "Title", "Live"));
}
#endregion
#region Edge cases
///
/// Verifies that whitespace-only optional fields are treated as missing.
///
[TestMethod]
public void TreatsWhitespaceOnlyOptionalFieldsAsMissing() {
AssertStem(RenameFormat.ArtistFirst, " ", "Title", "\t", "Title");
}
#endregion
///
/// Generates a file name stem and asserts the result.
///
/// The format to apply.
/// The artist value.
/// The title value.
/// The comment value.
/// The expected generated stem.
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}.");
}
}