Beispiel #1
0
        public void RemoveConferences()
        {
            // 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.RemoveRange(A <IEnumerable <Conference> > .Ignored)).Returns(conferences);

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

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

            var conferences = new List <Conference>();

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

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

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

            var conferences = new List <Conference>();

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

            // Act
            IEnumerable <Conference> result = null;

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

            // Assert
            Assert.IsNull(result);
        }