osu/osu.Game.Tests/Online/TestSceneBeatmapManager.cs

92 lines
3.2 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.
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
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 class TestSceneBeatmapManager : OsuTestScene
{
private BeatmapManager beatmaps;
private ProgressNotification recentNotification;
2021-11-09 12:34:36 +00:00
private static readonly BeatmapSetInfo test_db_model = new BeatmapSetInfo
{
OnlineBeatmapSetID = 1,
Metadata = new BeatmapMetadata
{
Artist = "test author",
Title = "test title",
Author = new APIUser
{
Username = "mapper"
}
}
};
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(BeatmapManager 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));
2021-11-09 12:34:36 +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());
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);
}
}
}