示例#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
        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());
        }
示例#3
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);
        }