public void GetDivisionsByConferenceAndSeason_HappyPath() { // Arrange var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository, _divisionRepository, _storedProcedureRepository); // Define argument variables of method under test. var conferenceName = "Conference 1"; var seasonID = 2017; // Set up needed infrastructure of class under test. var conferenceCount = 3; var divisionCountPerConference = 3; var divisions = new List <Division>(conferenceCount * divisionCountPerConference); for (int i = conferenceCount; i > 0; i--) { for (int j = divisionCountPerConference; j > 0; j--) { var division = new Division { Name = $"Division {j}", ConferenceName = $"Conference {i}" }; divisions.Add(division); } } A.CallTo(() => _divisionRepository.GetEntities()).Returns(divisions); // Act var result = service.GetDivisionsByConferenceAndSeason(conferenceName, seasonID); // Assert A.CallTo(() => _divisionRepository.GetEntities()).MustHaveHappenedOnceExactly(); Assert.IsInstanceOf <IEnumerable <Division> >(result); var resultToList = result.ToList(); Assert.AreEqual(divisionCountPerConference, 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 GetDivisionsByConferenceAndSeason_GenericExceptionCaught_LogsAndRethrowsException() { // Arrange var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository, _divisionRepository, _storedProcedureRepository); // Define argument variables of method under test. var conferenceName = "Conference 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.GetDivisionsByConferenceAndSeason(conferenceName, seasonID); }); // Assert Assert.IsNull(result); }
public void GetDivisionsByConferenceAndSeason_ArgumentNullExceptionCaught_ShowsExceptionMessageAndReturnsEmptyCollection() { // Arrange var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository, _divisionRepository, _storedProcedureRepository); // Define argument variables of method under test. var conferenceName = "Conference 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.GetDivisionsByConferenceAndSeason(conferenceName, seasonID); // Assert A.CallTo(() => _sharedService.ShowExceptionMessage(ex)).MustHaveHappenedOnceExactly(); Assert.IsInstanceOf <IEnumerable <Division> >(result); Assert.IsEmpty(result); }