2021-06-25 16:37:02 +08: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 17:02:44 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-06-25 16:37:02 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
{
|
|
|
|
public partial class TestUserLookupCache : UserLookupCache
|
|
|
|
{
|
2021-08-16 14:06:56 +08:00
|
|
|
/// <summary>
|
2021-11-04 17:02:44 +08:00
|
|
|
/// A special user ID which <see cref="ComputeValueAsync"/> would return a <see langword="null"/> <see cref="APIUser"/> for.
|
2021-08-16 14:06:56 +08: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 15:51:27 +08:00
|
|
|
public const int UNRESOLVED_USER_ID = -1;
|
2021-08-16 14:06:56 +08:00
|
|
|
|
2023-06-09 19:47:50 +08:00
|
|
|
protected override Task<APIUser?> ComputeValueAsync(int lookup, CancellationToken token = default)
|
2021-06-25 16:37:02 +08:00
|
|
|
{
|
2021-11-02 15:51:27 +08:00
|
|
|
if (lookup == UNRESOLVED_USER_ID)
|
2023-06-09 19:47:50 +08:00
|
|
|
return Task.FromResult<APIUser?>(null);
|
2021-08-16 14:06:56 +08:00
|
|
|
|
2023-06-09 19:47:50 +08:00
|
|
|
return Task.FromResult<APIUser?>(new APIUser
|
2021-08-16 14:06:56 +08:00
|
|
|
{
|
|
|
|
Id = lookup,
|
|
|
|
Username = $"User {lookup}"
|
|
|
|
});
|
|
|
|
}
|
2021-06-25 16:37:02 +08:00
|
|
|
}
|
|
|
|
}
|