mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 22:32:55 +08:00
Add test coverage for outdated ruleset
This commit is contained in:
parent
90b9c02ac6
commit
5ff4e6a4fe
@ -1,11 +1,19 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Rulesets.Difficulty;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Osu.Beatmaps;
|
||||
using osu.Game.Rulesets.Osu.Difficulty;
|
||||
using osu.Game.Rulesets.Osu.UI;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Tests.Database
|
||||
{
|
||||
@ -51,5 +59,80 @@ namespace osu.Game.Tests.Database
|
||||
Assert.IsFalse(rulesets.GetRuleset("mania")?.IsManaged);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestOutdatedRulesetNotAvailable()
|
||||
{
|
||||
RunTestWithRealm((realm, storage) =>
|
||||
{
|
||||
OutdatedRuleset.Version = "2021.101.0";
|
||||
OutdatedRuleset.HasImplementations = true;
|
||||
|
||||
var ruleset = new OutdatedRuleset();
|
||||
string rulesetShortName = ruleset.RulesetInfo.ShortName;
|
||||
|
||||
realm.Write(r => r.Add(new RulesetInfo(rulesetShortName, ruleset.RulesetInfo.Name, ruleset.RulesetInfo.InstantiationInfo, ruleset.RulesetInfo.OnlineID)
|
||||
{
|
||||
Available = true,
|
||||
}));
|
||||
|
||||
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName).Available), Is.True);
|
||||
|
||||
// Availability is updated on construction of a RealmRulesetStore
|
||||
var _ = new RealmRulesetStore(realm, storage);
|
||||
|
||||
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName).Available), Is.False);
|
||||
|
||||
// Simulate the ruleset getting updated
|
||||
OutdatedRuleset.Version = Ruleset.CURRENT_RULESET_API_VERSION;
|
||||
var __ = new RealmRulesetStore(realm, storage);
|
||||
|
||||
Assert.That(realm.Run(r => r.Find<RulesetInfo>(rulesetShortName).Available), Is.True);
|
||||
});
|
||||
}
|
||||
|
||||
private class OutdatedRuleset : Ruleset
|
||||
{
|
||||
public override string RulesetAPIVersionSupported => Version;
|
||||
|
||||
public static bool HasImplementations = true;
|
||||
|
||||
public static string Version { get; set; } = CURRENT_RULESET_API_VERSION;
|
||||
|
||||
public override IEnumerable<Mod> GetModsFor(ModType type)
|
||||
{
|
||||
if (!HasImplementations)
|
||||
throw new NotImplementedException();
|
||||
|
||||
return Array.Empty<Mod>();
|
||||
}
|
||||
|
||||
public override DrawableRuleset CreateDrawableRulesetWith(IBeatmap beatmap, IReadOnlyList<Mod>? mods = null)
|
||||
{
|
||||
if (!HasImplementations)
|
||||
throw new NotImplementedException();
|
||||
|
||||
return new DrawableOsuRuleset(new OsuRuleset(), beatmap, mods);
|
||||
}
|
||||
|
||||
public override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap)
|
||||
{
|
||||
if (!HasImplementations)
|
||||
throw new NotImplementedException();
|
||||
|
||||
return new OsuBeatmapConverter(beatmap, new OsuRuleset());
|
||||
}
|
||||
|
||||
public override DifficultyCalculator CreateDifficultyCalculator(IWorkingBeatmap beatmap)
|
||||
{
|
||||
if (!HasImplementations)
|
||||
throw new NotImplementedException();
|
||||
|
||||
return new OsuDifficultyCalculator(new OsuRuleset().RulesetInfo, beatmap);
|
||||
}
|
||||
|
||||
public override string Description => "outdated ruleset";
|
||||
public override string ShortName => "ruleset-outdated";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user