public async Task DeleteTeamSeason_WhenTeamSeasonIsFoundAndNotDeleted_ShouldReturnBadRequest() { // 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 linkGenerator = A.Fake <LinkGenerator>(); var testController = new TeamSeasonsController(teamSeasonRepository, sharedRepository, mapper, linkGenerator); int id = 1; // Act var result = await testController.DeleteTeamSeason(id); // Assert A.CallTo(() => teamSeasonRepository.GetTeamSeasonAsync(id)).MustHaveHappenedOnceExactly(); A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly(); result.Result.ShouldBeOfType <BadRequestResult>(); }
public async Task DeleteTeamSeason_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; // Act var result = await testController.DeleteTeamSeason(id); // Assert result.Result.ShouldBeOfType <ObjectResult>(); ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError); ((ObjectResult)result.Result).Value.ShouldBe("Database failure"); }
public async Task DeleteTeamSeason_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; // Act var result = await testController.DeleteTeamSeason(id); // Assert A.CallTo(() => teamSeasonRepository.GetTeamSeasonAsync(id)).MustHaveHappenedOnceExactly(); result.Result.ShouldBeOfType <NotFoundObjectResult>(); ((NotFoundObjectResult)result.Result).Value.ShouldBe($"Could not find teamSeason with ID of {id}"); }