Beispiel #1
0
        public void AddConferences()
        {
            // Arrange
            var repository = new ConferenceRepository();

            var dbContext   = A.Fake <ProFootballEntities>();
            var conferences = new List <Conference>();

            for (int i = 1; i <= 3; i++)
            {
                var conference = new Conference
                {
                    Name = "Conference " + i
                };
                conferences.Add(conference);
            }
            A.CallTo(() => dbContext.Conferences.AddRange(A <IEnumerable <Conference> > .Ignored)).Returns(conferences);

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

            // Assert
            A.CallTo(() => dbContext.Conferences.AddRange(conferences)).MustHaveHappenedOnceExactly();
            Assert.AreSame(conferences, result);
        }
        public void AddConferences_HappyPath()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new ConferenceRepository(dbContext);

            var conferences = new List <Conference>();

            A.CallTo(() => dbContext.Conferences.AddRange(A <IEnumerable <Conference> > .Ignored)).Returns(conferences);

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

            // Assert
            A.CallTo(() => dbContext.Conferences.AddRange(conferences)).MustHaveHappenedOnceExactly();
            Assert.AreSame(conferences, result);
        }
        public void AddConferences_ExceptionCaught_LogsAndRethrowsException()
        {
            // Arrange
            var dbContext  = A.Fake <ProFootballEntities>();
            var repository = new ConferenceRepository(dbContext);

            var conferences = new List <Conference>();

            A.CallTo(() => dbContext.Conferences.AddRange(A <IEnumerable <Conference> > .Ignored)).Throws <Exception>();

            // Act
            IEnumerable <Conference> result = null;

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

            // Assert
            Assert.IsNull(result);
        }