osu/osu.Game.Tests/Online/TestSceneBeatmapDownloading.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

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 07:37:17 +00: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 12:34:36 +00: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 partial class TestSceneBeatmapDownloading : OsuTestScene
{
private BeatmapModelDownloader beatmaps;
private ProgressNotification recentNotification;
2021-11-09 12:34:36 +00:00
private static readonly BeatmapSetInfo test_db_model = new BeatmapSetInfo
{
OnlineID = 1,
Beatmaps =
2021-11-09 12:34:36 +00:00
{
new BeatmapInfo
2021-11-09 12:34:36 +00:00
{
Metadata = new BeatmapMetadata
{
Artist = "test author",
Title = "test title",
Author = new RealmUser
{
Username = "mapper"
}
}
2021-11-09 12:34:36 +00: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 12:34:36 +00: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 02:47:00 +00:00
[Test]
public void TestCancelDownloadFromRequest()
{
2021-11-09 12:34:36 +00:00
AddStep("download beatmap", () => beatmaps.Download(test_db_model));
2022-07-20 07:33:52 +00:00
AddStep("cancel download from request", () => beatmaps.GetExistingDownload(test_db_model)!.Cancel());
2020-01-07 02:47:00 +00:00
2021-11-09 12:34:36 +00:00
AddUntilStep("is removed from download list", () => beatmaps.GetExistingDownload(test_db_model) == null);
2020-01-07 02:47:00 +00:00
AddAssert("is notification cancelled", () => recentNotification.State == ProgressNotificationState.Cancelled);
}
[Test]
public void TestCancelDownloadFromNotification()
{
2021-11-09 12:34:36 +00:00
AddStep("download beatmap", () => beatmaps.Download(test_db_model));
2020-01-07 02:47:00 +00:00
AddStep("cancel download from notification", () => recentNotification.Close(true));
2021-11-09 12:34:36 +00:00
AddUntilStep("is removed from download list", () => beatmaps.GetExistingDownload(test_db_model) == null);
AddAssert("is notification cancelled", () => recentNotification.State == ProgressNotificationState.Cancelled);
}
}
}