1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-21 16:33:21 +08:00
osu-lazer/osu.Game.Tests/Models/DisplayStringTest.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

134 lines
4.1 KiB
C#
Raw Normal View History

// 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;
#nullable enable
namespace osu.Game.Tests.Models
{
[TestFixture]
public class DisplayStringTest
{
[Test]
public void TestNull()
{
IBeatmapSetInfo? beatmap = null;
Assert.That(beatmap.GetDisplayString(), Is.EqualTo("null"));
}
2021-11-10 18:09:09 +08:00
[Test]
public void TestBeatmapSet()
{
var mock = new Mock<IBeatmapSetInfo>();
2021-11-24 14:01:45 +08: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 18:09:09 +08:00
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author)"));
}
2021-11-10 18:09:09 +08:00
[Test]
public void TestBeatmapSetWithNoAuthor()
{
var mock = new Mock<IBeatmapSetInfo>();
2021-11-24 14:01:45 +08: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 18:09:09 +08:00
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title"));
}
2021-11-10 18:09:09 +08:00
[Test]
public void TestBeatmapSetWithNoMetadata()
{
var mock = new Mock<IBeatmapSetInfo>();
2021-11-10 18:09:09 +08:00
mock.Setup(m => m.Metadata).Returns(new BeatmapMetadata());
2021-11-10 18:09:09 +08:00
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("unknown artist - unknown title"));
}
2021-11-10 18:09:09 +08:00
[Test]
public void TestBeatmap()
{
var mock = new Mock<IBeatmapInfo>();
2021-11-10 18:09:09 +08: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");
mock.Setup(m => m.DifficultyName).Returns("difficulty");
2021-11-10 18:09:09 +08:00
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author) [difficulty]"));
}
2021-11-10 18:09:09 +08:00
[Test]
public void TestMetadata()
{
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 18:09:09 +08:00
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author)"));
}
2021-11-10 18:09:09 +08:00
[Test]
public void TestScore()
{
var mock = new Mock<IScoreInfo>();
mock.Setup(m => m.User).Returns(new APIUser { Username = "user" }); // TODO: temporary.
2021-11-10 18:09:09 +08: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-10 18:09:09 +08:00
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("user playing artist - title (author) [difficulty]"));
}
2021-11-10 18:09:09 +08:00
[Test]
public void TestRuleset()
{
var mock = new Mock<IRulesetInfo>();
mock.Setup(m => m.Name).Returns("ruleset");
2021-11-10 18:09:09 +08:00
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("ruleset"));
}
2021-11-10 18:09:09 +08:00
[Test]
public void TestUser()
{
var mock = new Mock<IUser>();
mock.Setup(m => m.Username).Returns("user");
2021-11-10 18:09:09 +08:00
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("user"));
}
[Test]
public void TestFallback()
{
var fallback = new Fallback();
Assert.That(fallback.GetDisplayString(), Is.EqualTo("fallback"));
}
private class Fallback
{
public override string ToString() => "fallback";
}
}
}