public void MakePickDeletesExistingPick() { var existingPicks = new List<UserPick>(); var existingPick = new UserPick { GameId = GAME_ID, Id = EXISTING_PICK_ID, OptionGroupId = GROUP_ID, OptionType = GameOptionType.Winner, UserId = USER_ID }; existingPicks.Add(existingPick); _pickRepository .Setup(repository => repository.GetForGame(USER_ID, GAME_ID)) .Returns(existingPicks); var option = new Option<Team> { CutOff = DateTime.UtcNow.AddMinutes(1), GameId = GAME_ID, Id = OPTION_ID, GroupId = GROUP_ID }; _optionRepository .Setup(repository => repository.Get(OPTION_ID)) .Returns(option); _pickRepository .Setup(repository => repository.Pick(USER_ID, GAME_ID, OPTION_ID)) .Returns(1) .Verifiable(); _pickManager.Pick(USER_ID, OPTION_ID); _pickRepository.Verify(repository => repository.Pick(USER_ID, GAME_ID, OPTION_ID), Times.Once()); _pickRepository.Verify(repository => repository.Delete(USER_ID, EXISTING_PICK_ID), Times.Once()); }
public UserPick Pick(long userId, long gameOptionId) { // Get all the picks for the game var gameOption = _gameOptionRepository.Get(gameOptionId); if (gameOption == null) { throw new BusinessException(ErrorCodes.InvalidGameOption, "Requested game option does not exist."); } // Check if were past the cut off time if (DateTime.UtcNow > gameOption.CutOff) { throw new BusinessException(ErrorCodes.PastCutOffTime, "The cut off time to make the requested pick has passed."); } var gamePicks = _pickRepository.GetForGame(userId, gameOption.GameId); var gameId = gameOption.GameId; // Check if a pick already exists for the game and group var existingPick = gamePicks.FirstOrDefault(pick => pick.GameId == gameId && pick.OptionGroupId == gameOption.GroupId); // If a pick doesn't already exist for the game and group then add the pick if (existingPick != null) { // TODO: Log the existing pick _pickRepository.Delete(userId, existingPick.Id); } // Now make the pick var pickId = _pickRepository.Pick(userId, gameId, gameOptionId); var userPick = new UserPick { GameId = gameId, Id = pickId, OptionGroupId = gameOption.GroupId, OptionId = gameOptionId, OptionType = gameOption.Type, UserId = userId }; // TODO: Log the new pick return userPick; }
private static UserPick MapUserPick(MySqlDataReader dr) { var pick = new UserPick { GameId = dr.GetInt64("gameId"), Id = dr.GetInt64("id"), OptionId = dr.GetInt64("gameOptionId"), OptionGroupId = dr.GetInt64("groupId"), OptionType = (GameOptionType) dr.GetInt32("type"), UserId = dr.GetInt64("userId") }; var outcomeOrdinal = dr.GetOrdinal("outcome"); if (!dr.IsDBNull(outcomeOrdinal)) { pick.Outcome = (OptionOutcome) dr.GetInt32(outcomeOrdinal); } return pick; }
public IList<UserPick> GetForSeasonAllUsers(int season) { var picks = new List<UserPick>(); using (var conn = GetConnection()) { var cmd = new MySqlCommand(GET_PICKS_FOR_SEASON_FOR_ALL_USERS); cmd.Parameters.AddWithValue("@season", season); ExecuteReader(cmd, dr => { var pick = new UserPick { OptionId = dr.GetInt64("gameOptionId"), UserId = dr.GetInt64("userId") }; picks.Add(pick); }); } return picks; }