1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Add support for Perform/PerformAsync

This commit is contained in:
Dean Herbert 2020-04-13 21:35:35 +09:00
parent 1c8a71b284
commit 89d8063588
2 changed files with 59 additions and 12 deletions

View File

@ -43,17 +43,9 @@ namespace osu.Game.Tests.Online
}
[Test]
public void TestRequestHandling()
public void TestQueueRequestHandling()
{
AddStep("register request handling", () => ((DummyAPIAccess)API).HandleRequest = req =>
{
switch (req)
{
case LeaveChannelRequest cRequest:
cRequest.TriggerSuccess();
break;
}
});
registerHandler();
LeaveChannelRequest request;
bool gotResponse = false;
@ -68,5 +60,56 @@ namespace osu.Game.Tests.Online
AddAssert("response event fired", () => gotResponse);
}
[Test]
public void TestPerformRequestHandling()
{
registerHandler();
LeaveChannelRequest request;
bool gotResponse = false;
AddStep("fire request", () =>
{
gotResponse = false;
request = new LeaveChannelRequest(new Channel(), new User());
request.Success += () => gotResponse = true;
API.Perform(request);
});
AddAssert("response event fired", () => gotResponse);
}
[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;
}
});
}
}
}

View File

@ -64,9 +64,13 @@ namespace osu.Game.Online.API
HandleRequest?.Invoke(request);
}
public void Perform(APIRequest request) { }
public void Perform(APIRequest request) => HandleRequest?.Invoke(request);
public Task PerformAsync(APIRequest request) => Task.CompletedTask;
public Task PerformAsync(APIRequest request)
{
HandleRequest?.Invoke(request);
return Task.CompletedTask;
}
public void Register(IOnlineComponent component)
{