public async Task <ActionResult> PredictGame([Bind(Include = "GuestSeasonID,GuestName,HostSeasonID,HostName")] GamePredictionViewModel matchup)
        {
            try
            {
                var seasons = await _sharedService.GetSeasonsOrderedAsync();

                // Show predicted guest score.
                var guestSeason = await _sharedService.FindEntityAsync(matchup.GuestName, matchup.GuestSeasonID);

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

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

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

                // Show predicted host score.
                var hostSeason = await _sharedService.FindEntityAsync(matchup.HostName, matchup.HostSeasonID);

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

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

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

                return(View(matchup));
            }
            catch (Exception ex)
            {
                _log.Error("Exception in GamePredictorController.PredictGame (POST): " + ex.Message);
                throw;
            }
        }
 /// <summary>
 /// Gets the details of a team's season asynchronously
 /// </summary>
 /// <param name="teamName">The name of the selected team</param>
 /// <param name="seasonID">The ID of the selected season</param>
 /// <param name="dbContext">Injected DbContext object for unit testing</param>
 /// <returns>A TeamSeasonDetailsViewModel instance containing the selected team's seasons details</returns>
 public async Task <TeamSeasonDetailsViewModel> GetTeamSeasonDetailsAsync(string teamName, int seasonID,
                                                                          ProFootballEntities dbContext = null)
 {
     return(new TeamSeasonDetailsViewModel
     {
         TeamSeason = await _sharedService.FindEntityAsync(teamName, seasonID, dbContext),
         TeamSeasonScheduleProfile = GetTeamSeasonScheduleProfile(teamName, seasonID, dbContext),
         TeamSeasonScheduleTotals = GetTeamSeasonScheduleTotals(teamName, seasonID, dbContext),
         TeamSeasonScheduleAverages = GetTeamSeasonScheduleAverages(teamName, seasonID, dbContext)
     });
 }
        public async Task PredictGamePost_HappyPath()
        {
            // Arrange
            var controller = new GamePredictorController(_service, _sharedService);

            var guestName     = "Guest";
            var guestSeasonID = 2017;
            var hostName      = "Host";
            var hostSeasonID  = 2016;

            GamePredictorService.GuestSeasonID = guestSeasonID;
            GamePredictorService.HostSeasonID  = hostSeasonID;

            var matchup = new GamePredictionViewModel
            {
                GuestName     = guestName,
                GuestSeasonID = guestSeasonID,
                HostName      = hostName,
                HostSeasonID  = hostSeasonID
            };

            var seasons = new List <SeasonViewModel>();

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

            var guestSeason = new TeamSeasonViewModel
            {
                TeamName = guestName,
                SeasonID = guestSeasonID
            };

            A.CallTo(() => _sharedService.FindEntityAsync(matchup.GuestName, matchup.GuestSeasonID, null))
            .Returns(guestSeason);

            var guestSeasons = new List <TeamSeasonViewModel>();

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

            var hostSeason = new TeamSeasonViewModel
            {
                TeamName = hostName,
                SeasonID = hostSeasonID
            };

            A.CallTo(() => _sharedService.FindEntityAsync(matchup.HostName, matchup.HostSeasonID, null))
            .Returns(hostSeason);

            var hostSeasons = new List <TeamSeasonViewModel>();

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

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

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

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

            var viewBag = resultAsViewResult.ViewBag;

            A.CallTo(() => _sharedService.FindEntityAsync(matchup.GuestName, matchup.GuestSeasonID, null))
            .MustHaveHappenedOnceExactly();

            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(guestSeason.SeasonID, 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);
            Assert.AreEqual(guestSeason.TeamName, viewBagGuestName.SelectedValues[0]);

            A.CallTo(() => _sharedService.FindEntityAsync(matchup.HostName, matchup.HostSeasonID, null))
            .MustHaveHappenedOnceExactly();

            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(hostSeason.SeasonID, 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);
            Assert.AreEqual(hostSeason.TeamName, viewBagHostName.SelectedValues[0]);

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