2020-04-11 08:47:51 +00: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 09:02:49 +00:00
|
|
|
using NUnit.Framework;
|
2020-04-14 05:51:09 +00:00
|
|
|
using osu.Framework.Testing;
|
2020-04-11 08:47:51 +00:00
|
|
|
using osu.Game.Online.API;
|
|
|
|
using osu.Game.Online.API.Requests;
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2020-04-11 09:02:49 +00:00
|
|
|
using osu.Game.Online.Chat;
|
2020-04-11 08:47:51 +00:00
|
|
|
using osu.Game.Tests.Visual;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Online
|
|
|
|
{
|
2020-04-14 05:51:09 +00:00
|
|
|
[HeadlessTest]
|
2020-04-11 08:47:51 +00:00
|
|
|
public class TestDummyAPIRequestHandling : OsuTestScene
|
|
|
|
{
|
2020-04-11 09:02:43 +00:00
|
|
|
[Test]
|
|
|
|
public void TestGenericRequestHandling()
|
2020-04-11 08:47:51 +00: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 09:02:43 +00:00
|
|
|
AddAssert("response event fired", () => response != null);
|
|
|
|
|
|
|
|
AddAssert("request has response", () => request.Result == response);
|
|
|
|
}
|
2020-04-11 09:02:49 +00:00
|
|
|
|
|
|
|
[Test]
|
2020-04-13 12:35:35 +00:00
|
|
|
public void TestQueueRequestHandling()
|
2020-04-11 09:02:49 +00:00
|
|
|
{
|
2020-04-13 12:35:35 +00:00
|
|
|
registerHandler();
|
|
|
|
|
|
|
|
LeaveChannelRequest request;
|
|
|
|
bool gotResponse = false;
|
|
|
|
|
|
|
|
AddStep("fire request", () =>
|
2020-04-11 09:02:49 +00:00
|
|
|
{
|
2020-04-13 12:35:35 +00:00
|
|
|
gotResponse = false;
|
2020-07-14 04:07:17 +00:00
|
|
|
request = new LeaveChannelRequest(new Channel());
|
2020-04-13 12:35:35 +00:00
|
|
|
request.Success += () => gotResponse = true;
|
|
|
|
API.Queue(request);
|
2020-04-11 09:02:49 +00:00
|
|
|
});
|
|
|
|
|
2020-04-13 12:35:35 +00:00
|
|
|
AddAssert("response event fired", () => gotResponse);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestPerformRequestHandling()
|
|
|
|
{
|
|
|
|
registerHandler();
|
|
|
|
|
2020-04-11 09:02:49 +00:00
|
|
|
LeaveChannelRequest request;
|
|
|
|
bool gotResponse = false;
|
|
|
|
|
|
|
|
AddStep("fire request", () =>
|
|
|
|
{
|
|
|
|
gotResponse = false;
|
2020-07-14 04:07:17 +00:00
|
|
|
request = new LeaveChannelRequest(new Channel());
|
2020-04-11 09:02:49 +00:00
|
|
|
request.Success += () => gotResponse = true;
|
2020-04-13 12:35:35 +00:00
|
|
|
API.Perform(request);
|
2020-04-11 09:02:49 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddAssert("response event fired", () => gotResponse);
|
2020-04-11 08:47:51 +00:00
|
|
|
}
|
2020-04-13 12:35:35 +00:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void TestPerformAsyncRequestHandling()
|
|
|
|
{
|
|
|
|
registerHandler();
|
|
|
|
|
|
|
|
LeaveChannelRequest request;
|
|
|
|
bool gotResponse = false;
|
|
|
|
|
|
|
|
AddStep("fire request", () =>
|
|
|
|
{
|
|
|
|
gotResponse = false;
|
2020-07-14 04:07:17 +00:00
|
|
|
request = new LeaveChannelRequest(new Channel());
|
2020-04-13 12:35:35 +00: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();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-04-11 08:47:51 +00:00
|
|
|
}
|
|
|
|
}
|