1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 19:47:24 +08:00
osu-lazer/osu.Game.Tests/Online/TestDummyAPIRequestHandling.cs

118 lines
3.4 KiB
C#
Raw Normal View History

2020-04-11 16:47:51 +08:00
// 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.
2020-04-11 17:02:49 +08:00
using NUnit.Framework;
2020-04-14 13:51:09 +08:00
using osu.Framework.Testing;
2020-04-11 16:47:51 +08:00
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
2020-04-11 17:02:49 +08:00
using osu.Game.Online.Chat;
2020-04-11 16:47:51 +08:00
using osu.Game.Tests.Visual;
2020-04-11 17:02:49 +08:00
using osu.Game.Users;
2020-04-11 16:47:51 +08:00
namespace osu.Game.Tests.Online
{
2020-04-14 13:51:09 +08:00
[HeadlessTest]
2020-04-11 16:47:51 +08:00
public class TestDummyAPIRequestHandling : OsuTestScene
{
2020-04-11 17:02:43 +08:00
[Test]
public void TestGenericRequestHandling()
2020-04-11 16:47:51 +08:00
{
AddStep("register request handling", () => ((DummyAPIAccess)API).HandleRequest = req =>
{
switch (req)
{
case CommentVoteRequest cRequest:
cRequest.TriggerSuccess(new CommentBundle());
break;
}
});
CommentVoteRequest request = null;
CommentBundle response = null;
AddStep("fire request", () =>
{
response = null;
request = new CommentVoteRequest(1, CommentVoteAction.Vote);
request.Success += res => response = res;
API.Queue(request);
});
2020-04-11 17:02:43 +08:00
AddAssert("response event fired", () => response != null);
AddAssert("request has response", () => request.Result == response);
}
2020-04-11 17:02:49 +08:00
[Test]
2020-04-13 20:35:35 +08:00
public void TestQueueRequestHandling()
2020-04-11 17:02:49 +08:00
{
2020-04-13 20:35:35 +08:00
registerHandler();
LeaveChannelRequest request;
bool gotResponse = false;
AddStep("fire request", () =>
2020-04-11 17:02:49 +08:00
{
2020-04-13 20:35:35 +08:00
gotResponse = false;
request = new LeaveChannelRequest(new Channel(), new User());
request.Success += () => gotResponse = true;
API.Queue(request);
2020-04-11 17:02:49 +08:00
});
2020-04-13 20:35:35 +08:00
AddAssert("response event fired", () => gotResponse);
}
[Test]
public void TestPerformRequestHandling()
{
registerHandler();
2020-04-11 17:02:49 +08:00
LeaveChannelRequest request;
bool gotResponse = false;
AddStep("fire request", () =>
{
gotResponse = false;
request = new LeaveChannelRequest(new Channel(), new User());
request.Success += () => gotResponse = true;
2020-04-13 20:35:35 +08:00
API.Perform(request);
2020-04-11 17:02:49 +08:00
});
AddAssert("response event fired", () => gotResponse);
2020-04-11 16:47:51 +08:00
}
2020-04-13 20:35:35 +08:00
[Test]
public void TestPerformAsyncRequestHandling()
{
registerHandler();
LeaveChannelRequest request;
bool gotResponse = false;
AddStep("fire request", () =>
{
gotResponse = false;
request = new LeaveChannelRequest(new Channel(), new User());
request.Success += () => gotResponse = true;
API.PerformAsync(request);
});
AddAssert("response event fired", () => gotResponse);
}
private void registerHandler()
{
AddStep("register request handling", () => ((DummyAPIAccess)API).HandleRequest = req =>
{
switch (req)
{
case LeaveChannelRequest cRequest:
cRequest.TriggerSuccess();
break;
}
});
}
2020-04-11 16:47:51 +08:00
}
}