示例#1
0
        public async Task GetLeagues_WhenExceptionIsCaught_ShouldReturnInternalServerError()
        {
            // Arrange
            var leagueRepository = A.Fake <ILeagueRepository>();

            A.CallTo(() => leagueRepository.GetLeaguesAsync()).Throws <Exception>();

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

            var testController = new LeaguesController(leagueRepository, sharedRepository, mapper, linkGenerator);

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

            // Assert
            result.Result.ShouldBeOfType <ObjectResult>();
            ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError);
            ((ObjectResult)result.Result).Value.ShouldBe("Database failure");
        }
示例#2
0
        public async Task GetLeagues_WhenNoExceptionIsCaught_ShouldGetLeagues()
        {
            // Arrange
            var leagueRepository = A.Fake <ILeagueRepository>();
            var leagues          = new List <League>();

            A.CallTo(() => leagueRepository.GetLeaguesAsync()).Returns(leagues);

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

            var testController = new LeaguesController(leagueRepository, sharedRepository, mapper, linkGenerator);

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

            // Assert
            A.CallTo(() => leagueRepository.GetLeaguesAsync()).MustHaveHappenedOnceExactly();
            A.CallTo(() => mapper.Map <LeagueModel[]>(leagues)).MustHaveHappenedOnceExactly();
            result.ShouldBeOfType <ActionResult <LeagueModel[]> >();
            result.Value.ShouldBe(mapper.Map <LeagueModel[]>(leagues));
        }