public void GetSeasonIDs_HappyPath() { // Arrange var service = new GamePredictorWindowService(_seasonRepository); // Set up needed infrastructure of class under test. var lastSeason = 2017; var seasonCount = 3; var seasons = new List <Season>(seasonCount); for (int i = lastSeason; i > lastSeason - seasonCount; i--) { var season = new Season { ID = i }; seasons.Add(season); } A.CallTo(() => _seasonRepository.GetEntities()).Returns(seasons); // Act var result = service.GetSeasonIDs(); // Assert A.CallTo(() => _seasonRepository.GetEntities()).MustHaveHappenedOnceExactly(); Assert.IsInstanceOf <List <int> >(result); var resultAsList = result as IList <int>; Assert.AreEqual(seasonCount, resultAsList.Count); for (int i = 0; i < seasonCount; i++) { Assert.AreEqual(lastSeason - i, resultAsList[i]); } }
public void GetSeasonIDs_ExceptionCaught_LogsAndRethrowsException() { // Arrange var service = new GamePredictorWindowService(_seasonRepository); A.CallTo(() => _seasonRepository.GetEntities()).Throws <Exception>(); // Act IEnumerable <int> result = null; Assert.Throws <Exception>(() => result = service.GetSeasonIDs()); // Assert Assert.IsNull(result); }