public async Task PutTeamSeason_WhenTeamSeasonIsNotFound_ShouldReturnNotFoundResult() { // Arrange var teamSeasonRepository = A.Fake <ITeamSeasonRepository>(); TeamSeason?teamSeason = null; A.CallTo(() => teamSeasonRepository.GetTeamSeasonAsync(A <int> .Ignored)).Returns(teamSeason); var sharedRepository = A.Fake <ISharedRepository>(); var mapper = A.Fake <IMapper>(); var linkGenerator = A.Fake <LinkGenerator>(); var testController = new TeamSeasonsController(teamSeasonRepository, sharedRepository, mapper, linkGenerator); int id = 1; var model = new TeamSeasonModel(); // Act var result = await testController.PutTeamSeason(id, model); // Assert A.CallTo(() => teamSeasonRepository.GetTeamSeasonAsync(id)).MustHaveHappenedOnceExactly(); result.Result.ShouldBeOfType <NotFoundObjectResult>(); ((NotFoundObjectResult)result.Result).Value.ShouldBe($"Could not find teamSeason with ID of {id}"); }
public async Task PutTeamSeason_WhenTeamSeasonIsFoundAndNotSaved_ShouldReturnBadRequestResult() { // Arrange var teamSeasonRepository = A.Fake <ITeamSeasonRepository>(); TeamSeason?teamSeason = new TeamSeason(); A.CallTo(() => teamSeasonRepository.GetTeamSeasonAsync(A <int> .Ignored)).Returns(teamSeason); var sharedRepository = A.Fake <ISharedRepository>(); A.CallTo(() => sharedRepository.SaveChangesAsync()).Returns(0); var mapper = A.Fake <IMapper>(); var returnModel = new TeamSeasonModel(); A.CallTo(() => mapper.Map <TeamSeasonModel>(teamSeason)).Returns(returnModel); var linkGenerator = A.Fake <LinkGenerator>(); var testController = new TeamSeasonsController(teamSeasonRepository, sharedRepository, mapper, linkGenerator); int id = 1; var model = new TeamSeasonModel(); // Act var result = await testController.PutTeamSeason(id, model); // Assert A.CallTo(() => teamSeasonRepository.GetTeamSeasonAsync(id)).MustHaveHappenedOnceExactly(); A.CallTo(() => mapper.Map(model, teamSeason)).MustHaveHappenedOnceExactly(); A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly(); A.CallTo(() => mapper.Map <TeamSeasonModel>(teamSeason)).MustNotHaveHappened(); result.Result.ShouldBeOfType <BadRequestResult>(); }
public async Task PutTeamSeason_WhenExceptionIsCaught_ShouldReturnInternalServerError() { // Arrange var teamSeasonRepository = A.Fake <ITeamSeasonRepository>(); A.CallTo(() => teamSeasonRepository.GetTeamSeasonAsync(A <int> .Ignored)).Throws <Exception>(); var sharedRepository = A.Fake <ISharedRepository>(); var mapper = A.Fake <IMapper>(); var linkGenerator = A.Fake <LinkGenerator>(); var testController = new TeamSeasonsController(teamSeasonRepository, sharedRepository, mapper, linkGenerator); int id = 1; var model = new TeamSeasonModel(); // Act var result = await testController.PutTeamSeason(id, model); // Assert result.Result.ShouldBeOfType <ObjectResult>(); ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError); ((ObjectResult)result.Result).Value.ShouldBe("Database failure"); }