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

            var dbContext = A.Fake <ProFootballEntities>();
            var seasons   = new List <Season>();

            for (int i = 0; i < 3; i++)
            {
                var season = new Season
                {
                    ID = 2017 - i
                };
                seasons.Add(season);
            }
            A.CallTo(() => dbContext.Seasons.AddRange(A <IEnumerable <Season> > .Ignored)).Returns(seasons);

            // Act
            var result = repository.AddEntities(dbContext, seasons);

            // Assert
            A.CallTo(() => dbContext.Seasons.AddRange(seasons)).MustHaveHappenedOnceExactly();
            Assert.AreSame(seasons, result);
        }
コード例 #2
0
        public void AddSeasons_HappyPath()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new SeasonRepository(dbContext);

            var seasons = new List <Season>();

            A.CallTo(() => dbContext.Seasons.AddRange(A <IEnumerable <Season> > .Ignored)).Returns(seasons);

            // Act
            var result = repository.AddEntities(seasons);

            // Assert
            A.CallTo(() => dbContext.Seasons.AddRange(seasons)).MustHaveHappenedOnceExactly();
            Assert.AreSame(seasons, result);
        }
コード例 #3
0
        public void AddSeasons_ExceptionCaught_LogsAndRethrowsException()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new SeasonRepository(dbContext);

            var seasons = new List <Season>();

            A.CallTo(() => dbContext.Seasons.AddRange(A <IEnumerable <Season> > .Ignored)).Throws <Exception>();

            // Act
            IEnumerable <Season> result = null;

            Assert.Throws <Exception>(() => result = repository.AddEntities(seasons));

            // Assert
            Assert.IsNull(result);
        }