public void Index_ExceptionCaught_RethrowsException() { // Arrange var controller = new SeasonStandingsController(_service, _sharedService); var seasonID = 2017; bool?groupByDivision = true; A.CallTo(() => _sharedService.GetSeasonsOrderedAsync(null)).Throws <Exception>(); // Act // Assert Assert.ThrowsAsync <Exception>(async() => await controller.Index(seasonID, groupByDivision)); }
public async Task Index_GroupByDivisionNotNull_GroupByDivisionNotReset() { // Arrange var controller = new SeasonStandingsController(_service, _sharedService); var seasonID = 2017; bool?groupByDivision = true; 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.IsTrue(viewBag.GroupByDivision); A.CallTo(() => _service.GetSeasonStandings(SeasonStandingsService.SelectedSeason, true, null)) .MustHaveHappenedOnceExactly(); Assert.AreSame(seasonStandingsResults, resultAsViewResult.Model); }
public async Task Index_ShouldReturnIndexView() { // Arrange var seasonStandingsIndexViewModel = A.Fake <ISeasonStandingsIndexViewModel>(); var seasonRepository = A.Fake <ISeasonRepository>(); var seasons = new List <Season>(); A.CallTo(() => seasonRepository.GetSeasonsAsync()).Returns(seasons); var seasonStandingsRepository = A.Fake <ISeasonStandingsRepository>(); var seasonStandings = new List <SeasonTeamStanding>(); A.CallTo(() => seasonStandingsRepository.GetSeasonStandingsAsync( SeasonStandingsController.SelectedSeasonYear)).Returns(seasonStandings); var testController = new SeasonStandingsController(seasonStandingsIndexViewModel, seasonRepository, seasonStandingsRepository); // Act var result = await testController.Index(); // Assert A.CallTo(() => seasonRepository.GetSeasonsAsync()).MustHaveHappenedOnceExactly(); var orderedSeasons = seasons.OrderByDescending(s => s.Year); seasonStandingsIndexViewModel.Seasons.ShouldBeOfType <SelectList>(); seasonStandingsIndexViewModel.Seasons.Items.ShouldBe(seasons); seasonStandingsIndexViewModel.Seasons.DataValueField.ShouldBe <string>("Year"); seasonStandingsIndexViewModel.Seasons.DataTextField.ShouldBe <string>("Year"); seasonStandingsIndexViewModel.Seasons.SelectedValue.ShouldBe(SeasonStandingsController.SelectedSeasonYear); seasonStandingsIndexViewModel.SelectedSeasonYear.ShouldBe(SeasonStandingsController.SelectedSeasonYear); A.CallTo(() => seasonStandingsRepository.GetSeasonStandingsAsync( SeasonStandingsController.SelectedSeasonYear)).MustHaveHappenedOnceExactly(); seasonStandingsIndexViewModel.SeasonStandings.ShouldBe(seasonStandings); result.ShouldBeOfType <ViewResult>(); ((ViewResult)result).Model.ShouldBe(seasonStandingsIndexViewModel); }