public void CalculateUserResultsTestHappyPath() { var adminController = new AdminController(); int userId = 1; int gameFilterId = 1; //Team noBetPickTeam = new Team() { TeamId = 1, TeamLongName = "No Bet", TeamOtherName = "No Bet", TeamShortName = "X " }; var userGameResults = new List<UserGameResult>() { new UserGameResult(){ UserGameResultId = 1, UserGameSelectionId = 1, BetResult = 1, BetPoints = 2, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 2, UserGameSelectionId = 2, BetResult = 0, BetPoints = 0, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 3, UserGameSelectionId = 3, BetResult = 0, BetPoints = 0, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 4, UserGameSelectionId = 4, BetResult = -1, BetPoints = -1, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 5, UserGameSelectionId = 5, BetResult = -1, BetPoints = -1, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 6, UserGameSelectionId = 6, BetResult = 1, BetPoints = 1, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 7, UserGameSelectionId = 7, BetResult = 1, BetPoints = 3, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, }; var expected = new UserResult() { Bets = 5, GameFilterId = gameFilterId, Points = 4, UserId = userId, Wins = 3 }; var actual = adminController.CalculateUserResults(userId, gameFilterId, userGameResults); Assert.AreEqual(expected.Bets, actual.Bets); Assert.AreEqual(expected.GameFilterId, actual.GameFilterId); Assert.AreEqual(expected.Points, actual.Points); Assert.AreEqual(expected.UserId, actual.UserId); Assert.AreEqual(expected.Wins, actual.Wins); }
public void CalculateUserResultsTestWrongUserIdShouldError() { var adminController = new AdminController(); int userId = 1; int gameFilterId = 1; var userGameResults = new List<UserGameResult>() { new UserGameResult(){ UserGameResultId = 1, UserGameSelectionId = 1, BetResult = 1, BetPoints = 2, UserGameSelection = new UserGameSelection(){UserId = 2, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 2, UserGameSelectionId = 2, BetResult = 0, BetPoints = 0, UserGameSelection = new UserGameSelection(){UserId = 2, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 3, UserGameSelectionId = 3, BetResult = 0, BetPoints = 0, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 4, UserGameSelectionId = 4, BetResult = -1, BetPoints = -1, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 5, UserGameSelectionId = 5, BetResult = -1, BetPoints = -1, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 6, UserGameSelectionId = 6, BetResult = 1, BetPoints = 1, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, new UserGameResult(){ UserGameResultId = 7, UserGameSelectionId = 7, BetResult = 1, BetPoints = 3, UserGameSelection = new UserGameSelection(){UserId = userId, GameSpread = new GameSpread(){Game = new Game(){GameFilterId = gameFilterId}}}}, }; var expected = new UserResult() { Bets = 5, GameFilterId = gameFilterId, Points = 4, UserId = userId, Wins = 3 }; try { var actual = adminController.CalculateUserResults(userId, gameFilterId, userGameResults); Assert.Fail("Should have thrown exception"); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(ArgumentException)); Assert.IsTrue(ex.Message.Contains("The user game result list has records for the wrong user (2) and/or game filter (0)")); } }
public UserResult CalculateUserResults(int userId, int gameFilterId, List<UserGameResult> thisUsersGameResultsForThisGameFilter) { string logProcess = "AdminController.GameResultProcessing.BuildUserResults.CalculateUserResults"; try { var bets = 0; var wins = 0; var points = 0; var wrongUserIdCount = thisUsersGameResultsForThisGameFilter .Where(ugr => ugr.UserGameSelection.UserId != userId) .Count(); var wrongGameFilterIdCount = thisUsersGameResultsForThisGameFilter .Where(ugr => ugr.UserGameSelection.GameSpread.Game.GameFilterId != gameFilterId) .Count(); if (wrongUserIdCount > 0 || wrongGameFilterIdCount > 0) { throw new ArgumentException(string.Format("The user game result list has records for the wrong user ({0}) and/or game filter ({1})", wrongUserIdCount, wrongGameFilterIdCount)); } // just as a double check, restrict the list to this user and gameFilter bets = thisUsersGameResultsForThisGameFilter .Where(ugr => ugr.BetResult == 1 || ugr.BetResult == -1) .Count(); wins = thisUsersGameResultsForThisGameFilter .Where(ugr => ugr.BetResult == 1) .Count(); points = thisUsersGameResultsForThisGameFilter .Sum(ugr => ugr.BetPoints); var userResult = new UserResult() { Bets = bets, GameFilterId = gameFilterId, Points = points, UserId = userId, Wins = wins }; return userResult; } catch (Exception ex) { logMessages.Add(new Log() { GameDateTime = DateTime.Now, Type = "Error", Process = logProcess, Message = ex.Message }); throw; } finally { logMessages.Add(new Log() { GameDateTime = DateTime.Now, Type = "Info", Process = logProcess, Message = "Ending" }); } }