public void SimpleReference() { using (var container = new RhetosTestContainer()) { container.Resolve <ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestDataStructure.Child", "DELETE FROM TestDataStructure.Parent", }); var repository = container.Resolve <Common.DomRepository>(); var parent = new TestDataStructure.Parent { ID = Guid.NewGuid() }; var child = new TestDataStructure.Child { ID = Guid.NewGuid(), ParentID = parent.ID }; repository.TestDataStructure.Parent.Insert(new[] { parent }); repository.TestDataStructure.Child.Insert(new[] { child }); Assert.AreEqual(child.ID + " " + parent.ID, repository.TestDataStructure.Child.Query().Select(c => c.ID + " " + c.Parent.ID).Single(), "Testing if the Reference concept was properly implemented while using late initialization of the Reference property."); repository.TestDataStructure.Parent.Delete(new[] { parent }); Assert.AreEqual(0, repository.TestDataStructure.Child.Query().Count(), "Testing if the CascadeDelete concept was properly implemented while using a Reference concept with late initialization of the Reference property."); } }
public void SimpleReference() { using (var container = new RhetosTestContainer()) { container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestDataStructure.Child", "DELETE FROM TestDataStructure.Parent", }); var repository = container.Resolve<Common.DomRepository>(); var parent = new TestDataStructure.Parent { ID = Guid.NewGuid() }; var child = new TestDataStructure.Child { ID = Guid.NewGuid(), ParentID = parent.ID }; repository.TestDataStructure.Parent.Insert(new[] { parent }); repository.TestDataStructure.Child.Insert(new[] { child }); container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache(); Assert.AreEqual(child.ID + " " + parent.ID, repository.TestDataStructure.Child.Query().Select(c => c.ID + " " + c.Parent.ID).Single(), "Testing if the Reference concept was properly implemented while using late initialization of the Reference property."); repository.TestDataStructure.Parent.Delete(new[] { parent }); container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache(); Assert.AreEqual(0, repository.TestDataStructure.Child.Query().Count(), "Testing if the CascadeDelete concept was properly implemented while using a Reference concept with late initialization of the Reference property."); } }
public void SimpleReference() { using (var executionContext = new CommonTestExecutionContext()) { executionContext.SqlExecuter.ExecuteSql(new[] { "DELETE FROM TestDataStructure.Child", "DELETE FROM TestDataStructure.Parent", }); var repository = new Common.DomRepository(executionContext); var parent = new TestDataStructure.Parent { ID = Guid.NewGuid() }; var child = new TestDataStructure.Child { ID = Guid.NewGuid(), Parent = parent }; repository.TestDataStructure.Parent.Insert(new[] { parent }); repository.TestDataStructure.Child.Insert(new[] { child }); executionContext.NHibernateSession.Clear(); Assert.AreEqual(child.ID + " " + parent.ID, repository.TestDataStructure.Child.Query().Select(c => c.ID + " " + c.Parent.ID).Single(), "Testing if the Reference concept was properly implemented while using late initialization of the Reference property."); repository.TestDataStructure.Parent.Delete(new[] { parent }); executionContext.NHibernateSession.Clear(); Assert.AreEqual(0, repository.TestDataStructure.Child.Query().Count(), "Testing if the CascadeDelete concept was properly implemented while using a Reference concept with late initialization of the Reference property."); } }