Fix participant panel null user test no longer functioning properly

I guess the changes that involved `MultiplayerTestScene` having a test
user lookup cache caused this test case to false-pass silently.

Added an explicit assert which ensures the added user indeed has a null
`User` value.
This commit is contained in:
Salman Ahmed 2021-08-16 09:06:56 +03:00
parent dba5af4a06
commit f82ed64aa7
3 changed files with 20 additions and 6 deletions

View File

@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Testing;
@ -48,7 +49,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
AddAssert("one unique panel", () => this.ChildrenOfType<ParticipantPanel>().Select(p => p.User).Distinct().Count() == 1);
AddStep("add non-resolvable user", () => Client.AddNullUser(-3));
AddStep("add non-resolvable user", () => Client.AddNullUser());
AddAssert("null user added", () => Client.Room.AsNonNull().Users.Count(u => u.User == null) == 1);
AddUntilStep("two unique panels", () => this.ChildrenOfType<ParticipantPanel>().Select(p => p.User).Distinct().Count() == 2);
}

View File

@ -61,7 +61,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
return roomUser;
}
public void AddNullUser(int userId) => ((IMultiplayerClient)this).UserJoined(new MultiplayerRoomUser(userId));
public void AddNullUser() => ((IMultiplayerClient)this).UserJoined(new MultiplayerRoomUser(TestUserLookupCache.NULL_USER_ID));
public void RemoveUser(User user)
{

View File

@ -10,10 +10,22 @@ namespace osu.Game.Tests.Visual
{
public class TestUserLookupCache : UserLookupCache
{
protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default) => Task.FromResult(new User
/// <summary>
/// A special user ID which <see cref="ComputeValueAsync"/> would return a <see langword="null"/> <see cref="User"/> for.
/// As a simulation to what a regular <see cref="UserLookupCache"/> would return in the case of failing to fetch the user.
/// </summary>
public const int NULL_USER_ID = -1;
protected override Task<User> ComputeValueAsync(int lookup, CancellationToken token = default)
{
Id = lookup,
Username = $"User {lookup}"
});
if (lookup == NULL_USER_ID)
return Task.FromResult((User)null);
return Task.FromResult(new User
{
Id = lookup,
Username = $"User {lookup}"
});
}
}
}