예제 #1
0
        public void AddRegularSubject()
        {
            // Arrange
            NonGenericRepository subjectRepository = new NonGenericRepository(dbContext, typeof(Subject));
            Subject subject = new Subject {
                Name = Convert.ToString(TestContext.DataRow["Name"])
            };

            // Act
            subjectRepository.Insert(subject);
            dbContext.SaveChanges();

            // Assert
            CollectionAssert.Contains(dbContext.Subjects.ToList(), subject);
        }
예제 #2
0
        public void AddSubjectWithWrongNameLength()
        {
            // Arrange
            NonGenericRepository subjectRepository = new NonGenericRepository(dbContext, typeof(Subject));
            Subject subject = new Subject {
                Name = Convert.ToString(TestContext.DataRow["Name"])
            };

            // Act
            subjectRepository.Insert(subject);

            // Assert
            Assert.ThrowsException <System.Data.Entity.Validation.DbEntityValidationException>(() => dbContext.SaveChanges());
            // undo adding
            ((IObjectContextAdapter)dbContext).ObjectContext.Detach(subject);
        }