Skip to content

Commit e235e03

Browse files
committed
Player state tests
1 parent 5aa8664 commit e235e03

File tree

1 file changed

+87
-37
lines changed

1 file changed

+87
-37
lines changed

BanchoSharpTests/MultiplayerTests.cs

Lines changed: 87 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ private void InvokeEventInvoker(string message) => ((IBanchoBotEventInvoker)_cli
6666

6767
private void InvokeBancho(string banchoBotMessage, string recipient) => _client.SimulateMessageReceivedAsync(
6868
PrivateIrcMessage.CreateFromParameters("BanchoBot", recipient, banchoBotMessage));
69-
69+
7070
private void InvokeToLobby(string message) => Invoke(PrivateIrcMessage.CreateFromParameters("BanchoBot", _lobby.ChannelName, message));
71-
71+
7272
[SetUp]
7373
public void Setup()
7474
{
@@ -100,42 +100,44 @@ public void Setup()
100100
"Players: 1",
101101
"Slot 1 Not Ready https://osu.ppy.sh/u/8191845 Stage [Host / Easy, Hidden, Relax, Flashlight, SpunOut]")]
102102
public void TestMpSettingsUpdates(string lobbyName, string historyUrl, int matchId, Mods lobbyMods,
103-
int beatmapId, string beatmapTitle, string beatmapArtist, string beatmapDifficulty, LobbyFormat format,
104-
WinCondition winCondition, TeamColor p1TeamColor, bool p1IsHost, bool p1IsReady, int p1Id,
103+
int beatmapId, string beatmapTitle, string beatmapArtist, string beatmapDifficulty,
104+
LobbyFormat format,
105+
WinCondition winCondition, TeamColor p1TeamColor, bool p1IsHost, bool p1IsReady,
106+
int p1Id,
105107
string p1Name, int p1Slot, Mods p1Mods, params string[] updates)
106-
{
107-
_lobby = new MultiplayerLobby(_client, matchId, lobbyName);
108+
{
109+
_lobby = new MultiplayerLobby(_client, matchId, lobbyName);
108110

109-
foreach (string u in updates)
111+
foreach (string u in updates)
110112
{
111113
// Generates the !mp settings response for these parameters and calls it
112114
Invoke(PrivateIrcMessage.CreateFromParameters("BanchoBot", $"#mp_{_lobby.Id}", u));
113115
}
114116

115-
Assert.Multiple(() =>
116-
{
117-
// Assert that all parameters are equal to the corresponding multiplayerlobby values
118-
Assert.That(_lobby.Name, Is.EqualTo(lobbyName));
119-
Assert.That(_lobby.HistoryUrl, Is.EqualTo(historyUrl));
120-
Assert.That(_lobby.Id, Is.EqualTo(matchId));
121-
Assert.That(_lobby.Mods, Is.EqualTo(lobbyMods));
122-
Assert.That(_lobby.CurrentBeatmap.Id, Is.EqualTo(beatmapId));
123-
Assert.That(_lobby.CurrentBeatmap.Title, Is.EqualTo(beatmapTitle));
124-
Assert.That(_lobby.CurrentBeatmap.Artist, Is.EqualTo(beatmapArtist));
125-
Assert.That(_lobby.CurrentBeatmap.Difficulty, Is.EqualTo(beatmapDifficulty));
126-
Assert.That(_lobby.Format, Is.EqualTo(format));
127-
Assert.That(_lobby.WinCondition, Is.EqualTo(winCondition));
128-
Assert.That(_lobby.Host.Equals(_lobby.Players[0]), Is.EqualTo(p1IsHost));
129-
Assert.That(_lobby.Players[0].Team, Is.EqualTo(p1TeamColor));
130-
Assert.That(_lobby.Players[0].IsReady, Is.EqualTo(p1IsReady));
131-
Assert.That(_lobby.Players[0].Id, Is.EqualTo(p1Id));
132-
Assert.That(_lobby.Players[0].Name, Is.EqualTo(p1Name));
133-
Assert.That(_lobby.Players[0].Slot, Is.EqualTo(p1Slot));
134-
Assert.That(_lobby.Players[0].Mods, Is.EqualTo(p1Mods));
135-
});
136-
}
137-
138-
[TestCase(1314987, "Camellia", @"Feelin Sky (Camellia's ""200step"" Self-remix)", "Ambivalence", null,
117+
Assert.Multiple(() =>
118+
{
119+
// Assert that all parameters are equal to the corresponding multiplayerlobby values
120+
Assert.That(_lobby.Name, Is.EqualTo(lobbyName));
121+
Assert.That(_lobby.HistoryUrl, Is.EqualTo(historyUrl));
122+
Assert.That(_lobby.Id, Is.EqualTo(matchId));
123+
Assert.That(_lobby.Mods, Is.EqualTo(lobbyMods));
124+
Assert.That(_lobby.CurrentBeatmap.Id, Is.EqualTo(beatmapId));
125+
Assert.That(_lobby.CurrentBeatmap.Title, Is.EqualTo(beatmapTitle));
126+
Assert.That(_lobby.CurrentBeatmap.Artist, Is.EqualTo(beatmapArtist));
127+
Assert.That(_lobby.CurrentBeatmap.Difficulty, Is.EqualTo(beatmapDifficulty));
128+
Assert.That(_lobby.Format, Is.EqualTo(format));
129+
Assert.That(_lobby.WinCondition, Is.EqualTo(winCondition));
130+
Assert.That(_lobby.Host.Equals(_lobby.Players[0]), Is.EqualTo(p1IsHost));
131+
Assert.That(_lobby.Players[0].Team, Is.EqualTo(p1TeamColor));
132+
Assert.That(_lobby.Players[0].IsReady, Is.EqualTo(p1IsReady));
133+
Assert.That(_lobby.Players[0].Id, Is.EqualTo(p1Id));
134+
Assert.That(_lobby.Players[0].Name, Is.EqualTo(p1Name));
135+
Assert.That(_lobby.Players[0].Slot, Is.EqualTo(p1Slot));
136+
Assert.That(_lobby.Players[0].Mods, Is.EqualTo(p1Mods));
137+
});
138+
}
139+
140+
[TestCase(1314987, "Camellia", @"Feelin Sky (Camellia's ""200step"" Self-remix)", "Ambivalence", null,
139141
@"Camellia - Feelin Sky (Camellia's ""200step"" Self-remix) [Ambivalence] (https://osu.ppy.sh/b/1314987)")]
140142
[TestCase(676065, "FLOOR LEGENDS -KAC 2012-", "KAC 2012 ULTIMATE MEDLEY -HISTORIA SOUND VOLTEX-", "NOVICE", null,
141143
@"FLOOR LEGENDS -KAC 2012- - KAC 2012 ULTIMATE MEDLEY -HISTORIA SOUND VOLTEX- [NOVICE] (https://osu.ppy.sh/b/676065)")]
@@ -152,19 +154,43 @@ public void TestMpSettingsBeatmap()
152154
{
153155
string input = "Beatmap: https://osu.ppy.sh/b/2572163 Kurokotei - Galaxy Collapse";
154156
string input2 = "Beatmap: https://osu.ppy.sh/b/2907160 Silentroom - NULCTRL";
155-
157+
156158
var shell = new BeatmapShell(2572163, "Kurokotei", "Galaxy Collapse", null, _lobby.GameMode);
157159
var shell2 = new BeatmapShell(2907160, "Silentroom", "NULCTRL", null, _lobby.GameMode);
158-
160+
159161
Assert.Multiple(() =>
160162
{
161163
InvokeToLobby(input);
162164
Assert.That(_lobby.CurrentBeatmap, Is.EqualTo(shell));
163-
165+
164166
InvokeToLobby(input2);
165167
Assert.That(_lobby.CurrentBeatmap, Is.EqualTo(shell2));
166168
});
167169
}
170+
171+
[Test]
172+
public void TestAllPlayersReady()
173+
{
174+
_lobby.Players.Add(new MultiplayerPlayer(_lobby, "Player 1", 1));
175+
_lobby.Players.Add(new MultiplayerPlayer(_lobby, "Player 2", 2));
176+
_lobby.Players.Add(new MultiplayerPlayer(_lobby, "Player 3", 3));
177+
_lobby.Players.Add(new MultiplayerPlayer(_lobby, "Player 4", 4));
178+
179+
foreach (var player in _lobby.Players)
180+
{
181+
Assert.That(player.IsReady, Is.False);
182+
}
183+
184+
_lobby.OnAllPlayersReady += () =>
185+
{
186+
foreach (var player in _lobby.Players)
187+
{
188+
Assert.That(player.IsReady, Is.True);
189+
}
190+
};
191+
192+
InvokeToLobby("All players are ready!");
193+
}
168194

169195
[Test]
170196
public void TestHostChangingBeatmap()
@@ -189,6 +215,30 @@ public void TestHostChangingBeatmap()
189215
}
190216
}
191217

218+
// This also gets executed when the host manually selects a map
219+
[TestCase(":[email protected] PRIVMSG #mp_1 :Beatmap changed to: Various Artists - FINGER CONTROL MEGAPACK [Renard - With Me (LVL1)] (https://osu.ppy.sh/b/3593124)",
220+
3593124, "Various Artists", "FINGER CONTROL MEGAPACK", "Renard - With Me (LVL1)")]
221+
[TestCase(":[email protected] PRIVMSG #mp_1 :Beatmap changed to: baker - For a Dead Girl+ [Collab Extra] (https://osu.ppy.sh/b/1444316)",
222+
1444316, "baker", "For a Dead Girl+", "Collab Extra")]
223+
[TestCase(":[email protected] PRIVMSG #mp_1 :Beatmap changed to: THE ORAL CIGARETTES - Flower [Sakura] (https://osu.ppy.sh/b/1738018)",
224+
1738018, "THE ORAL CIGARETTES", "Flower", "Sakura")]
225+
[TestCase(":[email protected] PRIVMSG #mp_1 :Beatmap changed to: TheFatRat - Mayday (feat. Laura Brehm) [[2B] Calling Out Mayday] (https://osu.ppy.sh/b/1605148)",
226+
1605148, "TheFatRat", "Mayday (feat. Laura Brehm)", "[2B] Calling Out Mayday")]
227+
[TestCase(":[email protected] PRIVMSG #mp_106511377 :Beatmap changed to: Toby Fox - MEGALOVANIA (Camellia Remix) [Tocorn x Ciyus Miapah : Inevitable Demise] (https://osu.ppy.sh/b/2169346)",
228+
2169346, "Toby Fox", "MEGALOVANIA (Camellia Remix)", "Tocorn x Ciyus Miapah : Inevitable Demise")]
229+
public void TestMpSet(string message, int id, string artist, string title, string diff)
230+
{
231+
var irc = new PrivateIrcMessage(message);
232+
233+
_client.SimulateMessageReceivedAsync(irc);
234+
235+
Assert.Multiple(() =>
236+
{
237+
Assert.That(_lobby.CurrentBeatmap, Is.Not.Null);
238+
Assert.That(_lobby.CurrentBeatmap!.Equals(new BeatmapShell(id, artist, title, diff, _lobby.GameMode)));
239+
});
240+
}
241+
192242
[TestCase("a")]
193243
[TestCase("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")]
194244
[TestCase("⍝ږÇ=壕֤Я~𫮒֕�ꊇي탇ݛ󙖇暤t󋹝񥯿2ޥ춸Мᇫ𸏩e鑨򍏕╕񗋙")] // Random UTF-8
@@ -214,7 +264,7 @@ public void TestPlayerChangedSlot()
214264
string player1 = "dummy1";
215265
string player2 = "dummy2";
216266
string player3 = "dummy3";
217-
267+
218268
_lobby.OnPlayerSlotMove += e =>
219269
{
220270
var playerMatch = _lobby.FindPlayer(e.Player.Name);
@@ -224,11 +274,11 @@ public void TestPlayerChangedSlot()
224274
Assert.That(playerMatch!.Slot, Is.EqualTo(e.NewSlot));
225275
});
226276
};
227-
277+
228278
InvokeEventInvoker(_playerJoined(player1, 1, null));
229279
InvokeEventInvoker(_playerJoined(player2, 2, null));
230280
InvokeEventInvoker(_playerJoined(player3, 3, null));
231-
281+
232282
InvokeEventInvoker(_slotChanged(player1, 5));
233283
InvokeEventInvoker(_slotChanged(player2, 16));
234284
InvokeEventInvoker(_slotChanged(player3, 2));

0 commit comments

Comments
 (0)