Esempio n. 1
0
        public void BuildUserGameResultsTestsHappyPath()
        {
            Database.SetInitializer<SelectumContext>(null);
            SelectumContext db = new SelectumContext();

            var controller = new AdminController();
            int gameFilterId = 6;
            int extraPointFactorPerBetOverMin = 2;
            var noBetPickTeam = db.Teams.First(t => t.TeamLongName == "No Bet");
            List<User> users = db.Users.ToList();
            var thisGameFiltersGameResults = db.GameResults
                                                .Include(gr => gr.GameSpread)
                                                .Include(gr => gr.GameSpread.FavoriteTeam)
                                                .Include(gr => gr.GameSpread.UnderdogTeam)
                                                .Include(gr => gr.GameSpread.Game)
                                                .Include(gr => gr.WinnerTeam)
                                                .Where(gr => gr.GameSpread.Game.GameFilterId == gameFilterId)
                                                .ToList();

            var thisGameFiltersUsersGameSelections = db.UserGameSelections
                                                        .Include(ugs => ugs.GameSpread)
                                                        .Include(ugs => ugs.GameSpread.Game)
                                                        .Include(ugs => ugs.User)
                                                        .Include(ugs => ugs.PickTeam)
                                                        .Where(ugs => ugs.GameSpread.Game.GameFilterId == gameFilterId)
                                                        .ToList();
            var actual = controller.BuildUserGameResults(gameFilterId, thisGameFiltersGameResults, thisGameFiltersUsersGameSelections, users, noBetPickTeam, extraPointFactorPerBetOverMin);
            Assert.Inconclusive("This is just a test harness");
        }
Esempio n. 2
0
        public void BuildUserGameResultsTestsRebuildTable()
        {
            Database.SetInitializer<SelectumContext>(null);
            SelectumContext db = new SelectumContext();

            db.UserGameResults.ToList().ForEach(ugr => db.UserGameResults.Remove(ugr));
            db.SaveChanges();

            var controller = new AdminController();

            int extraPointFactorPerBetOverMin = 2;
            var noBetPickTeam = db.Teams.First(t => t.TeamLongName == "No Bet");
            List<User> users = db.Users.ToList();

            for (int i = 1; i <= 14; i++)
            {
                int gameFilterId = i;

                var thisGameFiltersGameResults = db.GameResults
                                                    .Include(gr => gr.GameSpread)
                                                    .Include(gr => gr.GameSpread.FavoriteTeam)
                                                    .Include(gr => gr.GameSpread.UnderdogTeam)
                                                    .Include(gr => gr.GameSpread.Game)
                                                    .Include(gr => gr.WinnerTeam)
                                                    .Where(gr => gr.GameSpread.Game.GameFilterId == gameFilterId)
                                                    .ToList();

                var thisGameFiltersUsersGameSelections = db.UserGameSelections
                                                            .Include(ugs => ugs.GameSpread)
                                                            .Include(ugs => ugs.GameSpread.Game)
                                                            .Include(ugs => ugs.User)
                                                            .Include(ugs => ugs.PickTeam)
                                                            .Where(ugs => ugs.GameSpread.Game.GameFilterId == gameFilterId)
                                                            .ToList();
                var userGameResults = controller.BuildUserGameResults(gameFilterId, thisGameFiltersGameResults, thisGameFiltersUsersGameSelections, users, noBetPickTeam, extraPointFactorPerBetOverMin);

                userGameResults.ForEach(ugr => db.UserGameResults.Add(ugr));
                db.SaveChanges();
            }
            Assert.Fail("This should not be ran except for manually");
        }
Esempio n. 3
0
        public void CalculateUserGameResultsTestAllFavoriteWins()
        {
            var adminController = new AdminController();
            int userId = 1;
            int gameFilterId = 1;
            int extraPointFactorPerBetOverMin = 2;
            Team noBetPickTeam = new Team() { TeamId = 1, TeamLongName = "No Bet", TeamOtherName = "No Bet", TeamShortName = "X  " };
            var gameResults = new List<GameResult>()
                                    {
                                        new GameResult(){ GameSpreadId = 1, WinnerTeamId = 10, GameSpread = new GameSpread(){UnderdogTeamId = 11, Game = new Game(){GameFilterId =1}}},
                                        new GameResult(){ GameSpreadId = 2, WinnerTeamId = 20, GameSpread = new GameSpread(){UnderdogTeamId = 21, Game = new Game(){GameFilterId =1}}},
                                        new GameResult(){ GameSpreadId = 3, WinnerTeamId = 30, GameSpread = new GameSpread(){UnderdogTeamId = 31, Game = new Game(){GameFilterId =1}}}
                                    };
            var userGameSelections = new List<UserGameSelection>()
                                    {
                                        new UserGameSelection(){ UserGameSelectionId = 1, UserId = 1, GameSpreadId = 1, PickTeamId = 10, Bet = 3, GameSpread = new GameSpread(){Game = new Game(){GameFilterId =1}}},
                                        new UserGameSelection(){ UserGameSelectionId = 2, UserId = 1, GameSpreadId = 2, PickTeamId = 20, Bet = 2, GameSpread = new GameSpread(){Game = new Game(){GameFilterId =1}}},
                                        new UserGameSelection(){ UserGameSelectionId = 3, UserId = 1, GameSpreadId = 3, PickTeamId = 30, Bet = 1, GameSpread = new GameSpread(){Game = new Game(){GameFilterId =1}}}
                                    };

            var expected = new List<UserGameResult>()
                                    {
                                        new UserGameResult(){ UserGameSelectionId=1, BetResult=1, BetPoints=3},
                                        new UserGameResult(){ UserGameSelectionId=2, BetResult=1, BetPoints=2},
                                        new UserGameResult(){ UserGameSelectionId=3, BetResult=1, BetPoints=1}
                                    };
            var actual = adminController.CalculateUserGameResults(userId, gameFilterId, gameResults, userGameSelections, noBetPickTeam, extraPointFactorPerBetOverMin);

            Assert.AreEqual(expected.Count, actual.Count);
            foreach (var exp in expected)
            {
                Assert.AreEqual(exp.UserGameSelectionId, actual.FirstOrDefault(a => a.UserGameSelectionId == exp.UserGameSelectionId).UserGameSelectionId);
                Assert.AreEqual(exp.BetPoints, actual.FirstOrDefault(a => a.UserGameSelectionId == exp.UserGameSelectionId).BetPoints);
                Assert.AreEqual(exp.BetResult, actual.FirstOrDefault(a => a.UserGameSelectionId == exp.UserGameSelectionId).BetResult);
            }
        }
Esempio n. 4
0
        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)"));
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public void CalculateUserGameResultsTestWrongUserIdShouldError()
        {
            var adminController = new AdminController();
            int userId = 1;
            int gameFilterId = 1;
            int extraPointFactorPerBetOverMin = 2;
            Team noBetPickTeam = new Team() { TeamId = 1, TeamLongName = "No Bet", TeamOtherName = "No Bet", TeamShortName = "X  " };
            var gameResults = new List<GameResult>()
                                    {
                                        new GameResult(){ GameSpreadId = 1, WinnerTeamId = 10, GameSpread = new GameSpread(){UnderdogTeamId = 11, Game = new Game(){GameFilterId =1}}},
                                        new GameResult(){ GameSpreadId = 2, WinnerTeamId = 20, GameSpread = new GameSpread(){UnderdogTeamId = 21, Game = new Game(){GameFilterId =1}}},
                                        new GameResult(){ GameSpreadId = 3, WinnerTeamId = 30, GameSpread = new GameSpread(){UnderdogTeamId = 31, Game = new Game(){GameFilterId =1}}}
                                    };
            var userGameSelections = new List<UserGameSelection>()
                                    {
                                        new UserGameSelection(){ UserGameSelectionId = 1, UserId = 1, GameSpreadId = 1, PickTeamId = 10, Bet = 3, GameSpread = new GameSpread(){Game = new Game(){GameFilterId =1}}},
                                        new UserGameSelection(){ UserGameSelectionId = 2, UserId = 2, GameSpreadId = 2, PickTeamId = 20, Bet = 2, GameSpread = new GameSpread(){Game = new Game(){GameFilterId =1}}},
                                        new UserGameSelection(){ UserGameSelectionId = 3, UserId = 1, GameSpreadId = 4, PickTeamId = 30, Bet = 1, GameSpread = new GameSpread(){Game = new Game(){GameFilterId =1}}}
                                    };

            var expected = new List<UserGameResult>()
                                    {
                                        new UserGameResult(){ UserGameSelectionId=1, BetResult=1, BetPoints=3},
                                        new UserGameResult(){ UserGameSelectionId=2, BetResult=1, BetPoints=2},
                                        new UserGameResult(){ UserGameSelectionId=3, BetResult=1, BetPoints=1}
                                    };
            try
            {
                var actual = adminController.CalculateUserGameResults(userId, gameFilterId, gameResults, userGameSelections, noBetPickTeam, extraPointFactorPerBetOverMin);
                Assert.Fail("Should have thrown an exception");
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
                Assert.IsTrue(ex.Message.Contains("The user game selection list has records for the wrong user (1) and/or game filter (0)"));
            }
        }
Esempio n. 7
0
        public void BuildUserResultsTestsHappyPath()
        {
            Database.SetInitializer<SelectumContext>(null);
            SelectumContext db = new SelectumContext();

            var controller = new AdminController();
            int gameFilterId = 6;
            List<User> users = db.Users.ToList();

            var thisGameFiltersUsersGameSelections = db.UserGameResults
                                                        .Include(ugs => ugs.UserGameSelection)
                                                        .Include(ugs => ugs.UserGameSelection.GameSpread)
                                                        .Include(ugs => ugs.UserGameSelection.GameSpread.Game)
                                                        .Include(ugs => ugs.UserGameSelection.User)
                                                        .Include(ugs => ugs.UserGameSelection.PickTeam)
                                                        .Where(ugs => ugs.UserGameSelection.GameSpread.Game.GameFilterId == gameFilterId)
                                                        .ToList();
            var actual = controller.BuildUserResults(gameFilterId, thisGameFiltersUsersGameSelections, users);
            Assert.Inconclusive("This is just a test harness");
        }
Esempio n. 8
0
        public void BuildUserResultsTestsRebuildTable()
        {
            Database.SetInitializer<SelectumContext>(null);
            SelectumContext db = new SelectumContext();

            db.UserResults.ToList().ForEach(ur => db.UserResults.Remove(ur));
            db.SaveChanges();

            var controller = new AdminController();
            List<User> users = db.Users.ToList();
            for (int i = 1; i <= 14; i++)
            {
                int gameFilterId = i;

                var thisGameFiltersUsersGameSelections = db.UserGameResults
                                                            .Include(ugs => ugs.UserGameSelection)
                                                            .Include(ugs => ugs.UserGameSelection.GameSpread)
                                                            .Include(ugs => ugs.UserGameSelection.GameSpread.Game)
                                                            .Include(ugs => ugs.UserGameSelection.User)
                                                            .Include(ugs => ugs.UserGameSelection.PickTeam)
                                                            .Where(ugs => ugs.UserGameSelection.GameSpread.Game.GameFilterId == gameFilterId)
                                                            .ToList();
                var userResults = controller.BuildUserResults(gameFilterId, thisGameFiltersUsersGameSelections, users);
                userResults.ForEach(ur => db.UserResults.Add(ur));
                db.SaveChanges();
            }
            Assert.Fail("This should not be ran except for manually");
        }