public async Task GetTeamSeasonScheduleAverages_WhenExceptionIsNotCaught_ShouldReturnTeamSeasonOpponentAveragesModel() { // Arrange var teamSeasonScheduleAveragesRepository = A.Fake <ITeamSeasonScheduleRepository>(); TeamSeasonScheduleAverages?teamSeasonScheduleAverages = new TeamSeasonScheduleAverages(); A.CallTo(() => teamSeasonScheduleAveragesRepository.GetTeamSeasonScheduleAveragesAsync( A <string> .Ignored, A <int> .Ignored)).Returns(teamSeasonScheduleAverages); var mapper = A.Fake <IMapper>(); var teamSeasonScheduleAveragesModel = new TeamSeasonScheduleAveragesModel(); A.CallTo(() => mapper.Map <TeamSeasonScheduleAveragesModel>(A <TeamSeasonScheduleAverages> .Ignored)) .Returns(teamSeasonScheduleAveragesModel); var testController = new TeamSeasonScheduleController(teamSeasonScheduleAveragesRepository, mapper); string teamName = "Team"; int seasonYear = 1920; // Act var result = await testController.GetTeamSeasonScheduleAverages(teamName, seasonYear); // Assert A.CallTo(() => teamSeasonScheduleAveragesRepository.GetTeamSeasonScheduleAveragesAsync(teamName, seasonYear)) .MustHaveHappenedOnceExactly(); A.CallTo(() => mapper.Map <TeamSeasonScheduleAveragesModel>(teamSeasonScheduleAverages)) .MustHaveHappenedOnceExactly(); result.Value.ShouldBeOfType <TeamSeasonScheduleAveragesModel>(); }
public async Task GetTeamSeasonScheduleAverages_WhenExceptionIsCaught_ShouldReturnInternalServerError() { // Arrange var teamSeasonScheduleAveragesRepository = A.Fake <ITeamSeasonScheduleRepository>(); A.CallTo(() => teamSeasonScheduleAveragesRepository.GetTeamSeasonScheduleAveragesAsync( A <string> .Ignored, A <int> .Ignored)).Throws <Exception>(); var mapper = A.Fake <IMapper>(); var testController = new TeamSeasonScheduleController(teamSeasonScheduleAveragesRepository, mapper); string teamName = "Team"; int seasonYear = 1920; // Act var result = await testController.GetTeamSeasonScheduleAverages(teamName, seasonYear); // Assert result.Result.ShouldBeOfType <ObjectResult>(); ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError); ((ObjectResult)result.Result).Value.ShouldBe("Database failure"); }