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;
|
|
|
|
|
|
|
|
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());
|
2021-03-23 17:08:32 +08:00
|
|
|
return true;
|
2020-04-11 16:47:51 +08:00
|
|
|
}
|
2021-03-23 17:08:32 +08:00
|
|
|
|
|
|
|
return false;
|
2020-04-11 16:47:51 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2021-10-05 13:28:56 +08:00
|
|
|
AddAssert("request has response", () => request.Response == response);
|
2020-04-11 17:02:43 +08:00
|
|
|
}
|
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;
|
2020-07-14 12:07:17 +08:00
|
|
|
request = new LeaveChannelRequest(new Channel());
|
2020-04-13 20:35:35 +08:00
|
|
|
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;
|
2020-07-14 12:07:17 +08:00
|
|
|
request = new LeaveChannelRequest(new Channel());
|
2020-04-11 17:02:49 +08:00
|
|
|
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;
|
2020-07-14 12:07:17 +08:00
|
|
|
request = new LeaveChannelRequest(new Channel());
|
2020-04-13 20:35:35 +08:00
|
|
|
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();
|
2021-03-23 17:08:32 +08:00
|
|
|
return true;
|
2020-04-13 20:35:35 +08:00
|
|
|
}
|
2021-03-23 17:08:32 +08:00
|
|
|
|
|
|
|
return false;
|
2020-04-13 20:35:35 +08:00
|
|
|
});
|
|
|
|
}
|
2020-04-11 16:47:51 +08:00
|
|
|
}
|
|
|
|
}
|