mirror of
https://github.com/osukey/osukey.git
synced 2025-05-30 01:47:30 +09:00
Rewrite tests to be easier to follow
This commit is contained in:
parent
f4ef841972
commit
a52d9363f9
@ -15,23 +15,20 @@ namespace osu.Game.Tests.Models
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class DisplayStringTest
|
public class DisplayStringTest
|
||||||
{
|
{
|
||||||
private static readonly object[][] test_cases =
|
[Test]
|
||||||
|
public void TestBeatmapSet()
|
||||||
{
|
{
|
||||||
new object[] { makeNoMetadataMockBeatmapSet(), "unknown artist - unknown title" },
|
var mock = new Mock<IBeatmapSetInfo>();
|
||||||
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" }
|
|
||||||
};
|
|
||||||
|
|
||||||
[TestCaseSource(nameof(test_cases))]
|
mock.Setup(m => m.Metadata.Artist).Returns("artist");
|
||||||
public void TestDisplayString(object model, string expected) => Assert.That(model.GetDisplayString(), Is.EqualTo(expected));
|
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>();
|
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.Title).Returns("title");
|
||||||
mock.Setup(m => m.Metadata.Author.Username).Returns(string.Empty);
|
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>();
|
var mock = new Mock<IBeatmapSetInfo>();
|
||||||
|
|
||||||
mock.Setup(m => m.Metadata).Returns(new BeatmapMetadata());
|
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()
|
[Test]
|
||||||
{
|
public void TestBeatmap()
|
||||||
var mock = new Mock<IBeatmapSetInfo>();
|
|
||||||
|
|
||||||
mock.Setup(m => m.Metadata).Returns(makeMockMetadata);
|
|
||||||
|
|
||||||
return mock.Object;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IBeatmapInfo makeMockBeatmap()
|
|
||||||
{
|
{
|
||||||
var mock = new Mock<IBeatmapInfo>();
|
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");
|
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>();
|
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.Title).Returns("title");
|
||||||
mock.Setup(m => m.Author.Username).Returns("author");
|
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>();
|
var mock = new Mock<IScoreInfo>();
|
||||||
|
|
||||||
mock.Setup(m => m.User).Returns(new APIUser { Username = "user" }); // TODO: temporary.
|
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>();
|
var mock = new Mock<IRulesetInfo>();
|
||||||
|
|
||||||
mock.Setup(m => m.Name).Returns("ruleset");
|
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>();
|
var mock = new Mock<IUser>();
|
||||||
|
|
||||||
mock.Setup(m => m.Username).Returns("user");
|
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
|
private class Fallback
|
||||||
|
Loading…
x
Reference in New Issue
Block a user