Add test coverage

This commit is contained in:
Dean Herbert
2020-05-14 19:05:35 +09:00
parent 4e4a779d68
commit a582611647
3 changed files with 46 additions and 6 deletions

View File

@ -0,0 +1,36 @@
// 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.IO;
using System.Threading;
using osu.Framework.Screens;
using osu.Game.Overlays.Settings.Sections.Maintenance;
namespace osu.Game.Tests.Visual.Settings
{
public class TestSceneMigrationScreens : ScreenTestScene
{
public TestSceneMigrationScreens()
{
AddStep("Push screen", () => Stack.Push(new TestMigrationSelectScreen()));
}
private class TestMigrationSelectScreen : MigrationSelectScreen
{
protected override void BeginMigration(DirectoryInfo target) => this.Push(new TestMigrationRunScreen());
private class TestMigrationRunScreen : MigrationRunScreen
{
protected override void PerformMigration()
{
Thread.Sleep(3000);
}
public TestMigrationRunScreen()
: base(null)
{
}
}
}
}
}

View File

@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
{ {
private readonly DirectoryInfo destination; private readonly DirectoryInfo destination;
[Resolved] [Resolved(canBeNull: true)]
private OsuGame game { get; set; } private OsuGame game { get; set; }
public override bool AllowBackButton => false; public override bool AllowBackButton => false;
@ -84,7 +84,7 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
Beatmap.Value = Beatmap.Default; Beatmap.Value = Beatmap.Default;
migrationTask = Task.Run(() => game.Migrate(destination.FullName)) migrationTask = Task.Run(PerformMigration)
.ContinueWith(t => .ContinueWith(t =>
{ {
if (t.IsFaulted) if (t.IsFaulted)
@ -94,6 +94,8 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
}); });
} }
protected virtual void PerformMigration() => game?.Migrate(destination.FullName);
public override void OnEntering(IScreen last) public override void OnEntering(IScreen last)
{ {
base.OnEntering(last); base.OnEntering(last);

View File

@ -29,10 +29,10 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
public override bool HideOverlaysOnEnter => true; public override bool HideOverlaysOnEnter => true;
[BackgroundDependencyLoader] [BackgroundDependencyLoader(true)]
private void load(OsuGame game, Storage storage, OsuColour colours) private void load(OsuGame game, Storage storage, OsuColour colours)
{ {
game.Toolbar.Hide(); game?.Toolbar.Hide();
// begin selection in the parent directory of the current storage location // begin selection in the parent directory of the current storage location
var initialPath = new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent?.FullName; var initialPath = new DirectoryInfo(storage.GetFullPath(string.Empty)).Parent?.FullName;
@ -115,12 +115,14 @@ namespace osu.Game.Overlays.Settings.Sections.Maintenance
} }
catch (Exception e) catch (Exception e)
{ {
Logger.Log($"Error during migration: {e?.Message}", level: LogLevel.Error); Logger.Log($"Error during migration: {e.Message}", level: LogLevel.Error);
return; return;
} }
ValidForResume = false; ValidForResume = false;
this.Push(new MigrationRunScreen(target)); BeginMigration(target);
} }
protected virtual void BeginMigration(DirectoryInfo target) => this.Push(new MigrationRunScreen(target));
} }
} }