public async Task SpectatingUserStateDoesNotChange() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Spectating); SetUserContext(ContextUser); await Hub.StartMatch(); GameplayReceiver.Verify(c => c.LoadRequested(), Times.Once); Clients.Verify(clients => clients.Client(ContextUser2.Object.ConnectionId).UserStateChanged(USER_ID_2, MultiplayerUserState.WaitingForLoad), Times.Never); await Hub.ChangeState(MultiplayerUserState.Loaded); Receiver.Verify(c => c.MatchStarted(), Times.Once); Clients.Verify(clients => clients.Client(ContextUser2.Object.ConnectionId).UserStateChanged(USER_ID_2, MultiplayerUserState.Playing), Times.Never); await Hub.ChangeState(MultiplayerUserState.FinishedPlay); Receiver.Verify(c => c.ResultsReady(), Times.Once); Clients.Verify(clients => clients.Client(ContextUser2.Object.ConnectionId).UserStateChanged(USER_ID_2, MultiplayerUserState.Results), Times.Never); }
public async Task OnlyReadiedUpUsersTransitionToPlay() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); SetUserContext(ContextUser); await Hub.StartMatch(); using (var room = await Rooms.GetForUse(ROOM_ID)) { Assert.Equal(MultiplayerRoomState.WaitingForLoad, room.Item?.State); Assert.Single(room.Item?.Users, u => u.State == MultiplayerUserState.WaitingForLoad); Assert.Single(room.Item?.Users, u => u.State == MultiplayerUserState.Idle); } await Hub.ChangeState(MultiplayerUserState.Loaded); using (var room = await Rooms.GetForUse(ROOM_ID)) { Assert.Single(room.Item?.Users, u => u.State == MultiplayerUserState.Playing); Assert.Single(room.Item?.Users, u => u.State == MultiplayerUserState.Idle); } }
public async Task AllUsersBackingOutFromLoadCancelsTransitionToPlay() { await Hub.JoinRoom(ROOM_ID); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); SetUserContext(ContextUser); await Hub.ChangeState(MultiplayerUserState.Ready); await Hub.StartMatch(); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.Equal(MultiplayerRoomState.WaitingForLoad, room.Item?.State); await Hub.ChangeState(MultiplayerUserState.Idle); SetUserContext(ContextUser2); await Hub.ChangeState(MultiplayerUserState.Idle); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.Equal(MultiplayerRoomState.Open, room.Item?.State); }
public async Task ChangingSettingsMarksReadyUsersAsIdle() { MultiplayerRoomSettings testSettings = new MultiplayerRoomSettings { Name = "bestest room ever", BeatmapChecksum = "checksum" }; await Hub.JoinRoom(ROOM_ID); MultiplayerRoom?room; using (var usage = Hub.GetRoom(ROOM_ID)) { // unsafe, but just for tests. room = usage.Item; Debug.Assert(room != null); } await Hub.ChangeState(MultiplayerUserState.Ready); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.Ready), Times.Once); Assert.All(room.Users, u => Assert.Equal(MultiplayerUserState.Ready, u.State)); await Hub.ChangeSettings(testSettings); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.Idle), Times.Once); Assert.All(room.Users, u => Assert.Equal(MultiplayerUserState.Idle, u.State)); }
public async void NotReadyUsersDontGetLoadRequest() { await Hub.JoinRoom(ROOM_ID); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); SetUserContext(ContextUser); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.Idle, u.State)); // one user enters a ready state. await Hub.ChangeState(MultiplayerUserState.Ready); using (var room = await Rooms.GetForUse(ROOM_ID)) { Assert.Single(room.Item?.Users.Where(u => u.State == MultiplayerUserState.Idle)); Assert.Single(room.Item?.Users.Where(u => u.State == MultiplayerUserState.Ready)); Assert.Equal(MultiplayerRoomState.Open, room.Item?.State); } // host requests the start of the match. await Hub.StartMatch(); GameplayReceiver.Verify(r => r.LoadRequested(), Times.Once); Receiver.Verify(r => r.LoadRequested(), Times.Never); using (var room = await Rooms.GetForUse(ROOM_ID)) { Assert.Single(room.Item?.Users.Where(u => u.State == MultiplayerUserState.WaitingForLoad)); Assert.Single(room.Item?.Users.Where(u => u.State == MultiplayerUserState.Idle)); } }
public async Task RoomHasNewPlaylistItemAfterMatchStart() { long playlistItemId = (await Hub.JoinRoom(ROOM_ID)).Settings.PlaylistItemId; long expectedPlaylistItemId = playlistItemId + 1; Database.Setup(db => db.AddPlaylistItemAsync(It.IsAny <multiplayer_playlist_item>())) .ReturnsAsync(() => expectedPlaylistItemId); await Hub.ChangeState(MultiplayerUserState.Ready); await Hub.StartMatch(); await Hub.ChangeState(MultiplayerUserState.Loaded); await Hub.ChangeState(MultiplayerUserState.FinishedPlay); using (var usage = Hub.GetRoom(ROOM_ID)) { var room = usage.Item; Debug.Assert(room != null); Assert.Equal(expectedPlaylistItemId, room.Settings.PlaylistItemId); Receiver.Verify(r => r.SettingsChanged(room.Settings), Times.Once); } }
public async Task OnlyFinishedUsersTransitionToResults() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); SetUserContext(ContextUser); await Hub.StartMatch(); await Hub.ChangeState(MultiplayerUserState.Loaded); await Hub.ChangeState(MultiplayerUserState.FinishedPlay); VerifyRemovedFromGameplayGroup(ContextUser, ROOM_ID); VerifyRemovedFromGameplayGroup(ContextUser2, ROOM_ID, false); using (var room = await Rooms.GetForUse(ROOM_ID)) { Assert.Single(room.Item?.Users, u => u.State == MultiplayerUserState.Results); Assert.Single(room.Item?.Users, u => u.State == MultiplayerUserState.Idle); } }
public async Task UserStateChangeNotifiesOtherUsers() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.Ready), Times.Once); }
public async Task CanTransitionFromReadyToSpectating() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); await Hub.ChangeState(MultiplayerUserState.Spectating); }
public async Task CanTransitionBetweenIdleAndSpectating() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Spectating); await Hub.ChangeState(MultiplayerUserState.Idle); }
public async Task SingleUserMatchFlow() { await Hub.JoinRoom(ROOM_ID); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.Idle, u.State)); // some users enter a ready state. await Hub.ChangeState(MultiplayerUserState.Ready); using (var room = await Rooms.GetForUse(ROOM_ID)) { Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.Ready, u.State)); Assert.Equal(MultiplayerRoomState.Open, room.Item?.State); } // host requests the start of the match. await Hub.StartMatch(); // server requests the all users start loading. GameplayReceiver.Verify(r => r.LoadRequested(), Times.Once); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.WaitingForLoad), Times.Once); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.WaitingForLoad, u.State)); // all users finish loading. await Hub.ChangeState(MultiplayerUserState.Loaded); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.Playing), Times.Once); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.Equal(MultiplayerRoomState.Playing, room.Item?.State); // server requests users start playing. Receiver.Verify(r => r.MatchStarted(), Times.Once); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.Playing, u.State)); // all users finish playing. await Hub.ChangeState(MultiplayerUserState.FinishedPlay); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.Equal(MultiplayerRoomState.Open, room.Item?.State); // server lets players know that results are ready for consumption (all players have finished). Receiver.Verify(r => r.ResultsReady(), Times.Once); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.Results), Times.Once); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.Results, u.State)); // players return back to idle state as they please. await Hub.ChangeState(MultiplayerUserState.Idle); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.Idle, u.State)); }
public async Task StartingMatchWithHostNotReadyFails() { await Hub.JoinRoom(ROOM_ID); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); SetUserContext(ContextUser); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.StartMatch()); }
public async Task UserCantChangeSettingsWhenGameIsActive() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); await Hub.StartMatch(); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.Equal(MultiplayerRoomState.WaitingForLoad, room.Item?.State); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.ChangeSettings(new MultiplayerRoomSettings())); }
public async Task SpectatingHostCanStartMatch() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Spectating); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); SetUserContext(ContextUser); await Hub.StartMatch(); GameplayReceiver.Verify(c => c.LoadRequested(), Times.Once); }
public async Task StartingAlreadyStartedMatchFails() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.Equal(MultiplayerRoomState.Open, room.Item?.State); await Hub.StartMatch(); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.Equal(MultiplayerRoomState.WaitingForLoad, room.Item?.State); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.StartMatch()); }
public async Task UserDisconnectsDuringGameplayUpdatesRoomState() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); SetUserContext(ContextUser); await Hub.StartMatch(); using (var room = await Rooms.GetForUse(ROOM_ID)) { Assert.Equal(MultiplayerRoomState.WaitingForLoad, room.Item?.State); Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.WaitingForLoad, u.State)); } SetUserContext(ContextUser); await Hub.ChangeState(MultiplayerUserState.Loaded); SetUserContext(ContextUser2); await Hub.ChangeState(MultiplayerUserState.Loaded); using (var room = await Rooms.GetForUse(ROOM_ID)) { Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.Playing, u.State)); Assert.Equal(MultiplayerRoomState.Playing, room.Item?.State); } // first user exits gameplay SetUserContext(ContextUser); await Hub.ChangeState(MultiplayerUserState.Idle); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.Equal(MultiplayerRoomState.Playing, room.Item?.State); // second user gets disconnected SetUserContext(ContextUser2); await Hub.LeaveRoom(); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.Equal(MultiplayerRoomState.Open, room.Item?.State); }
public async Task SpectatingUserReceivesLoadRequestedAfterMatchStarted() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); await Hub.StartMatch(); Receiver.Verify(c => c.LoadRequested(), Times.Never); GameplayReceiver.Verify(c => c.LoadRequested(), Times.Once); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Spectating); Caller.Verify(c => c.LoadRequested(), Times.Once); // Ensure no other clients received LoadRequested(). Receiver.Verify(c => c.LoadRequested(), Times.Never); GameplayReceiver.Verify(c => c.LoadRequested(), Times.Once); }
public async Task OnlyReadyPlayersAreAddedToAndRemovedFromGameplayGroup() { await Hub.JoinRoom(ROOM_ID); await Hub.ChangeState(MultiplayerUserState.Ready); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); SetUserContext(ContextUser); await Hub.StartMatch(); await Hub.ChangeState(MultiplayerUserState.Loaded); VerifyAddedToGameplayGroup(ContextUser, ROOM_ID); VerifyAddedToGameplayGroup(ContextUser2, ROOM_ID, false); await Hub.ChangeState(MultiplayerUserState.FinishedPlay); VerifyRemovedFromGameplayGroup(ContextUser, ROOM_ID); VerifyRemovedFromGameplayGroup(ContextUser2, ROOM_ID, false); }
public async Task MultiUserMatchFlow() { await Hub.JoinRoom(ROOM_ID); SetUserContext(ContextUser2); await Hub.JoinRoom(ROOM_ID); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.Idle, u.State)); // both users become ready. SetUserContext(ContextUser); await Hub.ChangeState(MultiplayerUserState.Ready); SetUserContext(ContextUser2); await Hub.ChangeState(MultiplayerUserState.Ready); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.Ready, u.State)); // host requests the start of the match. SetUserContext(ContextUser); await Hub.StartMatch(); // server requests the all users start loading. GameplayReceiver.Verify(r => r.LoadRequested(), Times.Once); using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.WaitingForLoad, u.State)); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.WaitingForLoad), Times.Once); Receiver.Verify(r => r.UserStateChanged(USER_ID_2, MultiplayerUserState.WaitingForLoad), Times.Once); // first user finishes loading. SetUserContext(ContextUser); await Hub.ChangeState(MultiplayerUserState.Loaded); // room is still waiting for second user to load. using (var room = await Rooms.GetForUse(ROOM_ID)) Assert.Equal(MultiplayerRoomState.WaitingForLoad, room.Item?.State); Receiver.Verify(r => r.MatchStarted(), Times.Never); // second user finishes loading, which triggers gameplay to start. SetUserContext(ContextUser2); await Hub.ChangeState(MultiplayerUserState.Loaded); using (var room = await Rooms.GetForUse(ROOM_ID)) { Assert.Equal(MultiplayerRoomState.Playing, room.Item?.State); Receiver.Verify(r => r.MatchStarted(), Times.Once); Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.Playing, u.State)); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.Playing), Times.Once); Receiver.Verify(r => r.UserStateChanged(USER_ID_2, MultiplayerUserState.Playing), Times.Once); } // first user finishes playing. SetUserContext(ContextUser); await Hub.ChangeState(MultiplayerUserState.FinishedPlay); using (var room = await Rooms.GetForUse(ROOM_ID)) { // room is still waiting for second user to finish playing. Assert.Equal(MultiplayerRoomState.Playing, room.Item?.State); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.FinishedPlay), Times.Once); Receiver.Verify(r => r.UserStateChanged(USER_ID_2, MultiplayerUserState.Playing), Times.Once); Receiver.Verify(r => r.ResultsReady(), Times.Never); } // second user finishes playing. SetUserContext(ContextUser2); await Hub.ChangeState(MultiplayerUserState.FinishedPlay); using (var room = await Rooms.GetForUse(ROOM_ID)) { // server lets players know that results are ready for consumption (all players have finished). Receiver.Verify(r => r.ResultsReady(), Times.Once); Assert.All(room.Item?.Users, u => Assert.Equal(MultiplayerUserState.Results, u.State)); Receiver.Verify(r => r.UserStateChanged(USER_ID, MultiplayerUserState.Results), Times.Once); Receiver.Verify(r => r.UserStateChanged(USER_ID_2, MultiplayerUserState.Results), Times.Once); Assert.Equal(MultiplayerRoomState.Open, room.Item?.State); } }
public async Task UserCantChangeStateToReservedStates(MultiplayerUserState reservedState) { await Hub.JoinRoom(ROOM_ID); await Assert.ThrowsAsync <InvalidStateChangeException>(() => Hub.ChangeState(reservedState)); }