Add support for Result fetching

This commit is contained in:
Dean Herbert 2020-04-11 18:02:43 +09:00
parent 832822858c
commit 415adecdf6
2 changed files with 13 additions and 3 deletions

View File

@ -10,7 +10,8 @@ namespace osu.Game.Tests.Online
{ {
public class TestDummyAPIRequestHandling : OsuTestScene public class TestDummyAPIRequestHandling : OsuTestScene
{ {
public TestDummyAPIRequestHandling() [Test]
public void TestGenericRequestHandling()
{ {
AddStep("register request handling", () => ((DummyAPIAccess)API).HandleRequest = req => AddStep("register request handling", () => ((DummyAPIAccess)API).HandleRequest = req =>
{ {
@ -33,7 +34,10 @@ namespace osu.Game.Tests.Online
API.Queue(request); API.Queue(request);
}); });
AddAssert("got response", () => response != null); AddAssert("response event fired", () => response != null);
AddAssert("request has response", () => request.Result == response);
}
} }
} }
} }

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using System; using System;
using System.Diagnostics;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.IO.Network; using osu.Framework.IO.Network;
using osu.Framework.Logging; using osu.Framework.Logging;
@ -98,10 +99,15 @@ namespace osu.Game.Online.API
{ {
if (cancelled) return; if (cancelled) return;
Success?.Invoke(); TriggerSuccess();
}); });
} }
internal void TriggerSuccess()
{
Success?.Invoke();
}
public void Cancel() => Fail(new OperationCanceledException(@"Request cancelled")); public void Cancel() => Fail(new OperationCanceledException(@"Request cancelled"));
public void Fail(Exception e) public void Fail(Exception e)