コード例 #1
0
        public void RemoveTeamSeasons()
        {
            // Arrange
            var repository = new TeamSeasonRepository();

            var dbContext   = A.Fake <ProFootballEntities>();
            var teamSeasons = new List <TeamSeason>();

            for (int i = 1; i <= 3; i++)
            {
                var teamSeason = new TeamSeason
                {
                    TeamName = "Team " + i,
                    SeasonID = 2017
                };
                teamSeasons.Add(teamSeason);
            }
            A.CallTo(() => dbContext.TeamSeasons.RemoveRange(A <IEnumerable <TeamSeason> > .Ignored)).Returns(teamSeasons);

            // Act
            var result = repository.RemoveEntities(dbContext, teamSeasons);

            // Assert
            A.CallTo(() => dbContext.TeamSeasons.RemoveRange(teamSeasons)).MustHaveHappenedOnceExactly();
            Assert.AreSame(teamSeasons, result);
        }
コード例 #2
0
        public void RemoveTeamSeasons_HappyPath()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new TeamSeasonRepository(dbContext);

            var teamSeasons = new List <TeamSeason>();

            A.CallTo(() => dbContext.TeamSeasons.RemoveRange(A <IEnumerable <TeamSeason> > .Ignored)).Returns(teamSeasons);

            // Act
            var result = repository.RemoveEntities(teamSeasons);

            // Assert
            A.CallTo(() => dbContext.TeamSeasons.RemoveRange(teamSeasons)).MustHaveHappenedOnceExactly();
            Assert.AreSame(teamSeasons, result);
        }
コード例 #3
0
        public void RemoveTeamSeasons_ExceptionCaught_LogsAndRethrowsException()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new TeamSeasonRepository(dbContext);

            var teamSeasons = new List <TeamSeason>();

            A.CallTo(() => dbContext.TeamSeasons.RemoveRange(A <IEnumerable <TeamSeason> > .Ignored)).Throws <Exception>();

            // Act
            IEnumerable <TeamSeason> result = null;

            Assert.Throws <Exception>(() => result = repository.RemoveEntities(teamSeasons));

            // Assert
            Assert.IsNull(result);
        }