mirror of
https://github.com/ppy/osu.git
synced 2025-02-05 10:13:00 +08:00
Add test implementation of the ruleset config cache
This commit is contained in:
parent
5cbaa028eb
commit
77da1e12d5
19
osu.Game/Tests/Rulesets/TestRulesetConfigCache.cs
Normal file
19
osu.Game/Tests/Rulesets/TestRulesetConfigCache.cs
Normal file
@ -0,0 +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.
|
||||||
|
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Rulesets.Configuration;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Rulesets
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Test implementation of a <see cref="IRulesetConfigCache"/>, which ensures isolation between test scenes.
|
||||||
|
/// </summary>
|
||||||
|
public class TestRulesetConfigCache : IRulesetConfigCache
|
||||||
|
{
|
||||||
|
private readonly ConcurrentDictionary<string, IRulesetConfigManager> configCache = new ConcurrentDictionary<string, IRulesetConfigManager>();
|
||||||
|
|
||||||
|
public IRulesetConfigManager GetConfigFor(Ruleset ruleset) => configCache.GetOrAdd(ruleset.ShortName, _ => ruleset.CreateConfig(null));
|
||||||
|
}
|
||||||
|
}
|
@ -31,6 +31,7 @@ using osu.Game.Rulesets.UI;
|
|||||||
using osu.Game.Screens;
|
using osu.Game.Screens;
|
||||||
using osu.Game.Storyboards;
|
using osu.Game.Storyboards;
|
||||||
using osu.Game.Tests.Beatmaps;
|
using osu.Game.Tests.Beatmaps;
|
||||||
|
using osu.Game.Tests.Rulesets;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual
|
namespace osu.Game.Tests.Visual
|
||||||
{
|
{
|
||||||
@ -119,6 +120,13 @@ namespace osu.Game.Tests.Visual
|
|||||||
|
|
||||||
var baseDependencies = base.CreateChildDependencies(parent);
|
var baseDependencies = base.CreateChildDependencies(parent);
|
||||||
|
|
||||||
|
// to isolate ruleset configs in tests from the actual database and avoid state pollution problems,
|
||||||
|
// as well as problems due to the implementation details of the "real" implementation (the configs only being available at `LoadComplete()`),
|
||||||
|
// cache a test implementation of the ruleset config cache over the "real" one.
|
||||||
|
var isolatedBaseDependencies = new DependencyContainer(baseDependencies);
|
||||||
|
isolatedBaseDependencies.CacheAs<IRulesetConfigCache>(new TestRulesetConfigCache());
|
||||||
|
baseDependencies = isolatedBaseDependencies;
|
||||||
|
|
||||||
var providedRuleset = CreateRuleset();
|
var providedRuleset = CreateRuleset();
|
||||||
if (providedRuleset != null)
|
if (providedRuleset != null)
|
||||||
baseDependencies = rulesetDependencies = new DrawableRulesetDependencies(providedRuleset, baseDependencies);
|
baseDependencies = rulesetDependencies = new DrawableRulesetDependencies(providedRuleset, baseDependencies);
|
||||||
|
Loading…
Reference in New Issue
Block a user