Rewrite tests to be easier to follow

This commit is contained in:
Bartłomiej Dach 2021-11-10 11:09:09 +01:00
parent f4ef841972
commit a52d9363f9
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497

View File

@ -15,23 +15,20 @@ namespace osu.Game.Tests.Models
[TestFixture]
public class DisplayStringTest
{
private static readonly object[][] test_cases =
[Test]
public void TestBeatmapSet()
{
new object[] { makeNoMetadataMockBeatmapSet(), "unknown artist - unknown title" },
new object[] { makeNoAuthorMockBeatmapSet(), "artist - title" },
new object[] { makeMockBeatmapSet(), "artist - title (author)" },
new object[] { makeMockBeatmap(), "artist - title (author) [difficulty]" },
new object[] { makeMockMetadata(), "artist - title (author)" },
new object[] { makeMockScore(), "user playing artist - title (author) [difficulty]" },
new object[] { makeMockRuleset(), "ruleset" },
new object[] { makeMockUser(), "user" },
new object[] { new Fallback(), "fallback" }
};
var mock = new Mock<IBeatmapSetInfo>();
[TestCaseSource(nameof(test_cases))]
public void TestDisplayString(object model, string expected) => Assert.That(model.GetDisplayString(), Is.EqualTo(expected));
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");
private static IBeatmapSetInfo makeNoAuthorMockBeatmapSet()
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author)"));
}
[Test]
public void TestBeatmapSetWithNoAuthor()
{
var mock = new Mock<IBeatmapSetInfo>();
@ -39,38 +36,34 @@ namespace osu.Game.Tests.Models
mock.Setup(m => m.Metadata.Title).Returns("title");
mock.Setup(m => m.Metadata.Author.Username).Returns(string.Empty);
return mock.Object;
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title"));
}
private static IBeatmapSetInfo makeNoMetadataMockBeatmapSet()
[Test]
public void TestBeatmapSetWithNoMetadata()
{
var mock = new Mock<IBeatmapSetInfo>();
mock.Setup(m => m.Metadata).Returns(new BeatmapMetadata());
return mock.Object;
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("unknown artist - unknown title"));
}
private static IBeatmapSetInfo makeMockBeatmapSet()
{
var mock = new Mock<IBeatmapSetInfo>();
mock.Setup(m => m.Metadata).Returns(makeMockMetadata);
return mock.Object;
}
private static IBeatmapInfo makeMockBeatmap()
[Test]
public void TestBeatmap()
{
var mock = new Mock<IBeatmapInfo>();
mock.Setup(m => m.Metadata).Returns(makeMockMetadata);
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");
return mock.Object;
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author) [difficulty]"));
}
private static IBeatmapMetadataInfo makeMockMetadata()
[Test]
public void TestMetadata()
{
var mock = new Mock<IBeatmapMetadataInfo>();
@ -78,35 +71,49 @@ namespace osu.Game.Tests.Models
mock.Setup(m => m.Title).Returns("title");
mock.Setup(m => m.Author.Username).Returns("author");
return mock.Object;
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("artist - title (author)"));
}
private static IScoreInfo makeMockScore()
[Test]
public void TestScore()
{
var mock = new Mock<IScoreInfo>();
mock.Setup(m => m.User).Returns(new APIUser { Username = "user" }); // TODO: temporary.
mock.Setup(m => m.Beatmap).Returns(makeMockBeatmap);
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");
return mock.Object;
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("user playing artist - title (author) [difficulty]"));
}
private static IRulesetInfo makeMockRuleset()
[Test]
public void TestRuleset()
{
var mock = new Mock<IRulesetInfo>();
mock.Setup(m => m.Name).Returns("ruleset");
return mock.Object;
Assert.That(mock.Object.GetDisplayString(), Is.EqualTo("ruleset"));
}
private static IUser makeMockUser()
[Test]
public void TestUser()
{
var mock = new Mock<IUser>();
mock.Setup(m => m.Username).Returns("user");
return mock.Object;
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