Пример #1
0
        public void FindEntity_GenericExceptionCaught_LogsAndRethrowsException()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new SeasonRepository(dbContext);

            var id = 2017;

            A.CallTo(() => dbContext.Seasons.Find(A <int> .Ignored)).Throws <Exception>();

            // Act
            Season result = null;

            Assert.Throws <Exception>(() => result = repository.FindEntity(id));

            // Assert
            Assert.IsNull(result);
        }
Пример #2
0
        public void FindEntity_InvalidOperationExceptionCaught_ThrowsObjectNotFoundException()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new SeasonRepository(dbContext);

            var id = 2017;

            A.CallTo(() => dbContext.Seasons.Find(A <int> .Ignored)).Throws <InvalidOperationException>();

            // Act
            Season result = null;

            Assert.Throws <ObjectNotFoundException>(() => { result = repository.FindEntity(id); });

            // Assert
            Assert.IsNull(result);
        }
Пример #3
0
        public void FindEntity_HappyPath()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new SeasonRepository(dbContext);

            var id = 2017;

            var season = new Season();

            A.CallTo(() => dbContext.Seasons.Find(A <int> .Ignored)).Returns(season);

            // Act
            var result = repository.FindEntity(id);

            // Assert
            A.CallTo(() => dbContext.Seasons.Find(id)).MustHaveHappenedOnceExactly();
            Assert.AreSame(season, result);
        }
Пример #4
0
        public void FindEntity_EntityNotFoundInDataStore_ThrowsObjectNotFoundException()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new SeasonRepository(dbContext);

            var id = 2017;

            Season season = null;

            A.CallTo(() => dbContext.Seasons.Find(A <int> .Ignored)).Returns(season);

            // Act
            Season result = null;

            Assert.Throws <ObjectNotFoundException>(() => { result = repository.FindEntity(id); });

            // Assert
            A.CallTo(() => dbContext.Seasons.Find(id)).MustHaveHappenedOnceExactly();
            Assert.IsNull(result);
        }