Skip to content

Commit

Permalink
Make test work properly
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jul 8, 2022
1 parent 13e1653 commit 3c8f064
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions osu.Game.Tests/Visual/Gameplay/TestScenePlayerLocalScoreImport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,51 @@

using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Extensions;
using osu.Framework.Platform;
using osu.Framework.Screens;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking;
using osu.Game.Tests.Resources;

namespace osu.Game.Tests.Visual.Gameplay
{
[HeadlessTest] // Importing rulesets doesn't work in interactive flows.
public class TestScenePlayerLocalScoreImport : PlayerTestScene
{
private Ruleset? customRuleset;
private BeatmapManager beatmaps = null!;
private RulesetStore rulesets = null!;

private BeatmapSetInfo? importedSet;

protected override bool ImportBeatmapToDatabase => true;
[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
{
Dependencies.Cache(rulesets = new RealmRulesetStore(Realm));
Dependencies.Cache(beatmaps = new BeatmapManager(LocalStorage, Realm, rulesets, null, audio, Resources, host, Beatmap.Default));
Dependencies.Cache(new ScoreManager(rulesets, () => beatmaps, LocalStorage, Realm, Scheduler));
Dependencies.Cache(Realm);
}

public override void SetUpSteps()
{
base.SetUpSteps();

AddStep("import beatmap", () =>
{
beatmaps.Import(TestResources.GetQuickTestBeatmapForImport()).WaitSafely();
importedSet = beatmaps.GetAllUsableBeatmapSets().First();
});
}

protected override IBeatmap CreateBeatmap(RulesetInfo ruleset) => beatmaps.GetWorkingBeatmap(importedSet?.Beatmaps.First()).Beatmap;

private Ruleset? customRuleset;

protected override Ruleset CreatePlayerRuleset() => customRuleset ?? new OsuRuleset();

Expand Down Expand Up @@ -66,7 +95,7 @@ public void TestScoreStoredLocallyCustomRuleset()
AddStep("seek to completion", () => Player.GameplayClockContainer.Seek(Player.DrawableRuleset.Objects.Last().GetEndTime()));

AddUntilStep("results displayed", () => Player.GetChildScreen() is ResultsScreen);
AddUntilStep("score in database", () => Realm.Run(r => r.All<ScoreInfo>().Count() == 1));
AddUntilStep("score in database", () => Realm.Run(r => r.Find<ScoreInfo>(Player.Score.ScoreInfo.ID) != null));
}
}
}

0 comments on commit 3c8f064

Please sign in to comment.