public void IfTheCreatorOfALobbyLeavesTheGameIsDestroyed() { var roomId = createRoom(); // Have the host leave the lobby LeaveRoomRequest leaveRequest = new LeaveRoomRequest() { RoomId = roomId }; LeaveRoomResponse leaveResponse = client.LeaveRoom(leaveRequest); Assert.AreEqual(leaveResponse.Status.IsSuccess, true); // Ensure that the player has left the game. // View open rooms. OpenLobbiesResponse openLobbiesResponsAfterLeave = client.GetOpenLobbies(new OpenLobbiesRequest()); assertSuccessResponse(openLobbiesResponsAfterLeave.Status); Assert.AreEqual(0, openLobbiesResponsAfterLeave.Rooms.Count); // Ensure the player is not in the game. PlayerCurrentGamesResponse gamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); assertSuccessResponse(gamesResponse.Status); Assert.AreEqual(0, gamesResponse.Games.Count); }
public void BeingTheLastPlayerToJoinAGameWillStartTheGame() { CreateRoomResponse roomResponse = client.CreateNewRoom(createRoomRequest("My room!", maxPlayers: 2)); Assert.AreEqual(roomResponse.Status.IsSuccess, true); Assert.IsTrue(roomResponse.CreatedRoom.Id != null); var roomId = roomResponse.CreatedRoom.Id; authHelper.loginToAccount("userTwo"); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); Assert.AreEqual(joinResponse.Status.IsSuccess, true); // Check to see the room is not visible. OpenLobbiesResponse openLobbiesResponseAfterJoin = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponseAfterJoin.Status.IsSuccess, true); Assert.AreEqual(0, openLobbiesResponseAfterJoin.Rooms.Count); // Check to see the player can see the game because they are a member. PlayerCurrentGamesResponse playerGamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(playerGamesResponse.Status.IsSuccess, true); Assert.AreEqual(1, playerGamesResponse.Games.Count); }
public void IfTheCreatorOfALobbyLeavesTheGameNoPlayersAreStuckInTheLobby() { CreateRoomRequest createRequest = new CreateRoomRequest() { Anonymous = false, Goal = Goal.Domination, MaxPlayers = 5, IsRanked = false, RoomName = "My Room!", AllowedSpecialists = { "a", "b", "c" }, }; CreateRoomResponse roomResponse = client.CreateNewRoom(createRequest); Assert.AreEqual(roomResponse.Status.IsSuccess, true); Assert.IsTrue(roomResponse.CreatedRoom.RoomId != null); var roomId = roomResponse.CreatedRoom.RoomId; // Have a player join the game authHelper.loginToAccount("userTwo"); client.JoinRoom(new JoinRoomRequest() { RoomId = roomId, }); authHelper.loginToAccount("userOne"); // Have the host leave the lobby LeaveRoomRequest leaveRequest = new LeaveRoomRequest() { RoomId = roomId }; LeaveRoomResponse leaveResponse = client.LeaveRoom(leaveRequest); Assert.AreEqual(leaveResponse.Status.IsSuccess, true); // Ensure that the player has left the game. // View open rooms. OpenLobbiesResponse openLobbiesResponsAfterLeave = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponsAfterLeave.Status.IsSuccess, true); Assert.AreEqual(0, openLobbiesResponsAfterLeave.Rooms.Count); // Ensure the player is not in the game. PlayerCurrentGamesResponse gamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(gamesResponse.Status.IsSuccess, true); Assert.AreEqual(0, gamesResponse.Games.Count); authHelper.loginToAccount("userTwo"); // Ensure the player is not in the game. PlayerCurrentGamesResponse gamesTwoResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(gamesTwoResponse.Status.IsSuccess, true); Assert.AreEqual(0, gamesTwoResponse.Games.Count); }
public void AdminsCanViewAnyOngoingGameTheyAreNotIn() { CreateRoomRequest createRequest = new CreateRoomRequest() { Anonymous = false, Goal = Goal.Domination, MaxPlayers = 2, IsRanked = false, RoomName = "My Room!", AllowedSpecialists = { "a", "b", "c" }, }; CreateRoomResponse roomResponse = client.CreateNewRoom(createRequest); Assert.AreEqual(roomResponse.Status.IsSuccess, true); Assert.IsTrue(roomResponse.CreatedRoom.RoomId != null); var roomId = roomResponse.CreatedRoom.RoomId; authHelper.loginToAccount("userTwo"); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); Assert.AreEqual(joinResponse.Status.IsSuccess, true); // Check to see the room is not visible. OpenLobbiesResponse openLobbiesResponseAfterJoin = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponseAfterJoin.Status.IsSuccess, true); Assert.AreEqual(0, openLobbiesResponseAfterJoin.Rooms.Count); // Check to see the player can see the game because they are a member. PlayerCurrentGamesResponse playerGamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(playerGamesResponse.Status.IsSuccess, true); Assert.AreEqual(1, playerGamesResponse.Games.Count); SuperUser superUser = authHelper.CreateSuperUser(); client.Login(new AuthorizationRequest() { Password = superUser.password, Username = superUser.userModel.UserModel.Username, }); PlayerCurrentGamesResponse adminGamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(adminGamesResponse.Status.IsSuccess, true); Assert.AreEqual(1, adminGamesResponse.Games.Count); }
public void IfTheCreatorOfALobbyLeavesTheGameNoPlayersAreStuckInTheLobby() { var roomId = createRoom(); // Have a player join the game authHelper.loginToAccount("userTwo"); client.JoinRoom(new JoinRoomRequest() { RoomId = roomId, }); authHelper.loginToAccount("userOne"); // Have the host leave the lobby LeaveRoomRequest leaveRequest = new LeaveRoomRequest() { RoomId = roomId }; LeaveRoomResponse leaveResponse = client.LeaveRoom(leaveRequest); assertSuccessResponse(leaveResponse.Status); // Ensure that the player has left the game. // View open rooms. OpenLobbiesResponse openLobbiesResponsAfterLeave = client.GetOpenLobbies(new OpenLobbiesRequest()); assertSuccessResponse(openLobbiesResponsAfterLeave.Status); Assert.AreEqual(0, openLobbiesResponsAfterLeave.Rooms.Count); // Ensure the player is not in the game. PlayerCurrentGamesResponse gamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); assertSuccessResponse(gamesResponse.Status); Assert.AreEqual(0, gamesResponse.Games.Count); authHelper.loginToAccount("userTwo"); // Ensure the player is not in the game. PlayerCurrentGamesResponse gamesTwoResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); assertSuccessResponse(gamesTwoResponse.Status); Assert.AreEqual(0, gamesTwoResponse.Games.Count); }
public override async Task <PlayerCurrentGamesResponse> GetPlayerCurrentGames(PlayerCurrentGamesRequest request, ServerCallContext context) { DbUserModel dbUserModel = context.UserState["user"] as DbUserModel; if (dbUserModel == null) { return new PlayerCurrentGamesResponse() { Status = ResponseFactory.createResponse(ResponseType.UNAUTHORIZED) } } ; PlayerCurrentGamesResponse currentGameResponse = new PlayerCurrentGamesResponse(); List <GameConfiguration> rooms = (await dbUserModel.GetActiveRooms()).Select(it => it.GameConfiguration).ToList(); currentGameResponse.Games.AddRange(rooms); currentGameResponse.Status = ResponseFactory.createResponse(ResponseType.SUCCESS); return(currentGameResponse); }
public override async Task <PlayerCurrentGamesResponse> GetPlayerCurrentGames(PlayerCurrentGamesRequest request, ServerCallContext context) { RedisUserModel user = context.UserState["user"] as RedisUserModel; if (user == null) { return new PlayerCurrentGamesResponse() { Status = ResponseFactory.createResponse(ResponseType.UNAUTHORIZED) } } ; PlayerCurrentGamesResponse currentGameResponse = new PlayerCurrentGamesResponse(); List <Room> rooms = (await user.GetActiveRooms()).ConvertAll(it => it.asRoom().Result); currentGameResponse.Games.AddRange(rooms); currentGameResponse.Status = ResponseFactory.createResponse(ResponseType.SUCCESS); return(currentGameResponse); }
public void BeingTheLastPlayerToJoinAGameWillStartTheGame() { CreateRoomRequest createRequest = new CreateRoomRequest() { Anonymous = false, Goal = Goal.Domination, MaxPlayers = 2, IsRanked = false, RoomName = "My Room!", AllowedSpecialists = { "a", "b", "c" }, }; CreateRoomResponse roomResponse = client.CreateNewRoom(createRequest); Assert.AreEqual(roomResponse.Status.IsSuccess, true); Assert.IsTrue(roomResponse.CreatedRoom.RoomId != null); var roomId = roomResponse.CreatedRoom.RoomId; authHelper.loginToAccount("userTwo"); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); Assert.AreEqual(joinResponse.Status.IsSuccess, true); // Check to see the room is not visible. OpenLobbiesResponse openLobbiesResponseAfterJoin = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponseAfterJoin.Status.IsSuccess, true); Assert.AreEqual(0, openLobbiesResponseAfterJoin.Rooms.Count); // Check to see the player can see the game because they are a member. PlayerCurrentGamesResponse playerGamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(playerGamesResponse.Status.IsSuccess, true); Assert.AreEqual(1, playerGamesResponse.Games.Count); }
public void AdminsCanViewAnyOngoingGameTheyAreNotIn() { var roomId = createRoom(maxPlayers: 2); authHelper.loginToAccount("userTwo"); JoinRoomRequest joinRequest = new JoinRoomRequest() { RoomId = roomId, }; JoinRoomResponse joinResponse = client.JoinRoom(joinRequest); Assert.AreEqual(joinResponse.Status.IsSuccess, true); // Check to see the room is not visible. OpenLobbiesResponse openLobbiesResponseAfterJoin = client.GetOpenLobbies(new OpenLobbiesRequest()); Assert.AreEqual(openLobbiesResponseAfterJoin.Status.IsSuccess, true); Assert.AreEqual(0, openLobbiesResponseAfterJoin.Rooms.Count); // Check to see the player can see the game because they are a member. PlayerCurrentGamesResponse playerGamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(playerGamesResponse.Status.IsSuccess, true); Assert.AreEqual(1, playerGamesResponse.Games.Count); SuperUser superUser = authHelper.CreateSuperUser(); client.Login(new AuthorizationRequest() { Password = superUser.password, Username = superUser.DbUserModel.UserModel.Username, }); PlayerCurrentGamesResponse adminGamesResponse = client.GetPlayerCurrentGames(new PlayerCurrentGamesRequest()); Assert.AreEqual(adminGamesResponse.Status.IsSuccess, true); Assert.AreEqual(1, adminGamesResponse.Games.Count); }