示例#1
0
        public void AddEntitys()
        {
            // Arrange
            var repository = new GameRepository();

            var dbContext = A.Fake <ProFootballEntities>();
            var games     = new List <Game>();

            for (int i = 1; i <= 3; i++)
            {
                var game = new Game
                {
                    ID = i
                };
                games.Add(game);
            }
            A.CallTo(() => dbContext.Games.AddRange(A <IEnumerable <Game> > .Ignored)).Returns(games);

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

            // Assert
            A.CallTo(() => dbContext.Games.AddRange(games)).MustHaveHappenedOnceExactly();
            Assert.AreSame(games, result);
        }
示例#2
0
        public void AddEntitys_ExceptionCaught_LogsAndRethrowsException()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new GameRepository(dbContext);

            var games = new List <Game>();

            A.CallTo(() => dbContext.Games.AddRange(A <IEnumerable <Game> > .Ignored)).Throws <Exception>();

            // Act
            IEnumerable <Game> result = null;

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

            // Assert
            Assert.IsNull(result);
        }