public void TestUnitAssociationWithUnsavedUnitDoesNotSaveOrCascade() { var SchoolRepository = new RepositoryWithTypedId <School, string>(); UnitAssociation unitAssociation = null; try { #region Arrange unitAssociation = GetValid(9); unitAssociation.Unit = CreateValidEntities.Unit(99); unitAssociation.Unit.School = SchoolRepository.GetById("1"); #endregion Arrange #region Act UnitAssociationRepository.DbContext.BeginTransaction(); UnitAssociationRepository.EnsurePersistent(unitAssociation); UnitAssociationRepository.DbContext.CommitTransaction(); #endregion Act } catch (Exception ex) { Assert.IsNotNull(unitAssociation); Assert.IsNotNull(ex); Assert.AreEqual("not-null property references a null or transient value Catbert4.Core.Domain.UnitAssociation.Unit", ex.Message); throw; } }
/// <summary> /// Needs Schools /// </summary> /// <param name="entriesToAdd"></param> protected void LoadUnits(int entriesToAdd) { var schoolRepository = new RepositoryWithTypedId <School, string>(); for (int i = 0; i < entriesToAdd; i++) { var validEntity = CreateValidEntities.Unit(i + 1); validEntity.School = schoolRepository.GetById("1"); Repository.OfType <Unit>().EnsurePersistent(validEntity); } }
public void TestMajorsWithPopulatedListSaves() { #region Arrange var majorCodeRepository = new RepositoryWithTypedId<MajorCode, string>(); LoadMajorCode(3); var student = GetValid(9); student.Majors = new List<MajorCode>(); student.Majors.Add(majorCodeRepository.GetById("1")); student.Majors.Add(majorCodeRepository.GetById("3")); #endregion Arrange #region Act StudentRepository.DbContext.BeginTransaction(); StudentRepository.EnsurePersistent(student); StudentRepository.DbContext.CommitTransaction(); #endregion Act #region Assert Assert.IsNotNull(student.Majors); Assert.AreEqual(2, student.Majors.Count); Assert.AreSame(student.Majors[1], majorCodeRepository.GetById("3")); Assert.IsFalse(student.IsTransient()); Assert.IsTrue(student.IsValid()); #endregion Assert }
public void TestDeleteStudentDoesNotCascadeToMajorCodes() { #region Arrange var majorCodeRepository = new RepositoryWithTypedId<MajorCode, string>(); LoadMajorCode(3); var student = GetValid(9); student.Majors = new List<MajorCode>(); student.Majors.Add(majorCodeRepository.GetById("1")); student.Majors.Add(majorCodeRepository.GetById("3")); StudentRepository.DbContext.BeginTransaction(); StudentRepository.EnsurePersistent(student); StudentRepository.DbContext.CommitTransaction(); #endregion Arrange #region Act StudentRepository.DbContext.BeginTransaction(); StudentRepository.Remove(student); StudentRepository.DbContext.CommitTransaction(); #endregion Act #region Assert Assert.AreEqual("Name1", majorCodeRepository.GetById("1").Name); Assert.AreEqual("Name2", majorCodeRepository.GetById("2").Name); Assert.AreEqual("Name3", majorCodeRepository.GetById("3").Name); #endregion Assert }