//[TestCase]
        public void TestCase1()
        {
            // Arrange
            var controller = new SeasonStandingsController(_service, _sharedService);

            // Act

            // Assert
        }
        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));
        }
Пример #3
0
        public void SetSelectedSeasonYear_WhenSeasonYearArgIsNull_ShouldReturnBadRequest()
        {
            // Arrange
            var seasonStandingsIndexViewModel = A.Fake <ISeasonStandingsIndexViewModel>();
            var seasonRepository          = A.Fake <ISeasonRepository>();
            var seasonStandingsRepository = A.Fake <ISeasonStandingsRepository>();
            var testController            = new SeasonStandingsController(seasonStandingsIndexViewModel, seasonRepository,
                                                                          seasonStandingsRepository);

            int?seasonYear = null;

            // Act
            var result = testController.SetSelectedSeasonYear(seasonYear);

            // Assert
            result.ShouldBeOfType <BadRequestResult>();
        }
        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);
        }
Пример #5
0
        public void SetSelectedSeasonYear_WhenSeasonYearArgIsNotNull_ShouldSetSelectedSeasonYearAndRedirectToIndexView()
        {
            // Arrange
            var seasonStandingsIndexViewModel = A.Fake <ISeasonStandingsIndexViewModel>();
            var seasonRepository          = A.Fake <ISeasonRepository>();
            var seasonStandingsRepository = A.Fake <ISeasonStandingsRepository>();
            var testController            = new SeasonStandingsController(seasonStandingsIndexViewModel, seasonRepository,
                                                                          seasonStandingsRepository);

            int?seasonYear = 1920;

            // Act
            var result = testController.SetSelectedSeasonYear(seasonYear);

            // Assert
            SeasonStandingsController.SelectedSeasonYear.ShouldBe(seasonYear.Value);
            result.ShouldBeOfType <RedirectToActionResult>();
            ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index));
        }
Пример #6
0
        public void SetGroupByDivision_WhenGroupByDivisionIsNotNull_ShouldSetGroupByDivisionAndRedirectToIndexView()
        {
            // Arrange
            var seasonStandingsIndexViewModel = A.Fake <ISeasonStandingsIndexViewModel>();
            var seasonRepository          = A.Fake <ISeasonRepository>();
            var seasonStandingsRepository = A.Fake <ISeasonStandingsRepository>();
            var testController            = new SeasonStandingsController(seasonStandingsIndexViewModel, seasonRepository,
                                                                          seasonStandingsRepository);

            bool?groupByDivision = true;

            // Act
            var result = testController.SetGroupByDivision(groupByDivision);

            // Assert
            SeasonStandingsController.GroupByDivision.ShouldBeTrue();
            result.ShouldBeOfType <RedirectToActionResult>();
            ((RedirectToActionResult)result).ActionName.ShouldBe <string>(nameof(testController.Index));
        }
Пример #7
0
        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);
        }
        public async Task GetSeasonStandings_WhenExceptionIsCaught_ShouldReturnInternalServerError()
        {
            // Arrange
            var seasonStandingsRepository = A.Fake <ISeasonStandingsRepository>();

            A.CallTo(() => seasonStandingsRepository.GetSeasonStandingsAsync(A <int> .Ignored)).Throws <Exception>();

            var mapper = A.Fake <IMapper>();

            var testController = new SeasonStandingsController(seasonStandingsRepository, mapper);

            int seasonYear = 1920;

            // Act
            var result = await testController.GetSeasonStandings(seasonYear);

            // Assert
            result.Result.ShouldBeOfType <ObjectResult>();
            ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError);
            ((ObjectResult)result.Result).Value.ShouldBe("Database failure");
        }
        public async Task GetSeasonStandings_WhenNoExceptionIsCaught_ShouldGetSeasonStandings()
        {
            // Arrange
            var seasonStandingsRepository = A.Fake <ISeasonStandingsRepository>();
            var seasonStandings           = new List <SeasonTeamStanding>();

            A.CallTo(() => seasonStandingsRepository.GetSeasonStandingsAsync(A <int> .Ignored)).Returns(seasonStandings);

            var mapper = A.Fake <IMapper>();

            var testController = new SeasonStandingsController(seasonStandingsRepository, mapper);

            int seasonYear = 1920;

            // Act
            var result = await testController.GetSeasonStandings(seasonYear);

            // Assert
            A.CallTo(() => seasonStandingsRepository.GetSeasonStandingsAsync(seasonYear))
            .MustHaveHappenedOnceExactly();
            A.CallTo(() => mapper.Map <SeasonTeamStandingModel[]>(seasonStandings)).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <ActionResult <SeasonTeamStandingModel[]> >();
            result.Value.ShouldBe(mapper.Map <SeasonTeamStandingModel[]>(seasonStandings));
        }