2021-11-09 12:48:05 +00:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Extensions;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
using osu.Game.Scoring;
|
|
|
|
using osu.Game.Users;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Models
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
public class DisplayStringTest
|
|
|
|
{
|
2021-11-12 06:25:59 +00:00
|
|
|
[Test]
|
|
|
|
public void TestNull()
|
|
|
|
{
|
|
|
|
IBeatmapSetInfo? beatmap = null;
|
|
|
|
Assert.That(beatmap.GetDisplayString(), Is.EqualTo("null"));
|
|
|
|
}
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
[Test]
|
|
|
|
public void TestBeatmapSet()
|
2021-11-10 09:27:23 +00:00
|
|
|
{
|
|
|
|
var mock = new Mock<IBeatmapSetInfo>();
|
|
|
|
|
2021-11-24 06:01:45 +00:00
|
|
|
mock.Setup(m => m.Metadata.Artist).Returns("artist");
|
|
|
|
mock.Setup(m => m.Metadata.Title).Returns("title");
|
|
|
|
mock.Setup(m => m.Metadata.Author.Username).Returns("author");
|
2021-11-10 09:27:23 +00:00
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author)"));
|
2021-11-10 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
[Test]
|
|
|
|
public void TestBeatmapSetWithNoAuthor()
|
2021-11-10 09:27:23 +00:00
|
|
|
{
|
|
|
|
var mock = new Mock<IBeatmapSetInfo>();
|
|
|
|
|
2021-11-24 06:01:45 +00:00
|
|
|
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);
|
2021-11-10 09:27:23 +00:00
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title"));
|
2021-11-10 09:27:23 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
[Test]
|
|
|
|
public void TestBeatmapSetWithNoMetadata()
|
2021-11-09 12:48:05 +00:00
|
|
|
{
|
|
|
|
var mock = new Mock<IBeatmapSetInfo>();
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
mock.Setup(m => m.Metadata).Returns(new BeatmapMetadata());
|
2021-11-09 12:48:05 +00:00
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("unknown artist - unknown title"));
|
2021-11-09 12:48:05 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
[Test]
|
|
|
|
public void TestBeatmap()
|
2021-11-09 12:48:05 +00:00
|
|
|
{
|
|
|
|
var mock = new Mock<IBeatmapInfo>();
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
mock.Setup(m => m.Metadata.Artist).Returns("artist");
|
|
|
|
mock.Setup(m => m.Metadata.Title).Returns("title");
|
|
|
|
mock.Setup(m => m.Metadata.Author.Username).Returns("author");
|
2021-11-09 12:48:05 +00:00
|
|
|
mock.Setup(m => m.DifficultyName).Returns("difficulty");
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author) [difficulty]"));
|
2021-11-09 12:48:05 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
[Test]
|
|
|
|
public void TestMetadata()
|
2021-11-09 12:48:05 +00:00
|
|
|
{
|
|
|
|
var mock = new Mock<IBeatmapMetadataInfo>();
|
|
|
|
|
|
|
|
mock.Setup(m => m.Artist).Returns("artist");
|
|
|
|
mock.Setup(m => m.Title).Returns("title");
|
|
|
|
mock.Setup(m => m.Author.Username).Returns("author");
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author)"));
|
2021-11-09 12:48:05 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
[Test]
|
|
|
|
public void TestScore()
|
2021-11-09 12:48:05 +00:00
|
|
|
{
|
|
|
|
var mock = new Mock<IScoreInfo>();
|
|
|
|
|
|
|
|
mock.Setup(m => m.User).Returns(new APIUser { Username = "user" }); // TODO: temporary.
|
2021-11-10 10:09:09 +00:00
|
|
|
mock.Setup(m => m.Beatmap.Metadata.Artist).Returns("artist");
|
|
|
|
mock.Setup(m => m.Beatmap.Metadata.Title).Returns("title");
|
|
|
|
mock.Setup(m => m.Beatmap.Metadata.Author.Username).Returns("author");
|
|
|
|
mock.Setup(m => m.Beatmap.DifficultyName).Returns("difficulty");
|
2021-11-09 12:48:05 +00:00
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("user playing artist - title (author) [difficulty]"));
|
2021-11-09 12:48:05 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
[Test]
|
|
|
|
public void TestRuleset()
|
2021-11-09 12:48:05 +00:00
|
|
|
{
|
|
|
|
var mock = new Mock<IRulesetInfo>();
|
|
|
|
|
|
|
|
mock.Setup(m => m.Name).Returns("ruleset");
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("ruleset"));
|
2021-11-09 12:48:05 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
[Test]
|
|
|
|
public void TestUser()
|
2021-11-09 12:48:05 +00:00
|
|
|
{
|
|
|
|
var mock = new Mock<IUser>();
|
|
|
|
|
|
|
|
mock.Setup(m => m.Username).Returns("user");
|
|
|
|
|
2021-11-10 10:09:09 +00:00
|
|
|
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("user"));
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestFallback()
|
|
|
|
{
|
|
|
|
var fallback = new Fallback();
|
|
|
|
|
|
|
|
Assert.That(fallback.GetDisplayString(), Is.EqualTo("fallback"));
|
2021-11-09 12:48:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private class Fallback
|
|
|
|
{
|
|
|
|
public override string ToString() => "fallback";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|