コード例 #1
0
        public void GetSeasonStandingsForDivision_ArgumentNullExceptionCaught_ShowsExceptionMessageAndReturnsEmptyCollection()
        {
            // Arrange
            var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository,
                                                            _divisionRepository, _storedProcedureRepository);

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

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

            A.CallTo(
                () => _storedProcedureRepository.GetSeasonStandingsForDivision(A <int> .Ignored, A <string> .Ignored))
            .Throws(ex);

            // Act
            var result = service.GetSeasonStandingsForDivision(seasonID, divisionName);

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

            Assert.IsInstanceOf <IEnumerable <GetSeasonStandingsForDivision_Result> >(result);
            Assert.IsEmpty(result);
        }
コード例 #2
0
        //[TestCase]
        public void TestCase1()
        {
            // Arrange
            var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository,
                                                            _divisionRepository, _storedProcedureRepository);

            // TODO: Define argument variables of method under test.

            // TODO: Set up needed infrastructure of class under test.

            // Act
            // TODO: Call method under test.

            // Assert
            // TODO: Assert results of call to method under test.
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
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);
        }
コード例 #5
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);
            }
        }
コード例 #6
0
        public void GetSeasonStandingsForDivision_HappyPath()
        {
            // Arrange
            var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository,
                                                            _divisionRepository, _storedProcedureRepository);

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

            // Set up needed infrastructure of class under test.
            var dbContext = A.Fake <ProFootballEntities>();

            var count = 3;
            var seasonStandingsForDivisionEnumerable = new List <GetSeasonStandingsForDivision_Result>(count);

            for (int i = 0; i < count; i++)
            {
                var item = new GetSeasonStandingsForDivision_Result();
                seasonStandingsForDivisionEnumerable.Add(item);
            }
            dbContext.SetUpFakeSeasonStandingsForDivision(seasonStandingsForDivisionEnumerable);

            var seasonStandingsForDivision = dbContext.GetSeasonStandingsForDivision(seasonID, divisionName);

            A.CallTo(
                () => _storedProcedureRepository.GetSeasonStandingsForDivision(A <int> .Ignored, A <string> .Ignored))
            .Returns(seasonStandingsForDivision);

            // Act
            var result = service.GetSeasonStandingsForDivision(seasonID, divisionName);

            // Assert
            A.CallTo(() => _storedProcedureRepository.GetSeasonStandingsForDivision(seasonID, divisionName))
            .MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <IEnumerable <GetSeasonStandingsForDivision_Result> >(result);
            Assert.AreEqual(count, result.Count());
        }
コード例 #7
0
        public void GetSeasonStandingsForDivision_GenericExceptionCaught_LogsAndRethrowsException()
        {
            // Arrange
            var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository,
                                                            _divisionRepository, _storedProcedureRepository);

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

            // Set up needed infrastructure of class under test.
            A.CallTo(
                () => _storedProcedureRepository.GetSeasonStandingsForDivision(A <int> .Ignored, A <string> .Ignored))
            .Throws <Exception>();

            // Act
            IEnumerable <GetSeasonStandingsForDivision_Result> result = null;

            Assert.Throws <Exception>(
                () => { result = service.GetSeasonStandingsForDivision(seasonID, divisionName); });

            // Assert
            Assert.IsNull(result);
        }