Exemplo n.º 1
0
        public void AddWeekCounts()
        {
            // Arrange
            var repository = new WeekCountRepository();

            var dbContext  = A.Fake <ProFootballEntities>();
            var weekCounts = new List <WeekCount>();

            for (int i = 1; i <= 3; i++)
            {
                var weekCount = new WeekCount
                {
                    SeasonID = i
                };
                weekCounts.Add(weekCount);
            }
            A.CallTo(() => dbContext.WeekCounts.AddRange(A <IEnumerable <WeekCount> > .Ignored)).Returns(weekCounts);

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

            // Assert
            A.CallTo(() => dbContext.WeekCounts.AddRange(weekCounts)).MustHaveHappenedOnceExactly();
            Assert.AreSame(weekCounts, result);
        }
Exemplo n.º 2
0
        public void AddWeekCounts_HappyPath()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new WeekCountRepository(dbContext);

            var weekCounts = new List <WeekCount>();

            A.CallTo(() => dbContext.WeekCounts.AddRange(A <IEnumerable <WeekCount> > .Ignored)).Returns(weekCounts);

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

            // Assert
            A.CallTo(() => dbContext.WeekCounts.AddRange(weekCounts)).MustHaveHappenedOnceExactly();
            Assert.AreSame(weekCounts, result);
        }
Exemplo n.º 3
0
        public void AddWeekCounts_ExceptionCaught_LogsAndRethrowsException()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new WeekCountRepository(dbContext);

            var weekCounts = new List <WeekCount>();

            A.CallTo(() => dbContext.WeekCounts.AddRange(A <IEnumerable <WeekCount> > .Ignored)).Throws <Exception>();

            // Act
            IEnumerable <WeekCount> result = null;

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

            // Assert
            Assert.IsNull(result);
        }