Expose and use test ruleset config cache in test scenes

This commit is contained in:
Bartłomiej Dach
2021-12-23 19:34:41 +01:00
parent 8094b502cb
commit c429c74d89
4 changed files with 16 additions and 10 deletions

View File

@ -95,6 +95,16 @@ namespace osu.Game.Tests.Visual
/// </remarks>
protected Storage LocalStorage => localStorage.Value;
/// <summary>
/// A cache for ruleset configurations to be used in this test scene.
/// </summary>
/// <remarks>
/// This <see cref="IRulesetConfigCache"/> instance is provided to the children of this test scene via DI.
/// It is only exposed so that test scenes themselves can access the ruleset config cache in a safe manner
/// (<see cref="OsuTestScene"/>s cannot use DI themselves, as they will end up accessing the real cached instance from <see cref="OsuGameBase"/>).
/// </remarks>
protected IRulesetConfigCache RulesetConfigs { get; private set; }
private Lazy<Storage> localStorage;
private Storage headlessHostStorage;
@ -124,7 +134,7 @@ namespace osu.Game.Tests.Visual
// 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());
isolatedBaseDependencies.CacheAs(RulesetConfigs = new TestRulesetConfigCache());
baseDependencies = isolatedBaseDependencies;
var providedRuleset = CreateRuleset();