예제 #1
0
        public void GetSeasonStandingsForConference_ArgumentNullExceptionCaught_ShowsExceptionMessageAndReturnsEmptyCollection()
        {
            // Arrange
            var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository,
                                                            _divisionRepository, _storedProcedureRepository);

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

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

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

            // Act
            var result = service.GetSeasonStandingsForConference(seasonID, conferenceName);

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

            Assert.IsInstanceOf <IEnumerable <GetSeasonStandingsForConference_Result> >(result);
            Assert.IsEmpty(result);
        }
예제 #2
0
        public void GetSeasonStandingsForConference_HappyPath()
        {
            // Arrange
            var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository,
                                                            _divisionRepository, _storedProcedureRepository);

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

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

            var count = 3;
            var seasonStandingsForConferenceEnumerable = new List <GetSeasonStandingsForConference_Result>(count);

            for (int i = 0; i < count; i++)
            {
                var item = new GetSeasonStandingsForConference_Result();
                seasonStandingsForConferenceEnumerable.Add(item);
            }
            dbContext.SetUpFakeSeasonStandingsForConference(seasonStandingsForConferenceEnumerable);

            var seasonStandingsForConference = dbContext.GetSeasonStandingsForConference(seasonID, conferenceName);

            A.CallTo(
                () => _storedProcedureRepository.GetSeasonStandingsForConference(A <int> .Ignored, A <string> .Ignored))
            .Returns(seasonStandingsForConference);

            // Act
            var result = service.GetSeasonStandingsForConference(seasonID, conferenceName);

            // Assert
            A.CallTo(() => _storedProcedureRepository.GetSeasonStandingsForConference(seasonID, conferenceName))
            .MustHaveHappenedOnceExactly();

            Assert.IsInstanceOf <IEnumerable <GetSeasonStandingsForConference_Result> >(result);
            Assert.AreEqual(count, result.Count());
        }
예제 #3
0
        public void GetSeasonStandingsForConference_GenericExceptionCaught_LogsAndRethrowsException()
        {
            // Arrange
            var service = new SeasonStandingsControlService(_sharedService, _leagueRepository, _conferenceRepository,
                                                            _divisionRepository, _storedProcedureRepository);

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

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

            // Act
            IEnumerable <GetSeasonStandingsForConference_Result> result = null;

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

            // Assert
            Assert.IsNull(result);
        }