1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-09 09:37:42 +08:00
osu-lazer/osu.Game.Tests/Online/TestSceneBeatmapDownloading.cs

101 lines
3.5 KiB
C#
Raw Normal View History

// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Models;
2021-11-09 20:34:36 +08:00
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Notifications;
using osu.Game.Tests.Visual;
namespace osu.Game.Tests.Online
{
[HeadlessTest]
public class TestSceneBeatmapDownloading : OsuTestScene
{
private BeatmapModelDownloader beatmaps;
private ProgressNotification recentNotification;
2021-11-09 20:34:36 +08:00
private static readonly BeatmapSetInfo test_db_model = new BeatmapSetInfo
{
OnlineID = 1,
Beatmaps =
2021-11-09 20:34:36 +08:00
{
new BeatmapInfo
2021-11-09 20:34:36 +08:00
{
Metadata = new BeatmapMetadata
{
Artist = "test author",
Title = "test title",
Author = new RealmUser
{
Username = "mapper"
}
}
2021-11-09 20:34:36 +08:00
}
}
};
private static readonly APIBeatmapSet test_online_model = new APIBeatmapSet
{
OnlineID = 2,
Artist = "test author",
Title = "test title",
Author = new APIUser
{
Username = "mapper"
}
};
[BackgroundDependencyLoader]
private void load(BeatmapModelDownloader beatmaps)
{
this.beatmaps = beatmaps;
beatmaps.PostNotification = n => recentNotification = n as ProgressNotification;
}
2021-11-09 20:34:36 +08:00
private static readonly object[][] notification_test_cases =
{
new object[] { test_db_model },
new object[] { test_online_model }
};
[TestCaseSource(nameof(notification_test_cases))]
public void TestNotificationMessage(IBeatmapSetInfo model)
{
AddStep("clear recent notification", () => recentNotification = null);
AddStep("download beatmap", () => beatmaps.Download(model));
AddUntilStep("wait for notification", () => recentNotification != null);
AddUntilStep("notification text correct", () => recentNotification.Text.ToString() == "Downloading test author - test title (mapper)");
}
2020-01-07 10:47:00 +08:00
[Test]
public void TestCancelDownloadFromRequest()
{
2021-11-09 20:34:36 +08:00
AddStep("download beatmap", () => beatmaps.Download(test_db_model));
2022-07-20 15:33:52 +08:00
AddStep("cancel download from request", () => beatmaps.GetExistingDownload(test_db_model)!.Cancel());
2020-01-07 10:47:00 +08:00
2021-11-09 20:34:36 +08:00
AddUntilStep("is removed from download list", () => beatmaps.GetExistingDownload(test_db_model) == null);
2020-01-07 10:47:00 +08:00
AddAssert("is notification cancelled", () => recentNotification.State == ProgressNotificationState.Cancelled);
}
[Test]
public void TestCancelDownloadFromNotification()
{
2021-11-09 20:34:36 +08:00
AddStep("download beatmap", () => beatmaps.Download(test_db_model));
2020-01-07 10:47:00 +08:00
AddStep("cancel download from notification", () => recentNotification.Close(true));
2021-11-09 20:34:36 +08:00
AddUntilStep("is removed from download list", () => beatmaps.GetExistingDownload(test_db_model) == null);
AddAssert("is notification cancelled", () => recentNotification.State == ProgressNotificationState.Cancelled);
}
}
}