Centralise test storage logic

This commit is contained in:
Dean Herbert 2018-07-19 14:07:55 +09:00
parent 41441771ae
commit 7be3a5d466
3 changed files with 16 additions and 24 deletions

View File

@ -16,7 +16,6 @@
using osu.Game.Screens.Select;
using osu.Game.Screens.Select.Carousel;
using osu.Game.Screens.Select.Filter;
using osu.Game.Tests.Platform;
namespace osu.Game.Tests.Visual
{
@ -28,6 +27,7 @@ public class TestCasePlaySongSelect : OsuTestCase
private RulesetStore rulesets;
private WorkingBeatmap defaultBeatmap;
private DatabaseContextFactory factory;
public override IReadOnlyList<Type> RequiredTypes => new[]
{
@ -59,18 +59,14 @@ private void load()
{
TestSongSelect songSelect = null;
var storage = new TestStorage(@"TestCasePlaySongSelect");
// this is by no means clean. should be replacing inside of OsuGameBase somehow.
DatabaseContextFactory factory = new DatabaseContextFactory(storage);
factory = new DatabaseContextFactory(LocalStorage);
factory.ResetDatabase();
using (var usage = factory.Get())
usage.Migrate();
Dependencies.Cache(rulesets = new RulesetStore(factory));
Dependencies.Cache(manager = new BeatmapManager(storage, factory, rulesets, null, null)
Dependencies.Cache(manager = new BeatmapManager(LocalStorage, factory, rulesets, null, null)
{
DefaultBeatmap = defaultBeatmap = Beatmap.Default
});

View File

@ -1,17 +0,0 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Platform;
namespace osu.Game.Tests.Platform
{
public class TestStorage : DesktopStorage
{
public TestStorage(string baseName)
: base(baseName, null)
{
}
public override string GetDatabaseConnectionString(string name) => "Data Source=" + GetUsablePathFor($"{name}.db", true);
}
}

View File

@ -1,10 +1,12 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Configuration;
using osu.Framework.Platform;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Rulesets;
@ -20,6 +22,9 @@ public abstract class OsuTestCase : TestCase
protected DependencyContainer Dependencies { get; private set; }
private readonly Lazy<Storage> localStorage;
protected Storage LocalStorage => localStorage.Value;
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
{
Dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
@ -33,6 +38,11 @@ protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnl
return Dependencies;
}
protected OsuTestCase()
{
localStorage = new Lazy<Storage>(() => new DesktopStorage($"{GetType().Name}-{Guid.NewGuid()}", null));
}
[BackgroundDependencyLoader]
private void load(AudioManager audioManager, RulesetStore rulesets)
{
@ -50,6 +60,9 @@ protected override void Dispose(bool isDisposing)
beatmap.Disabled = true;
beatmap.Value.Track.Stop();
}
if (localStorage.IsValueCreated)
localStorage.Value.DeleteDirectory(".");
}
protected override ITestCaseTestRunner CreateRunner() => new OsuTestCaseTestRunner();