예제 #1
0
func TestGetJoinedPlayers(t *testing.T) {
	dao := NewLobbyDAO()

	joinedPlayers := dao.GetJoinedPlayers()
	assert.True(t, len(joinedPlayers) == 0, "Should be 0 players")

	for i := 0; i < 3; i++ {
		{
			player := model.NewPlayer()
			player.PlayerName = "aron" + string(i)
			player.JoinedTs = 1234

			dao.SavePlayer(player)
		}
	}

	joinedPlayers = dao.GetJoinedPlayers()
	assert.True(t, len(joinedPlayers) == 3, "Should be 3 players")

	for i := 0; i < 3; i++ {
		{
			dao.RemovePlayer("aron" + string(i))
		}
	}
	joinedPlayers = dao.GetJoinedPlayers()
	assert.True(t, len(joinedPlayers) == 0, "Should be 0 players")
}
예제 #2
0
파일: api.go 프로젝트: rachoac/tictactoe-go
/**
 * Join a named player to the lobby, indicating that they are ready for a game challenge
 * @param playerName
 * @return
 */
func (self *LobbyAPI) JoinPlayer(playerName string) *model.Player {
	player := self.lobbyDAO.GetPlayer(playerName)
	if player == nil {
		player = model.NewPlayer()
		player.PlayerName = playerName
		player.JoinedTs = util.Now()
		self.lobbyDAO.SavePlayer(player)
	}

	return player
}
예제 #3
0
func TestRemovePlayer(t *testing.T) {
	dao := NewLobbyDAO()

	player := model.NewPlayer()
	player.PlayerName = "aron"
	player.JoinedTs = 1234

	dao.SavePlayer(player)
	dao.RemovePlayer(player.PlayerName)
	savedPlayer := dao.GetPlayer(player.PlayerName)

	assert.Nil(t, savedPlayer, "The original player should be destroyed")
}
예제 #4
0
func TestGetSavePlayer(t *testing.T) {
	dao := NewLobbyDAO()

	player := model.NewPlayer()
	player.PlayerName = "aron"
	player.JoinedTs = 1234

	dao.SavePlayer(player)
	savedPlayer := dao.GetPlayer(player.PlayerName)

	assert.NotEmpty(t, savedPlayer, "The original player should be rehydratable")
	assert.Equal(t, player.PlayerName, savedPlayer.PlayerName, "The rehydrated player name should be the same as the originally saved player")
	assert.Equal(t, player.JoinedTs, savedPlayer.JoinedTs, "The rehydrated player joined ts should be the same as the originally saved player")
}