mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 20:05:29 +08:00
Merge pull request #17789 from peppy/rank-range-pill-test-refactor
Refactor `TestSceneRankRangePill` to not depend on `TestMultiplayerClient`
This commit is contained in:
commit
76517cecab
@ -1,67 +1,68 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Moq;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
|
using osu.Game.Online.Multiplayer;
|
||||||
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.Multiplayer
|
namespace osu.Game.Tests.Visual.Multiplayer
|
||||||
{
|
{
|
||||||
public class TestSceneRankRangePill : MultiplayerTestScene
|
public class TestSceneRankRangePill : OsuTestScene
|
||||||
{
|
{
|
||||||
[SetUp]
|
private readonly Mock<MultiplayerClient> multiplayerClient = new Mock<MultiplayerClient>();
|
||||||
public new void Setup() => Schedule(() =>
|
|
||||||
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
|
||||||
|
// not used directly in component, but required due to it inheriting from OnlinePlayComposite.
|
||||||
|
new CachedModelDependencyContainer<Room>(base.CreateChildDependencies(parent));
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load()
|
||||||
{
|
{
|
||||||
|
Dependencies.CacheAs(multiplayerClient.Object);
|
||||||
|
|
||||||
Child = new RankRangePill
|
Child = new RankRangePill
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre
|
Origin = Anchor.Centre
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestSingleUser()
|
public void TestSingleUser()
|
||||||
{
|
{
|
||||||
AddStep("add user", () =>
|
setupRoomWithUsers(new APIUser
|
||||||
{
|
{
|
||||||
MultiplayerClient.AddUser(new APIUser
|
Id = 2,
|
||||||
{
|
Statistics = { GlobalRank = 1234 }
|
||||||
Id = 2,
|
|
||||||
Statistics = { GlobalRank = 1234 }
|
|
||||||
});
|
|
||||||
|
|
||||||
// Remove the local user so only the one above is displayed.
|
|
||||||
MultiplayerClient.RemoveUser(API.LocalUser.Value);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TestMultipleUsers()
|
public void TestMultipleUsers()
|
||||||
{
|
{
|
||||||
AddStep("add users", () =>
|
setupRoomWithUsers(
|
||||||
{
|
new APIUser
|
||||||
MultiplayerClient.AddUser(new APIUser
|
|
||||||
{
|
{
|
||||||
Id = 2,
|
Id = 2,
|
||||||
Statistics = { GlobalRank = 1234 }
|
Statistics = { GlobalRank = 1234 }
|
||||||
});
|
},
|
||||||
|
new APIUser
|
||||||
MultiplayerClient.AddUser(new APIUser
|
|
||||||
{
|
{
|
||||||
Id = 3,
|
Id = 3,
|
||||||
Statistics = { GlobalRank = 3333 }
|
Statistics = { GlobalRank = 3333 }
|
||||||
});
|
},
|
||||||
|
new APIUser
|
||||||
MultiplayerClient.AddUser(new APIUser
|
|
||||||
{
|
{
|
||||||
Id = 4,
|
Id = 4,
|
||||||
Statistics = { GlobalRank = 4321 }
|
Statistics = { GlobalRank = 4321 }
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove the local user so only the ones above are displayed.
|
|
||||||
MultiplayerClient.RemoveUser(API.LocalUser.Value);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestCase(1, 10)]
|
[TestCase(1, 10)]
|
||||||
@ -73,22 +74,29 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
[TestCase(1000000, 10000000)]
|
[TestCase(1000000, 10000000)]
|
||||||
public void TestRange(int min, int max)
|
public void TestRange(int min, int max)
|
||||||
{
|
{
|
||||||
AddStep("add users", () =>
|
setupRoomWithUsers(
|
||||||
{
|
new APIUser
|
||||||
MultiplayerClient.AddUser(new APIUser
|
|
||||||
{
|
{
|
||||||
Id = 2,
|
Id = 2,
|
||||||
Statistics = { GlobalRank = min }
|
Statistics = { GlobalRank = min }
|
||||||
});
|
},
|
||||||
|
new APIUser
|
||||||
MultiplayerClient.AddUser(new APIUser
|
|
||||||
{
|
{
|
||||||
Id = 3,
|
Id = 3,
|
||||||
Statistics = { GlobalRank = max }
|
Statistics = { GlobalRank = max }
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Remove the local user so only the ones above are displayed.
|
private void setupRoomWithUsers(params APIUser[] users)
|
||||||
MultiplayerClient.RemoveUser(API.LocalUser.Value);
|
{
|
||||||
|
AddStep("setup room", () =>
|
||||||
|
{
|
||||||
|
multiplayerClient.SetupGet(m => m.Room).Returns(new MultiplayerRoom(0)
|
||||||
|
{
|
||||||
|
Users = new List<MultiplayerRoomUser>(users.Select(apiUser => new MultiplayerRoomUser(apiUser.Id) { User = apiUser }))
|
||||||
|
});
|
||||||
|
|
||||||
|
multiplayerClient.Raise(m => m.RoomUpdated -= null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked when any change occurs to the multiplayer room.
|
/// Invoked when any change occurs to the multiplayer room.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event Action? RoomUpdated;
|
public virtual event Action? RoomUpdated;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Invoked when a new user joins the room.
|
/// Invoked when a new user joins the room.
|
||||||
@ -88,7 +88,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The joined <see cref="MultiplayerRoom"/>.
|
/// The joined <see cref="MultiplayerRoom"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public MultiplayerRoom? Room
|
public virtual MultiplayerRoom? Room
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user