Update tests which were importing scores without a valid beatmap

This commit is contained in:
Dean Herbert 2022-01-17 14:40:06 +09:00
parent 381174e482
commit 90166829c3
2 changed files with 32 additions and 11 deletions

View File

@ -8,8 +8,8 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Extensions;
using osu.Framework.Platform; using osu.Framework.Platform;
using osu.Game.Beatmaps;
using osu.Game.IO.Archives; using osu.Game.IO.Archives;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
@ -17,6 +17,8 @@ using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Tests.Beatmaps.IO;
using osu.Game.Tests.Resources;
namespace osu.Game.Tests.Scores.IO namespace osu.Game.Tests.Scores.IO
{ {
@ -31,6 +33,8 @@ namespace osu.Game.Tests.Scores.IO
{ {
var osu = LoadOsuIntoHost(host, true); var osu = LoadOsuIntoHost(host, true);
var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely();
var toImport = new ScoreInfo var toImport = new ScoreInfo
{ {
Rank = ScoreRank.B, Rank = ScoreRank.B,
@ -42,7 +46,7 @@ namespace osu.Game.Tests.Scores.IO
Date = DateTimeOffset.Now, Date = DateTimeOffset.Now,
OnlineID = 12345, OnlineID = 12345,
Ruleset = new OsuRuleset().RulesetInfo, Ruleset = new OsuRuleset().RulesetInfo,
BeatmapInfo = new BeatmapInfo() BeatmapInfo = beatmap.Beatmaps.First()
}; };
var imported = await LoadScoreIntoOsu(osu, toImport); var imported = await LoadScoreIntoOsu(osu, toImport);
@ -71,10 +75,12 @@ namespace osu.Game.Tests.Scores.IO
{ {
var osu = LoadOsuIntoHost(host, true); var osu = LoadOsuIntoHost(host, true);
var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely();
var toImport = new ScoreInfo var toImport = new ScoreInfo
{ {
User = new APIUser { Username = "Test user" }, User = new APIUser { Username = "Test user" },
BeatmapInfo = new BeatmapInfo(), BeatmapInfo = beatmap.Beatmaps.First(),
Ruleset = new OsuRuleset().RulesetInfo, Ruleset = new OsuRuleset().RulesetInfo,
Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() }, Mods = new Mod[] { new OsuModHardRock(), new OsuModDoubleTime() },
}; };
@ -100,10 +106,12 @@ namespace osu.Game.Tests.Scores.IO
{ {
var osu = LoadOsuIntoHost(host, true); var osu = LoadOsuIntoHost(host, true);
var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely();
var toImport = new ScoreInfo var toImport = new ScoreInfo
{ {
User = new APIUser { Username = "Test user" }, User = new APIUser { Username = "Test user" },
BeatmapInfo = new BeatmapInfo(), BeatmapInfo = beatmap.Beatmaps.First(),
Ruleset = new OsuRuleset().RulesetInfo, Ruleset = new OsuRuleset().RulesetInfo,
Statistics = new Dictionary<HitResult, int> Statistics = new Dictionary<HitResult, int>
{ {
@ -133,10 +141,12 @@ namespace osu.Game.Tests.Scores.IO
{ {
var osu = LoadOsuIntoHost(host, true); var osu = LoadOsuIntoHost(host, true);
var beatmap = BeatmapImportHelper.LoadOszIntoOsu(osu, TestResources.GetQuickTestBeatmapForImport()).GetResultSafely();
await LoadScoreIntoOsu(osu, new ScoreInfo await LoadScoreIntoOsu(osu, new ScoreInfo
{ {
User = new APIUser { Username = "Test user" }, User = new APIUser { Username = "Test user" },
BeatmapInfo = new BeatmapInfo(), BeatmapInfo = beatmap.Beatmaps.First(),
Ruleset = new OsuRuleset().RulesetInfo, Ruleset = new OsuRuleset().RulesetInfo,
OnlineID = 2 OnlineID = 2
}, new TestArchiveReader()); }, new TestArchiveReader());
@ -147,7 +157,7 @@ namespace osu.Game.Tests.Scores.IO
Assert.That(scoreManager.IsAvailableLocally(new ScoreInfo Assert.That(scoreManager.IsAvailableLocally(new ScoreInfo
{ {
User = new APIUser { Username = "Test user" }, User = new APIUser { Username = "Test user" },
BeatmapInfo = new BeatmapInfo(), BeatmapInfo = beatmap.Beatmaps.First(),
OnlineID = 2 OnlineID = 2
})); }));
} }

View File

@ -6,16 +6,18 @@ using NUnit.Framework;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Scoring;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Testing; using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database; using osu.Game.Database;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Rulesets; using osu.Game.Rulesets;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking; using osu.Game.Screens.Ranking;
using osu.Game.Tests.Resources;
using osuTK.Input; using osuTK.Input;
using APIUser = osu.Game.Online.API.Requests.Responses.APIUser; using APIUser = osu.Game.Online.API.Requests.Responses.APIUser;
@ -29,6 +31,18 @@ namespace osu.Game.Tests.Visual.Gameplay
private TestReplayDownloadButton downloadButton; private TestReplayDownloadButton downloadButton;
[Resolved]
private BeatmapManager beatmapManager { get; set; }
[Resolved]
private ScoreManager scoreManager { get; set; }
[BackgroundDependencyLoader]
private void load()
{
beatmapManager.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
}
[Test] [Test]
public void TestDisplayStates() public void TestDisplayStates()
{ {
@ -115,9 +129,6 @@ namespace osu.Game.Tests.Visual.Gameplay
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value); AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
} }
[Resolved]
private ScoreManager scoreManager { get; set; }
[Test] [Test]
public void TestScoreImportThenDelete() public void TestScoreImportThenDelete()
{ {
@ -176,7 +187,7 @@ namespace osu.Game.Tests.Visual.Gameplay
Id = 39828, Id = 39828,
Username = @"WubWoofWolf", Username = @"WubWoofWolf",
} }
}.CreateScoreInfo(rulesets, CreateBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo); }.CreateScoreInfo(rulesets, beatmapManager.GetAllUsableBeatmapSets().First().Beatmaps.First());
} }
private class TestReplayDownloadButton : ReplayDownloadButton private class TestReplayDownloadButton : ReplayDownloadButton