1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 07:22:54 +08:00

Add test implementation of the ruleset config cache

This commit is contained in:
Bartłomiej Dach 2021-12-23 19:18:26 +01:00
parent 5cbaa028eb
commit 77da1e12d5
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 27 additions and 0 deletions

View 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));
}
}

View File

@ -31,6 +31,7 @@ using osu.Game.Rulesets.UI;
using osu.Game.Screens;
using osu.Game.Storyboards;
using osu.Game.Tests.Beatmaps;
using osu.Game.Tests.Rulesets;
namespace osu.Game.Tests.Visual
{
@ -119,6 +120,13 @@ namespace osu.Game.Tests.Visual
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();
if (providedRuleset != null)
baseDependencies = rulesetDependencies = new DrawableRulesetDependencies(providedRuleset, baseDependencies);