From 66f4516eee5b871ce82954bde74dad69319286dd Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 1 Nov 2021 16:43:39 +0900 Subject: [PATCH] Allow creating sample API models without specifying a ruleset --- .../Multiplayer/TestSceneDrawableRoomPlaylist.cs | 16 +++++++++------- .../Online/TestSceneDirectDownloadButton.cs | 5 ++--- .../TestSceneUpdateableBeatmapSetCover.cs | 6 +++--- osu.Game/Tests/Visual/OsuTestScene.cs | 12 ++++++------ 4 files changed, 20 insertions(+), 19 deletions(-) diff --git a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs index f44b0c9716..5dfa055d7d 100644 --- a/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs +++ b/osu.Game.Tests/Visual/Multiplayer/TestSceneDrawableRoomPlaylist.cs @@ -6,6 +6,7 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Audio; +using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Platform; @@ -202,7 +203,7 @@ namespace osu.Game.Tests.Visual.Multiplayer [Test] public void TestDownloadButtonHiddenWhenBeatmapExists() { - var beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo; + var beatmap = CreateAPIBeatmapSet(); AddStep("import beatmap", () => manager.Import(beatmap.BeatmapSet).Wait()); @@ -223,11 +224,11 @@ namespace osu.Game.Tests.Visual.Multiplayer [Test] public void TestDownloadButtonVisibleInitiallyWhenBeatmapDoesNotExist() { - var byOnlineId = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo; - byOnlineId.BeatmapSet.OnlineBeatmapSetID = 1337; // Some random ID that does not exist locally. + var byOnlineId = CreateAPIBeatmapSet(); + byOnlineId.OnlineID = 1337; // Some random ID that does not exist locally. - var byChecksum = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo; - byChecksum.MD5Hash = "1337"; // Some random checksum that does not exist locally. + var byChecksum = CreateAPIBeatmapSet(); + byChecksum.Beatmaps.ForEach(b => b.Checksum = "1337"); // Some random checksum that does not exist locally. createPlaylist(byOnlineId, byChecksum); @@ -237,8 +238,9 @@ namespace osu.Game.Tests.Visual.Multiplayer [Test] public void TestExplicitBeatmapItem() { - var beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo; - beatmap.BeatmapSet.OnlineInfo.HasExplicitContent = true; + var beatmap = CreateAPIBeatmapSet(); + + beatmap.HasExplicitContent = true; createPlaylist(beatmap); } diff --git a/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs b/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs index f0cf88840a..3d828077c8 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs @@ -9,7 +9,6 @@ using osu.Game.Beatmaps; using osu.Game.Online; using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays.BeatmapListing.Panels; -using osu.Game.Rulesets.Osu; using osu.Game.Tests.Resources; using osuTK; @@ -110,7 +109,7 @@ namespace osu.Game.Tests.Visual.Online private IBeatmapSetInfo getDownloadableBeatmapSet() { - var apiBeatmapSet = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo).BeatmapSetInfo.OnlineInfo; + var apiBeatmapSet = CreateAPIBeatmapSet(); apiBeatmapSet.HasVideo = true; apiBeatmapSet.HasStoryboard = true; @@ -120,7 +119,7 @@ namespace osu.Game.Tests.Visual.Online private IBeatmapSetInfo getUndownloadableBeatmapSet() { - var apiBeatmapSet = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo).BeatmapSetInfo.OnlineInfo; + var apiBeatmapSet = CreateAPIBeatmapSet(); apiBeatmapSet.Artist = "test"; apiBeatmapSet.Title = "undownloadable"; diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneUpdateableBeatmapSetCover.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneUpdateableBeatmapSetCover.cs index f67f6258cc..6896e7a67a 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneUpdateableBeatmapSetCover.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneUpdateableBeatmapSetCover.cs @@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.UserInterface { AddStep("setup cover", () => Child = new UpdateableOnlineBeatmapSetCover(coverType) { - OnlineInfo = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet.OnlineInfo, + OnlineInfo = CreateAPIBeatmapSet(), RelativeSizeAxes = Axes.Both, Masking = true, }); @@ -41,7 +41,7 @@ namespace osu.Game.Tests.Visual.UserInterface AddStep("setup covers", () => { - BeatmapSetInfo setInfo = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet; + var beatmapSet = CreateAPIBeatmapSet(); FillFlowContainer fillFlow; @@ -99,7 +99,7 @@ namespace osu.Game.Tests.Visual.UserInterface AddStep("setup cover", () => Child = updateableCover = new TestUpdateableOnlineBeatmapSetCover { - OnlineInfo = CreateBeatmap(Ruleset.Value).BeatmapInfo.BeatmapSet.OnlineInfo, + OnlineInfo = CreateAPIBeatmapSet(), RelativeSizeAxes = Axes.Both, Masking = true, }); diff --git a/osu.Game/Tests/Visual/OsuTestScene.cs b/osu.Game/Tests/Visual/OsuTestScene.cs index 090a085f71..e25cbaf467 100644 --- a/osu.Game/Tests/Visual/OsuTestScene.cs +++ b/osu.Game/Tests/Visual/OsuTestScene.cs @@ -178,10 +178,10 @@ namespace osu.Game.Tests.Visual /// /// Returns a sample API Beatmap with BeatmapSet populated. /// - /// The ruleset to create the sample model using. - protected APIBeatmap CreateAPIBeatmap(RulesetInfo ruleset) + /// The ruleset to create the sample model using. osu! ruleset will be used if not specified. + protected APIBeatmap CreateAPIBeatmap(RulesetInfo ruleset = null) { - var beatmapSet = CreateAPIBeatmapSet(ruleset); + var beatmapSet = CreateAPIBeatmapSet(ruleset ?? Ruleset.Value); // Avoid circular reference. var beatmap = beatmapSet.Beatmaps.First(); @@ -196,10 +196,10 @@ namespace osu.Game.Tests.Visual /// /// Returns a sample API BeatmapSet with beatmaps populated. /// - /// The ruleset to create the sample model using. - protected APIBeatmapSet CreateAPIBeatmapSet(RulesetInfo ruleset) + /// The ruleset to create the sample model using. osu! ruleset will be used if not specified. + protected APIBeatmapSet CreateAPIBeatmapSet(RulesetInfo ruleset = null) { - var beatmap = CreateBeatmap(ruleset).BeatmapInfo; + var beatmap = CreateBeatmap(ruleset ?? Ruleset.Value).BeatmapInfo; return new APIBeatmapSet {