public async Task DeleteLeague_WhenLeagueIsFoundAndNotDeleted_ShouldReturnBadRequest() { // Arrange var leagueRepository = A.Fake <ILeagueRepository>(); League?league = new League(); A.CallTo(() => leagueRepository.GetLeagueAsync(A <int> .Ignored)).Returns(league); var sharedRepository = A.Fake <ISharedRepository>(); A.CallTo(() => sharedRepository.SaveChangesAsync()).Returns(0); var mapper = A.Fake <IMapper>(); var linkGenerator = A.Fake <LinkGenerator>(); var testController = new LeaguesController(leagueRepository, sharedRepository, mapper, linkGenerator); int id = 1; // Act var result = await testController.DeleteLeague(id); // Assert A.CallTo(() => leagueRepository.GetLeagueAsync(id)).MustHaveHappenedOnceExactly(); A.CallTo(() => sharedRepository.SaveChangesAsync()).MustHaveHappenedOnceExactly(); result.Result.ShouldBeOfType <BadRequestResult>(); }
public async Task DeleteLeague_WhenExceptionIsCaught_ShouldReturnInternalServerError() { // Arrange var leagueRepository = A.Fake <ILeagueRepository>(); A.CallTo(() => leagueRepository.GetLeagueAsync(A <int> .Ignored)).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); int id = 1; // Act var result = await testController.DeleteLeague(id); // Assert result.Result.ShouldBeOfType <ObjectResult>(); ((ObjectResult)result.Result).StatusCode.ShouldBe(StatusCodes.Status500InternalServerError); ((ObjectResult)result.Result).Value.ShouldBe("Database failure"); }
public async Task DeleteLeague_WhenLeagueIsNotFound_ShouldReturnNotFoundResult() { // Arrange var leagueRepository = A.Fake <ILeagueRepository>(); League?league = null; A.CallTo(() => leagueRepository.GetLeagueAsync(A <int> .Ignored)).Returns(league); var sharedRepository = A.Fake <ISharedRepository>(); var mapper = A.Fake <IMapper>(); var linkGenerator = A.Fake <LinkGenerator>(); var testController = new LeaguesController(leagueRepository, sharedRepository, mapper, linkGenerator); int id = 1; // Act var result = await testController.DeleteLeague(id); // Assert A.CallTo(() => leagueRepository.GetLeagueAsync(id)).MustHaveHappenedOnceExactly(); result.Result.ShouldBeOfType <NotFoundObjectResult>(); ((NotFoundObjectResult)result.Result).Value.ShouldBe($"Could not find league with ID of {id}"); }