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); }
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); }