mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 15:22:55 +08:00
Add fallback for cases where beatmap has no author/title/artist specified
This commit is contained in:
parent
03a315b9f5
commit
f4ef841972
@ -17,6 +17,8 @@ namespace osu.Game.Tests.Models
|
|||||||
{
|
{
|
||||||
private static readonly object[][] test_cases =
|
private static readonly object[][] test_cases =
|
||||||
{
|
{
|
||||||
|
new object[] { makeNoMetadataMockBeatmapSet(), "unknown artist - unknown title" },
|
||||||
|
new object[] { makeNoAuthorMockBeatmapSet(), "artist - title" },
|
||||||
new object[] { makeMockBeatmapSet(), "artist - title (author)" },
|
new object[] { makeMockBeatmapSet(), "artist - title (author)" },
|
||||||
new object[] { makeMockBeatmap(), "artist - title (author) [difficulty]" },
|
new object[] { makeMockBeatmap(), "artist - title (author) [difficulty]" },
|
||||||
new object[] { makeMockMetadata(), "artist - title (author)" },
|
new object[] { makeMockMetadata(), "artist - title (author)" },
|
||||||
@ -29,6 +31,26 @@ namespace osu.Game.Tests.Models
|
|||||||
[TestCaseSource(nameof(test_cases))]
|
[TestCaseSource(nameof(test_cases))]
|
||||||
public void TestDisplayString(object model, string expected) => Assert.That(model.GetDisplayString(), Is.EqualTo(expected));
|
public void TestDisplayString(object model, string expected) => Assert.That(model.GetDisplayString(), Is.EqualTo(expected));
|
||||||
|
|
||||||
|
private static IBeatmapSetInfo makeNoAuthorMockBeatmapSet()
|
||||||
|
{
|
||||||
|
var mock = new Mock<IBeatmapSetInfo>();
|
||||||
|
|
||||||
|
mock.Setup(m => m.Metadata.Artist).Returns("artist");
|
||||||
|
mock.Setup(m => m.Metadata.Title).Returns("title");
|
||||||
|
mock.Setup(m => m.Metadata.Author.Username).Returns(string.Empty);
|
||||||
|
|
||||||
|
return mock.Object;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IBeatmapSetInfo makeNoMetadataMockBeatmapSet()
|
||||||
|
{
|
||||||
|
var mock = new Mock<IBeatmapSetInfo>();
|
||||||
|
|
||||||
|
mock.Setup(m => m.Metadata).Returns(new BeatmapMetadata());
|
||||||
|
|
||||||
|
return mock.Object;
|
||||||
|
}
|
||||||
|
|
||||||
private static IBeatmapSetInfo makeMockBeatmapSet()
|
private static IBeatmapSetInfo makeMockBeatmapSet()
|
||||||
{
|
{
|
||||||
var mock = new Mock<IBeatmapSetInfo>();
|
var mock = new Mock<IBeatmapSetInfo>();
|
||||||
|
@ -27,8 +27,12 @@ namespace osu.Game.Beatmaps
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static string GetDisplayTitle(this IBeatmapMetadataInfo metadataInfo)
|
public static string GetDisplayTitle(this IBeatmapMetadataInfo metadataInfo)
|
||||||
{
|
{
|
||||||
string author = string.IsNullOrEmpty(metadataInfo.Author.Username) ? string.Empty : $"({metadataInfo.Author.Username})";
|
string author = string.IsNullOrEmpty(metadataInfo.Author.Username) ? string.Empty : $" ({metadataInfo.Author.Username})";
|
||||||
return $"{metadataInfo.Artist} - {metadataInfo.Title} {author}".Trim();
|
|
||||||
|
string artist = string.IsNullOrEmpty(metadataInfo.Artist) ? "unknown artist" : metadataInfo.Artist;
|
||||||
|
string title = string.IsNullOrEmpty(metadataInfo.Title) ? "unknown title" : metadataInfo.Title;
|
||||||
|
|
||||||
|
return $"{artist} - {title}{author}".Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user