// 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; } }
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); }