Files
SongTidy/SongTidy.Tests/Models/RenameFormatsTests.cs
T

138 lines
4.3 KiB
C#

using SongTidy.Models;
namespace SongTidy.Tests.Models;
/// <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");
}
#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}.");
}
}