public async Task UserCantLeaveWhenNotAlreadyJoined() { await Assert.ThrowsAsync <NotJoinedRoomException>(() => Hub.LeaveRoom()); // ensure no state was left behind. await Assert.ThrowsAsync <KeyNotFoundException>(() => UserStates.GetForUse(USER_ID)); }
public async Task UserCantJoinWhenRestricted() { Database.Setup(db => db.IsUserRestrictedAsync(It.IsAny <int>())).ReturnsAsync(true); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.JoinRoom(ROOM_ID)); // ensure no state was left behind. await Assert.ThrowsAsync <KeyNotFoundException>(() => UserStates.GetForUse(USER_ID)); }
public async Task UserJoinPreRetrievalFailureCleansUpRoom() { SetUserContext(ContextUser2); // not the correct user to join the game first; triggers host mismatch failure. await Assert.ThrowsAnyAsync <Exception>(() => Hub.JoinRoom(ROOM_ID)); await Assert.ThrowsAsync <KeyNotFoundException>(() => Rooms.GetForUse(ROOM_ID)); await Assert.ThrowsAsync <KeyNotFoundException>(() => UserStates.GetForUse(USER_ID)); }
public async Task UserJoinPostJoinFailureCleansUpRoomAndUser() { Database.Setup(db => db.AddRoomParticipantAsync(It.IsAny <MultiplayerRoom>(), It.IsAny <MultiplayerRoomUser>())) .ThrowsAsync(new Exception("error")); await Assert.ThrowsAnyAsync <Exception>(() => Hub.JoinRoom(ROOM_ID)); await Assert.ThrowsAsync <KeyNotFoundException>(() => Rooms.GetForUse(ROOM_ID)); await Assert.ThrowsAsync <KeyNotFoundException>(() => UserStates.GetForUse(USER_ID)); }
public async Task UserJoinPreJoinFailureCleansUpRoom() { Database.Setup(db => db.MarkRoomActiveAsync(It.IsAny <MultiplayerRoom>())) .ThrowsAsync(new Exception("error")); await Assert.ThrowsAnyAsync <Exception>(() => Hub.JoinRoom(ROOM_ID)); await Assert.ThrowsAsync <KeyNotFoundException>(() => Rooms.GetForUse(ROOM_ID)); await Assert.ThrowsAsync <KeyNotFoundException>(() => UserStates.GetForUse(USER_ID)); }
public async Task UserCantJoinAlreadyEnded() { Database.Setup(db => db.GetRoomAsync(It.IsAny <long>())) .ReturnsAsync(new multiplayer_room { ends_at = DateTimeOffset.Now.AddMinutes(-5), user_id = USER_ID }); await Assert.ThrowsAsync <InvalidStateException>(() => Hub.JoinRoom(ROOM_ID)); // ensure no state was left behind. await Assert.ThrowsAsync <KeyNotFoundException>(() => UserStates.GetForUse(USER_ID)); }