public void GetPlacedBetsTestsAlmostAllPlacedBetsReturnsMinCorrectly() { var modelUtils = new ModelUtilities(); var initializer = new ModelDataInitializer(); List<UserGameSelection> userGameSelections = initializer.InitializeUserGameSelections(); userGameSelections = userGameSelections.Where(ugs => ugs.UserId == 1 && ugs.GameSpreadId >= 1 && ugs.GameSpreadId <= 16).ToList(); var actual = modelUtils.GetPlacedBets(userGameSelections); Assert.AreEqual(14, actual); }
public void GetPlacedBetsTests0PlacedBetsReturnsCorrectly() { var modelUtils = new ModelUtilities(); var initializer = new ModelDataInitializer(); List<UserGameSelection> userGameSelections = initializer.InitializeUserGameSelections(); userGameSelections = userGameSelections.Where(ugs => ugs.UserId == -1).ToList(); var actual = modelUtils.GetPlacedBets(userGameSelections); Assert.AreEqual(0, actual); }
public ActionResult GameFilter(int id = 0) { try { int currentGameFilterId = validateGameFilterId(id); SetViewBagGameFilter(currentGameFilterId); bool selectionDisabledForThisGameFilter = !db.GameFilters.FirstOrDefault(gf => gf.GameFilterId == currentGameFilterId).GameFilterEnabled; var utilities = new ModelUtilities(); var userId = GetUserIdentityId(); var userGameSelections = db.UserGameSelections .Include(ugs => ugs.GameSpread) .Include(t => t.PickTeam) .Include(g => g.GameSpread.FavoriteTeam) .Include(g => g.GameSpread.UnderdogTeam) .Include(g => g.GameSpread.Game) .Include(u => u.User) .Where(u => u.UserId == userId) .Where(ugs => ugs.GameSpread.Game.GameFilterId == currentGameFilterId) .ToList(); if (userGameSelections.Count == 0) { var gameSpreads = db.GameSpreads .Where(_ => _.Game.GameFilterId == currentGameFilterId) .OrderBy(_ => _.GameId) .ToList(); var user = db.Users.FirstOrDefault(_=>_.UserId == userId); var noBetTeam = db.Teams.FirstOrDefault(_ => _.TeamLongName == "No Bet"); userGameSelections = utilities.CreateDefaultUserGameSelections(gameSpreads, user, noBetTeam); // save to the db so the output has unique row numbers (it uses UserGameSelectionId) userGameSelections.ForEach(ugs => db.UserGameSelections.Add(ugs)); db.SaveChanges(); } var selection = new Selection(); //selection.UserGameSelections = userGameSelections; selection.PlacedBets = utilities.GetPlacedBets(userGameSelections); selection.BonusPoints = utilities.GetBonusPoints(userGameSelections, selection.MinSpentPointsForAnyOneWeek, selection.ExtraPointFactorPerBetOverMin); selection.SpentPoints = utilities.GetSpentPoints(userGameSelections); selection.PossibleBets = utilities.GetPossibleBets(userGameSelections); selection.SelectionDisabledForThisGameFilter = selectionDisabledForThisGameFilter; selection.GameRowsHaveBeenSaved = userGameSelections.Where(ugs => ugs.Saved == false).Count() == 0; // all records are false, meaning all have been saved var gameRows = new List<SelectionGameRow>(); foreach (var ugs in userGameSelections) { var gameRow = new SelectionGameRow(); /*gameRow.Bet = ugs.Bet; gameRow.GameSpread = ugs.GameSpread; gameRow.GameSpreadId = ugs.GameSpreadId; gameRow.PickTeam = ugs.PickTeam; gameRow.PickTeamId = ugs.PickTeamId; gameRow.Saved = ugs.Saved; gameRow.User = ugs.User; gameRow.UserGameSelectionId = ugs.UserGameSelectionId; gameRow.UserId = ugs.UserId;*/ if (ugs.GameSpread.Game.HomeTeam == 1) { if (ugs.GameSpread.UnderdogTeam.TeamId == ugs.GameSpread.Game.Team1.TeamId) { ugs.GameSpread.UnderdogTeam.TeamLongName = string.Concat("@" + ugs.GameSpread.UnderdogTeam.TeamLongName); } else { ugs.GameSpread.FavoriteTeam.TeamLongName = string.Concat("@" + ugs.GameSpread.FavoriteTeam.TeamLongName); } } else { if (ugs.GameSpread.UnderdogTeam.TeamId == ugs.GameSpread.Game.Team2.TeamId) { ugs.GameSpread.UnderdogTeam.TeamLongName = string.Concat("@" + ugs.GameSpread.UnderdogTeam.TeamLongName); } else { ugs.GameSpread.FavoriteTeam.TeamLongName = string.Concat("@" + ugs.GameSpread.FavoriteTeam.TeamLongName); } } gameRow.UserGameSelection = ugs; var betPickers = new List<BetPicker>(); for (int i = 0; i < selection.MaxBetForAnyOneGame; i++) { var betPicker = new BetPicker(); var berPickerValue = i + 1; if (ugs.Bet == 0) { betPicker.Disabled = true; } else { betPicker.Disabled = selection.SelectionDisabledForThisGameFilter || ugs.Saved; } betPicker.Toggled = berPickerValue == ugs.Bet; betPicker.BetValue = berPickerValue; betPickers.Add(betPicker); } gameRow.BetPickers.AddRange(betPickers); gameRows.Add(gameRow); } selection.GameRows = gameRows; // validation rules if (userGameSelections == null || userGameSelections.Count == 0) { //throw new ArgumentException(string.Format("Missing user game selections for given GameFilterId:{0}", currentGameFilterId)); ViewBag.MessageToUser = string.Format("Missing user game selections for given GameFilterId:{0}", currentGameFilterId); } return View(selection); } catch (Exception ex) { return HttpNotFound(ex.Message); } }