Exemplo n.º 1
0
        public async Task GetLeagueSeasons_WhenExceptionIsCaught_ShouldReturnInternalServerError()
        {
            // Arrange
            var leagueSeasonRepository = A.Fake <ILeagueSeasonRepository>();

            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonsAsync()).Throws <Exception>();

            var sharedRepository = A.Fake <ISharedRepository>();
            var mapper           = A.Fake <IMapper>();
            var linkGenerator    = A.Fake <LinkGenerator>();

            var testController = new LeagueSeasonsController(leagueSeasonRepository, sharedRepository, mapper,
                                                             linkGenerator);

            // Act
            var result = await testController.GetLeagueSeasons();

            // Assert
            result.Result.ShouldBeOfType <ObjectResult>();
            ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError);
            ((ObjectResult)result.Result).Value.ShouldBe("Database failure");
        }
Exemplo n.º 2
0
        public async Task GetLeagueSeasons_WhenNoExceptionIsCaught_ShouldGetLeagueSeasons()
        {
            // Arrange
            var leagueSeasonRepository = A.Fake <ILeagueSeasonRepository>();
            var leagueSeasons          = new List <LeagueSeason>();

            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonsAsync()).Returns(leagueSeasons);

            var sharedRepository = A.Fake <ISharedRepository>();
            var mapper           = A.Fake <IMapper>();
            var linkGenerator    = A.Fake <LinkGenerator>();

            var testController = new LeagueSeasonsController(leagueSeasonRepository, sharedRepository, mapper, linkGenerator);

            // Act
            var result = await testController.GetLeagueSeasons();

            // Assert
            A.CallTo(() => leagueSeasonRepository.GetLeagueSeasonsAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => mapper.Map <LeagueSeasonModel[]>(leagueSeasons)).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <ActionResult <LeagueSeasonModel[]> >();
            result.Value.ShouldBe(mapper.Map <LeagueSeasonModel[]>(leagueSeasons));
        }