mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 08:33:21 +08:00
Add return bool to HandleRequest to better trigger failures
This commit is contained in:
parent
ce452565f4
commit
aeff9bd853
@ -23,8 +23,10 @@ namespace osu.Game.Tests.Online
|
||||
{
|
||||
case CommentVoteRequest cRequest:
|
||||
cRequest.TriggerSuccess(new CommentBundle());
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
CommentVoteRequest request = null;
|
||||
@ -108,8 +110,10 @@ namespace osu.Game.Tests.Online
|
||||
{
|
||||
case LeaveChannelRequest cRequest:
|
||||
cRequest.TriggerSuccess();
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -135,13 +135,15 @@ namespace osu.Game.Tests.Visual.Background
|
||||
dummyAPI.HandleRequest = request =>
|
||||
{
|
||||
if (dummyAPI.State.Value != APIState.Online || !(request is GetSeasonalBackgroundsRequest backgroundsRequest))
|
||||
return;
|
||||
return false;
|
||||
|
||||
backgroundsRequest.TriggerSuccess(new APISeasonalBackgrounds
|
||||
{
|
||||
Backgrounds = seasonal_background_urls.Select(url => new APISeasonalBackground { Url = url }).ToList(),
|
||||
EndDate = endDate
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -30,13 +30,14 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
((DummyAPIAccess)API).HandleRequest = req =>
|
||||
{
|
||||
if (req is SearchBeatmapSetsRequest searchBeatmapSetsRequest)
|
||||
if (!(req is SearchBeatmapSetsRequest searchBeatmapSetsRequest)) return false;
|
||||
|
||||
searchBeatmapSetsRequest.TriggerSuccess(new SearchBeatmapSetsResponse
|
||||
{
|
||||
searchBeatmapSetsRequest.TriggerSuccess(new SearchBeatmapSetsResponse
|
||||
{
|
||||
BeatmapSets = setsForResponse,
|
||||
});
|
||||
}
|
||||
BeatmapSets = setsForResponse,
|
||||
});
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -63,13 +63,15 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Builds = builds.Values.ToList()
|
||||
};
|
||||
changelogRequest.TriggerSuccess(changelogResponse);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case GetChangelogBuildRequest buildRequest:
|
||||
if (requestedBuild != null)
|
||||
buildRequest.TriggerSuccess(requestedBuild);
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
Child = changelog = new TestChangelogOverlay();
|
||||
|
@ -11,6 +11,8 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Chat.Selection;
|
||||
@ -64,6 +66,24 @@ namespace osu.Game.Tests.Visual.Online
|
||||
});
|
||||
}
|
||||
|
||||
[SetUpSteps]
|
||||
public void SetUpSteps()
|
||||
{
|
||||
AddStep("register request handling", () =>
|
||||
{
|
||||
((DummyAPIAccess)API).HandleRequest = req =>
|
||||
{
|
||||
switch (req)
|
||||
{
|
||||
case JoinChannelRequest _:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestHideOverlay()
|
||||
{
|
||||
|
@ -85,9 +85,10 @@ namespace osu.Game.Tests.Visual.Online
|
||||
dummyAPI.HandleRequest = request =>
|
||||
{
|
||||
if (!(request is GetCommentsRequest getCommentsRequest))
|
||||
return;
|
||||
return false;
|
||||
|
||||
getCommentsRequest.TriggerSuccess(commentBundle);
|
||||
return true;
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -33,9 +33,10 @@ namespace osu.Game.Tests.Visual.Online
|
||||
dummyAPI.HandleRequest = request =>
|
||||
{
|
||||
if (!(request is GetNewsRequest getNewsRequest))
|
||||
return;
|
||||
return false;
|
||||
|
||||
getNewsRequest.TriggerSuccess(r);
|
||||
return true;
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -170,6 +170,17 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
|
||||
private void bindHandler(bool delayed = false, ScoreInfo userScore = null, bool failRequests = false) => ((DummyAPIAccess)API).HandleRequest = request =>
|
||||
{
|
||||
// pre-check for requests we should be handling (as they are scheduled below).
|
||||
switch (request)
|
||||
{
|
||||
case ShowPlaylistUserScoreRequest _:
|
||||
case IndexPlaylistScoresRequest _:
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
requestComplete = false;
|
||||
|
||||
double delay = delayed ? 3000 : 0;
|
||||
@ -196,6 +207,8 @@ namespace osu.Game.Tests.Visual.Playlists
|
||||
break;
|
||||
}
|
||||
}, delay);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
private void triggerSuccess<T>(APIRequest<T> req, T result)
|
||||
|
@ -32,8 +32,10 @@ namespace osu.Game.Tests.Visual.SongSelect
|
||||
{
|
||||
case GetUserRequest userRequest:
|
||||
userRequest.TriggerSuccess(getUser(userRequest.Ruleset.ID));
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -34,8 +34,9 @@ namespace osu.Game.Online.API
|
||||
|
||||
/// <summary>
|
||||
/// Provide handling logic for an arbitrary API request.
|
||||
/// Should return true is a request was handled. If null or false return, the request will be failed with a <see cref="NotSupportedException"/>.
|
||||
/// </summary>
|
||||
public Action<APIRequest> HandleRequest;
|
||||
public Func<APIRequest, bool> HandleRequest;
|
||||
|
||||
private readonly Bindable<APIState> state = new Bindable<APIState>(APIState.Online);
|
||||
|
||||
@ -55,12 +56,12 @@ namespace osu.Game.Online.API
|
||||
|
||||
public virtual void Queue(APIRequest request)
|
||||
{
|
||||
if (HandleRequest != null)
|
||||
HandleRequest.Invoke(request);
|
||||
else
|
||||
if (HandleRequest?.Invoke(request) != true)
|
||||
{
|
||||
// this will fail due to not receiving an APIAccess, and trigger a failure on the request.
|
||||
// this is intended - any request in testing that needs non-failures should use HandleRequest.
|
||||
request.Perform(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void Perform(APIRequest request) => HandleRequest?.Invoke(request);
|
||||
|
@ -52,15 +52,15 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
Rooms.Add(createdRoom);
|
||||
createRoomRequest.TriggerSuccess(createdRoom);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case JoinRoomRequest joinRoomRequest:
|
||||
joinRoomRequest.TriggerSuccess();
|
||||
break;
|
||||
return true;
|
||||
|
||||
case PartRoomRequest partRoomRequest:
|
||||
partRoomRequest.TriggerSuccess();
|
||||
break;
|
||||
return true;
|
||||
|
||||
case GetRoomsRequest getRoomsRequest:
|
||||
var roomsWithoutParticipants = new List<Room>();
|
||||
@ -76,11 +76,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
}
|
||||
|
||||
getRoomsRequest.TriggerSuccess(roomsWithoutParticipants);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case GetRoomRequest getRoomRequest:
|
||||
getRoomRequest.TriggerSuccess(Rooms.Single(r => r.RoomID.Value == getRoomRequest.RoomId));
|
||||
break;
|
||||
return true;
|
||||
|
||||
case GetBeatmapSetRequest getBeatmapSetRequest:
|
||||
var onlineReq = new GetBeatmapSetRequest(getBeatmapSetRequest.ID, getBeatmapSetRequest.Type);
|
||||
@ -89,11 +89,11 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
// Get the online API from the game's dependencies.
|
||||
game.Dependencies.Get<IAPIProvider>().Queue(onlineReq);
|
||||
break;
|
||||
return true;
|
||||
|
||||
case CreateRoomScoreRequest createRoomScoreRequest:
|
||||
createRoomScoreRequest.TriggerSuccess(new APIScoreToken { ID = 1 });
|
||||
break;
|
||||
return true;
|
||||
|
||||
case SubmitRoomScoreRequest submitRoomScoreRequest:
|
||||
submitRoomScoreRequest.TriggerSuccess(new MultiplayerScore
|
||||
@ -108,8 +108,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
User = api.LocalUser.Value,
|
||||
Statistics = new Dictionary<HitResult, int>()
|
||||
});
|
||||
break;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user