Exemplo n.º 1
0
        public void GetConferencesByLeagueAndSeason_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 conferenceCountPerLeague = 3;
            var conferences = new List <Conference>(leagueCount * conferenceCountPerLeague);

            for (int i = leagueCount; i > 0; i--)
            {
                for (int j = conferenceCountPerLeague; j > 0; j--)
                {
                    var conference = new Conference
                    {
                        Name       = $"Conference {j}",
                        LeagueName = $"League {i}"
                    };
                    conferences.Add(conference);
                }
            }
            A.CallTo(() => _conferenceRepository.GetEntities()).Returns(conferences);

            // Act
            var result = service.GetConferencesByLeagueAndSeason(leagueName, seasonID);

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

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

            var resultToList = result.ToList();

            Assert.AreEqual(conferenceCountPerLeague, 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);
            }
        }
Exemplo n.º 2
0
        public void GetConferencesByLeagueAndSeason_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(() => _conferenceRepository.GetEntities()).Throws <Exception>();

            // Act
            IEnumerable <Conference> result = null;

            Assert.Throws <Exception>(() => result = service.GetConferencesByLeagueAndSeason(leagueName, seasonID));

            // Assert
            Assert.IsNull(result);
        }
Exemplo n.º 3
0
        public void GetConferencesByLeagueAndSeason_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(() => _conferenceRepository.GetEntities()).Throws(ex);

            // Act
            var result = service.GetConferencesByLeagueAndSeason(leagueName, seasonID);

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

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