1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 04:13:00 +08:00
osu-lazer/osu.Game.Tests/Visual/Online/TestSceneReplayMissingBeatmap.cs

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

98 lines
3.1 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.
2023-09-04 15:17:21 +08:00
using System.Linq;
using System.Net;
using NUnit.Framework;
2023-09-04 15:17:21 +08:00
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Tests.Resources;
namespace osu.Game.Tests.Visual.Online
{
public partial class TestSceneReplayMissingBeatmap : OsuGameTestScene
{
private DummyAPIAccess dummyAPI => (DummyAPIAccess)API;
[Test]
public void TestSceneMissingBeatmapWithOnlineAvailable()
{
var beatmap = new APIBeatmap
{
2023-08-14 02:43:16 +08:00
OnlineBeatmapSetID = 173612,
BeatmapSet = new APIBeatmapSet
{
2023-09-04 15:17:21 +08:00
Title = "FREEDOM Dive",
Artist = "xi",
Covers = new BeatmapSetOnlineCovers
{
Card = "https://assets.ppy.sh/beatmaps/173612/covers/card@2x.jpg"
},
2023-08-14 02:43:16 +08:00
OnlineID = 173612
}
};
2023-08-14 02:43:16 +08:00
setupBeatmapResponse(beatmap);
AddStep("import score", () =>
{
using (var resourceStream = TestResources.OpenResource("Replays/mania-replay.osr"))
{
var importTask = new ImportTask(resourceStream, "replay.osr");
Game.ScoreManager.Import(new[] { importTask });
}
});
2023-09-04 15:17:21 +08:00
AddUntilStep("Replay missing notification show", () => Game.Notifications.ChildrenOfType<MissingBeatmapNotification>().Any());
}
[Test]
public void TestSceneMissingBeatmapWithOnlineUnavailable()
{
setupFailedResponse();
AddStep("import score", () =>
{
using (var resourceStream = TestResources.OpenResource("Replays/mania-replay.osr"))
{
var importTask = new ImportTask(resourceStream, "replay.osr");
Game.ScoreManager.Import(new[] { importTask });
}
});
2023-09-04 15:17:21 +08:00
AddUntilStep("Replay missing notification not show", () => !Game.Notifications.ChildrenOfType<MissingBeatmapNotification>().Any());
}
2023-08-14 02:43:16 +08:00
private void setupBeatmapResponse(APIBeatmap b)
=> AddStep("setup response", () =>
{
dummyAPI.HandleRequest = request =>
{
if (request is GetBeatmapRequest getBeatmapRequest)
{
getBeatmapRequest.TriggerSuccess(b);
return true;
}
return false;
};
});
private void setupFailedResponse()
=> AddStep("setup failed response", () =>
{
dummyAPI.HandleRequest = request =>
{
request.TriggerFailure(new WebException());
return true;
};
});
}
}