diff --git a/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs b/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs index 4afb76a7e2..b94fb42bf0 100644 --- a/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs +++ b/osu.Game.Tests/Visual/TestCasePlaySongSelect.cs @@ -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 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 }); diff --git a/osu.Game/Tests/Platform/TestStorage.cs b/osu.Game/Tests/Platform/TestStorage.cs deleted file mode 100644 index 8391de3405..0000000000 --- a/osu.Game/Tests/Platform/TestStorage.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2007-2018 ppy Pty Ltd . -// 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); - } -} diff --git a/osu.Game/Tests/Visual/OsuTestCase.cs b/osu.Game/Tests/Visual/OsuTestCase.cs index fcbab5b8f5..8e09ec849c 100644 --- a/osu.Game/Tests/Visual/OsuTestCase.cs +++ b/osu.Game/Tests/Visual/OsuTestCase.cs @@ -1,10 +1,12 @@ // Copyright (c) 2007-2018 ppy Pty Ltd . // 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 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(() => 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();