2021-06-25 08:37:02 +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.
|
|
|
|
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using osu.Game.Database;
|
2021-11-04 09:02:44 +00:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-06-25 08:37:02 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
2022-11-24 05:32:20 +00:00
|
|
|
public partial class TestUserLookupCache : UserLookupCache
|
2021-06-25 08:37:02 +00:00
|
|
|
{
|
2021-08-16 06:06:56 +00:00
|
|
|
/// <summary>
|
2021-11-04 09:02:44 +00:00
|
|
|
/// A special user ID which <see cref="ComputeValueAsync"/> would return a <see langword="null"/> <see cref="APIUser"/> for.
|
2021-08-16 06:06:56 +00:00
|
|
|
/// As a simulation to what a regular <see cref="UserLookupCache"/> would return in the case of failing to fetch the user.
|
|
|
|
/// </summary>
|
2021-11-02 07:51:27 +00:00
|
|
|
public const int UNRESOLVED_USER_ID = -1;
|
2021-08-16 06:06:56 +00:00
|
|
|
|
2023-06-09 11:47:50 +00:00
|
|
|
protected override Task<APIUser?> ComputeValueAsync(int lookup, CancellationToken token = default)
|
2021-06-25 08:37:02 +00:00
|
|
|
{
|
2021-11-02 07:51:27 +00:00
|
|
|
if (lookup == UNRESOLVED_USER_ID)
|
2023-06-09 11:47:50 +00:00
|
|
|
return Task.FromResult<APIUser?>(null);
|
2021-08-16 06:06:56 +00:00
|
|
|
|
2023-06-09 11:47:50 +00:00
|
|
|
return Task.FromResult<APIUser?>(new APIUser
|
2021-08-16 06:06:56 +00:00
|
|
|
{
|
|
|
|
Id = lookup,
|
|
|
|
Username = $"User {lookup}"
|
|
|
|
});
|
|
|
|
}
|
2021-06-25 08:37:02 +00:00
|
|
|
}
|
|
|
|
}
|