Esempio n. 1
0
        public void GetLeaguesBySeason_GenericExceptionCaught_LogsAndRethrowsException()
        {
            // Arrange
            var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository,
                                                            _divisionRepository, _storedProcedureRepository);

            // Define argument variables of method under test.
            var seasonID = 2017;

            // Set up needed infrastructure of class under test.
            A.CallTo(() => _leagueRepository.GetEntities()).Throws <Exception>();

            // Act
            IEnumerable <League> result = null;

            Assert.Throws <Exception>(() => result = service.GetLeaguesBySeason(seasonID));

            // Assert
            Assert.IsNull(result);
        }
Esempio n. 2
0
        public void GetLeaguesBySeason_HappyPath()
        {
            // Arrange
            var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository,
                                                            _divisionRepository, _storedProcedureRepository);

            // Define argument variables of method under test.
            var seasonID = 2017;

            // Set up needed infrastructure of class under test.
            var leagueCount = 3;
            var leagues     = new List <League>(leagueCount);

            for (int i = leagueCount; i > 0; i--)
            {
                var league = new League
                {
                    Name = $"League {i}"
                };
                leagues.Add(league);
            }
            A.CallTo(() => _leagueRepository.GetEntities()).Returns(leagues);

            // Act
            var result = service.GetLeaguesBySeason(seasonID);

            // Assert
            A.CallTo(() => _leagueRepository.GetEntities()).MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <IEnumerable <League> >(result);

            var resultToList = result.ToList();

            Assert.AreEqual(leagueCount, 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);
            }
        }
Esempio n. 3
0
        public void GetLeaguesBySeason_ArgumentNullExceptionCaught_ShowsExceptionMessageAndReturnsEmptyCollection()
        {
            // Arrange
            var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository,
                                                            _divisionRepository, _storedProcedureRepository);

            // Define argument variables of method under test.
            var seasonID = 2017;

            // Set up needed infrastructure of class under test.
            var ex = new ArgumentNullException();

            A.CallTo(() => _leagueRepository.GetEntities()).Throws(ex);

            // Act
            var result = service.GetLeaguesBySeason(seasonID);

            // Assert
            A.CallTo(() => _sharedService.ShowExceptionMessage(ex)).MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <IEnumerable <League> >(result);
            Assert.IsEmpty(result);
        }