public void GetDivisionsByLeagueAndSeason_HappyPath() { // Arrange var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository, _divisionRepository, _storedProcedureRepository); // Define argument variables of method under test. var leagueName = "League 1"; var seasonID = 2017; // Set up needed infrastructure of class under test. var leagueCount = 3; var divisionCountPerLeague = 3; var divisions = new List <Division>(leagueCount * divisionCountPerLeague); for (int i = leagueCount; i > 0; i--) { for (int j = divisionCountPerLeague; j > 0; j--) { var division = new Division { Name = $"Division {j}", LeagueName = $"League {i}" }; divisions.Add(division); } } A.CallTo(() => _divisionRepository.GetEntities()).Returns(divisions); // Act var result = service.GetDivisionsByLeagueAndSeason(leagueName, seasonID); // Assert A.CallTo(() => _divisionRepository.GetEntities()).MustHaveHappenedOnceExactly(); Assert.IsInstanceOf <IEnumerable <Division> >(result); var resultToList = result.ToList(); Assert.AreEqual(divisionCountPerLeague, resultToList.Count); // Verify correct order: Order by Name ascending. for (int i = 1; i < resultToList.Count; i++) { Assert.Greater(resultToList[i].Name, resultToList[i - 1].Name); } }
public void GetDivisionsByLeagueAndSeason_GenericExceptionCaught_LogsAndRethrowsException() { // Arrange var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository, _divisionRepository, _storedProcedureRepository); // Define argument variables of method under test. var leagueName = "League 1"; var seasonID = 2017; // Set up needed infrastructure of class under test. A.CallTo(() => _divisionRepository.GetEntities()).Throws <Exception>(); // Act IEnumerable <Division> result = null; Assert.Throws <Exception>(() => result = service.GetDivisionsByLeagueAndSeason(leagueName, seasonID)); // Assert Assert.IsNull(result); }
public void GetDivisionsByLeagueAndSeason_ArgumentNullExceptionCaught_ShowsExceptionMessageAndReturnsEmptyCollection() { // Arrange var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository, _divisionRepository, _storedProcedureRepository); // Define argument variables of method under test. var leagueName = "League 1"; var seasonID = 2017; // Set up needed infrastructure of class under test. var ex = new ArgumentNullException(); A.CallTo(() => _divisionRepository.GetEntities()).Throws(ex); // Act var result = service.GetDivisionsByLeagueAndSeason(leagueName, seasonID); // Assert A.CallTo(() => _sharedService.ShowExceptionMessage(ex)).MustHaveHappenedOnceExactly(); Assert.IsInstanceOf <IEnumerable <Division> >(result); Assert.IsEmpty(result); }