// GET: Games
        public async Task <ActionResult> Index(int?seasonID, int?week, string guestSearchString,
                                               string hostSearchString)
        {
            try
            {
                var seasons = await _sharedService.GetSeasonsOrderedAsync();

                _service.SetSelectedSeason(seasons, seasonID);
                ViewBag.SeasonID = new SelectList(seasons, "ID", "ID", GamesService.SelectedSeason);

                var weeks = await _service.GetWeeksAsync(GamesService.SelectedSeason);

                _service.SetSelectedWeek(week);
                ViewBag.Week = new SelectList(weeks, "ID", "ID", GamesService.SelectedWeek);

                var games = await _service.GetGamesAsync(GamesService.SelectedSeason, GamesService.SelectedWeek.ID,
                                                         guestSearchString, hostSearchString);

                return(View(games));
            }
            catch (Exception ex)
            {
                _log.Error("Exception in GamesController.Index: " + ex.Message);
                throw;
            }
        }
        // GET: GamePredictor
        public async Task <ActionResult> PredictGame()
        {
            try
            {
                await _service.GetGuestAndHostSeasonIds();

                var seasons = await _sharedService.GetSeasonsOrderedAsync();

                ViewBag.GuestSeasonID = new SelectList(seasons, "ID", "ID", GamePredictorService.GuestSeasonID);

                var guestSeasons = await _service.GetEntities((int)GamePredictorService.GuestSeasonID);

                ViewBag.GuestName = new SelectList(guestSeasons, "TeamName", "TeamName");

                ViewBag.HostSeasonID = new SelectList(seasons, "ID", "ID", GamePredictorService.HostSeasonID);

                var hostSeasons = await _service.GetEntities((int)GamePredictorService.HostSeasonID);

                ViewBag.HostName = new SelectList(hostSeasons, "TeamName", "TeamName");

                return(View());
            }
            catch (Exception ex)
            {
                _log.Error("Exception in GamePredictorController.PredictGame (GET): " + ex.Message);
                throw;
            }
        }
        // GET: SeasonStandings
        public async Task <ActionResult> Index(int?seasonID, bool?groupByDivision)
        {
            try
            {
                var seasons = await _sharedService.GetSeasonsOrderedAsync();

                _service.SetSelectedSeason(seasons, seasonID);
                ViewBag.SeasonID = new SelectList(seasons, "ID", "ID", SeasonStandingsService.SelectedSeason);

                if (groupByDivision == null)
                {
                    groupByDivision = false;
                }

                ViewBag.GroupByDivision = groupByDivision;

                var seasonStandingsResults =
                    _service.GetSeasonStandings(SeasonStandingsService.SelectedSeason, groupByDivision);

                return(View(seasonStandingsResults));
            }
            catch (Exception ex)
            {
                _log.Error("Exception in SeasonStandingsController.Index: " + ex.Message);
                throw;
            }
        }
        public async Task Index_GroupByDivisionNull_GroupByDivisionSetToFalse()
        {
            // Arrange
            var controller = new SeasonStandingsController(_service, _sharedService);

            var  seasonID        = 2017;
            bool?groupByDivision = null;

            var seasons = new List <SeasonViewModel>();

            A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).Returns(seasons);

            var seasonStandingsResults = new List <SeasonStandingsResultViewModel>();

            A.CallTo(() => _service.GetSeasonStandings(A <int> .Ignored, A <bool> .Ignored, null))
            .Returns(seasonStandingsResults);

            // Act
            var result = await controller.Index(seasonID, groupByDivision);

            // Assert
            A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _service.SetSelectedSeason(seasons, seasonID)).MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <ViewResult>(result);
            var resultAsViewResult = result as ViewResult;

            var viewBag = resultAsViewResult.ViewBag;

            var viewBagSeasonID = viewBag.SeasonID;

            Assert.IsInstanceOf <SelectList>(viewBagSeasonID);
            Assert.AreSame(seasons, viewBagSeasonID.Items);
            Assert.AreEqual("ID", viewBagSeasonID.DataValueField);
            Assert.AreEqual("ID", viewBagSeasonID.DataTextField);
            Assert.AreEqual(SeasonStandingsService.SelectedSeason, viewBagSeasonID.SelectedValues[0]);

            Assert.IsFalse(viewBag.GroupByDivision);

            A.CallTo(() => _service.GetSeasonStandings(SeasonStandingsService.SelectedSeason, false, null))
            .MustHaveHappenedOnceExactly();

            Assert.AreSame(seasonStandingsResults, resultAsViewResult.Model);
        }
        // GET: TeamSeasons
        public async Task <ActionResult> Index(int?seasonID, string sortOrder)
        {
            try
            {
                var seasons = await _sharedService.GetSeasonsOrderedAsync();

                _service.SetSelectedSeason(seasons, seasonID, sortOrder);
                ViewBag.SeasonID = new SelectList(seasons, "ID", "ID", TeamSeasonsService.SelectedSeason);

                ViewBag.TeamSortParm =
                    sortOrder == "team_desc" ? "team_desc" : "team_asc";
                ViewBag.WinsSortParm =
                    sortOrder == "wins_desc" ? "wins_desc" : "wins_asc";
                ViewBag.LossesSortParm =
                    sortOrder == "losses_desc" ? "losses_desc" : "losses_asc";
                ViewBag.TiesSortParm =
                    sortOrder == "ties_desc" ? "ties_desc" : "ties_asc";
                ViewBag.WinningPercentageSortParm =
                    sortOrder == "win_pct_desc" ? "win_pct_desc" : "win_pct_asc";
                ViewBag.PointsForSortParm =
                    sortOrder == "pf_desc" ? "pf_desc" : "pf_asc";
                ViewBag.PointsAgainstSortParm =
                    sortOrder == "pa_desc" ? "pa_desc" : "pa_asc";
                ViewBag.PythagoreanWinsSortParm =
                    sortOrder == "pyth_wins_desc" ? "pyth_wins_desc" : "pyth_wins_asc";
                ViewBag.PythagoreanLossesSortParm =
                    sortOrder == "pyth_losses_desc" ? "pyth_losses_desc" : "pyth_losses_asc";
                ViewBag.OffensiveAverageSortParm =
                    sortOrder == "off_avg_desc" ? "off_avg_desc" : "off_avg_asc";
                ViewBag.OffensiveFactorSortParm =
                    sortOrder == "off_factor_desc" ? "off_factor_desc" : "off_factor_asc";
                ViewBag.OffensiveIndexSortParm =
                    sortOrder == "off_index_desc" ? "off_index_desc" : "off_index_asc";
                ViewBag.DefensiveAverageSortParm =
                    sortOrder == "def_avg_desc" ? "def_avg_desc" : "def_avg_asc";
                ViewBag.DefensiveFactorSortParm =
                    sortOrder == "def_factor_desc" ? "def_factor_desc" : "def_factor_asc";
                ViewBag.DefensiveIndexSortParm =
                    sortOrder == "def_index_desc" ? "def_index_desc" : "def_index_asc";
                ViewBag.FinalPythagoreanWinningPercentageSortParm =
                    sortOrder == "fin_pyth_pct_desc" ? "fin_pyth_pct_desc" : "fin_pyth_pct_asc";

                var teamSeasons =
                    await _service.GetEntitiesOrderedAsync(TeamSeasonsService.SelectedSeason, sortOrder);

                return(View(teamSeasons));
            }
            catch (Exception ex)
            {
                _log.Error("Exception in TeamSeasonsController.Index: " + ex.Message);

                throw;
            }
        }
        public async Task PredictGameGet_HappyPath()
        {
            // Arrange
            var controller = new GamePredictorController(_service, _sharedService);

            var seasons = new List <SeasonViewModel>();

            A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).Returns(seasons);

            GamePredictorService.GuestSeasonID = 2017;
            var guestSeasons = new List <TeamSeasonViewModel>();

            A.CallTo(() => _service.GetEntities((int)GamePredictorService.GuestSeasonID, null))
            .Returns(guestSeasons);

            GamePredictorService.HostSeasonID = 2016;
            var hostSeasons = new List <TeamSeasonViewModel>();

            A.CallTo(() => _service.GetEntities((int)GamePredictorService.HostSeasonID, null))
            .Returns(hostSeasons);

            // Act
            var result = await controller.PredictGame();

            // Assert
            A.CallTo(() => _service.GetGuestAndHostSeasonIds(null)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <ViewResult>(result);

            var viewBag = (result as ViewResult).ViewBag;

            var viewBagGuestSeasonID = viewBag.GuestSeasonID;

            Assert.IsInstanceOf <SelectList>(viewBagGuestSeasonID);
            Assert.AreSame(seasons, viewBagGuestSeasonID.Items);
            Assert.AreEqual("ID", viewBagGuestSeasonID.DataValueField);
            Assert.AreEqual("ID", viewBagGuestSeasonID.DataTextField);
            Assert.AreEqual(GamePredictorService.GuestSeasonID, viewBagGuestSeasonID.SelectedValues[0]);

            A.CallTo(() => _service.GetEntities((int)GamePredictorService.GuestSeasonID, null))
            .MustHaveHappenedOnceExactly();

            var viewBagGuestName = viewBag.GuestName;

            Assert.IsInstanceOf <SelectList>(viewBagGuestName);
            Assert.AreSame(guestSeasons, viewBagGuestName.Items);
            Assert.AreEqual("TeamName", viewBagGuestName.DataValueField);
            Assert.AreEqual("TeamName", viewBagGuestName.DataTextField);

            var viewBagHostSeasonID = viewBag.HostSeasonID;

            Assert.IsInstanceOf <SelectList>(viewBagHostSeasonID);
            Assert.AreSame(seasons, viewBagHostSeasonID.Items);
            Assert.AreEqual("ID", viewBagHostSeasonID.DataValueField);
            Assert.AreEqual("ID", viewBagHostSeasonID.DataTextField);
            Assert.AreEqual(GamePredictorService.HostSeasonID, viewBagHostSeasonID.SelectedValues[0]);

            A.CallTo(() => _service.GetEntities((int)GamePredictorService.HostSeasonID, null))
            .MustHaveHappenedOnceExactly();

            var viewBagHostName = viewBag.HostName;

            Assert.IsInstanceOf <SelectList>(viewBagHostName);
            Assert.AreSame(hostSeasons, viewBagHostName.Items);
            Assert.AreEqual("TeamName", viewBagHostName.DataValueField);
            Assert.AreEqual("TeamName", viewBagHostName.DataTextField);
        }
        public async Task Index_HappyPath()
        {
            // Arrange
            var controller = new GamesController(_service, _sharedService);

            var seasonID          = 2017;
            var week              = 1;
            var guestSearchString = "Guest";
            var hostSearchString  = "Host";

            var seasons = new List <SeasonViewModel>();

            A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).Returns(seasons);
            GamesService.SelectedSeason = seasonID;

            var weeks = new List <WeekViewModel>();

            A.CallTo(() => _service.GetWeeksAsync(A <int> .Ignored, null)).Returns(weeks);
            GamesService.SelectedWeek = new WeekViewModel(week);

            var games = new List <GameViewModel>();

            A.CallTo(() => _service.GetGamesAsync(A <int> .Ignored, A <string> .Ignored, A <string> .Ignored,
                                                  A <string> .Ignored, null)).Returns(games);

            // Act
            var result = await controller.Index(seasonID, week, guestSearchString, hostSearchString);

            // Assert
            A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _service.SetSelectedSeason(seasons, GamesService.SelectedSeason))
            .MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <ViewResult>(result);
            var resultAsViewResult = result as ViewResult;

            var viewBag = resultAsViewResult.ViewBag;

            var viewBagSeasonID = viewBag.SeasonID;

            Assert.IsInstanceOf <SelectList>(viewBagSeasonID);
            Assert.AreSame(seasons, viewBagSeasonID.Items);
            Assert.AreEqual("ID", viewBagSeasonID.DataValueField);
            Assert.AreEqual("ID", viewBagSeasonID.DataTextField);
            Assert.AreEqual(GamesService.SelectedSeason, viewBagSeasonID.SelectedValues[0]);

            A.CallTo(() => _service.GetWeeksAsync(seasonID, null)).MustHaveHappenedOnceExactly();
            A.CallTo(() => _service.SetSelectedWeek(week)).MustHaveHappenedOnceExactly();

            var viewBagWeek = viewBag.Week;

            Assert.IsInstanceOf <SelectList>(viewBagWeek);
            Assert.AreSame(weeks, viewBagWeek.Items);
            Assert.AreEqual("ID", viewBagWeek.DataValueField);
            Assert.AreEqual("ID", viewBagWeek.DataTextField);
            Assert.AreEqual(GamesService.SelectedWeek, viewBagWeek.SelectedValues[0]);

            A.CallTo(() => _service.GetGamesAsync(seasonID, GamesService.SelectedWeek.ID,
                                                  guestSearchString, hostSearchString, null)).MustHaveHappenedOnceExactly();

            Assert.AreSame(games, resultAsViewResult.Model);
        }