public void UpdatePersistent() { using (var container = new RhetosTestContainer()) { var context = container.Resolve <Common.ExecutionContext>(); var repository = container.Resolve <Common.DomRepository>(); var b = new TestEntity.BaseEntity { ID = Guid.NewGuid(), Name = "b" }; var c = new TestEntity.Child { Name = "c", ParentID = b.ID }; repository.TestEntity.BaseEntity.Insert(b); repository.TestEntity.Child.Insert(c); var b2 = repository.TestEntity.BaseEntity.Query().Where(item => item.ID == b.ID).Single(); b2.Name = "b2"; // Should not be saved when calling Child.Update. var c2 = repository.TestEntity.Child.Query().Where(item => item.ID == c.ID).Single(); Console.WriteLine("c2.GetType().FullName: " + c2.GetType().FullName); c2.Name = "c2"; c2.Parent.Name = "b3"; // Should not be saved when calling Child.Update. repository.TestEntity.Child.Update(c2); var report = repository.TestEntity.Child.Query().Where(item => item.ID == c.ID) .Select(item => item.Name + " " + item.Parent.Name); Assert.AreEqual("c2 b", TestUtility.DumpSorted(report)); } }
public void SimpleReferenceProperty() { using (var container = new RhetosTestContainer()) { container.Resolve <ISqlExecuter>().ExecuteSql("DELETE FROM TestEntity.BaseEntity"); var repository = container.Resolve <Common.DomRepository>(); var context = container.Resolve <Common.ExecutionContext>(); var b1 = new TestEntity.BaseEntity { Name = "b1" }; var b2 = new TestEntity.BaseEntity { Name = "b2" }; repository.TestEntity.BaseEntity.Insert(b1, b2); var c1 = new TestEntity.Child { Name = "c1", ParentID = b1.ID }; repository.TestEntity.Child.Insert(c1); Assert.AreEqual("c1b1", TestUtility.DumpSorted(repository.TestEntity.Child.Query(), item => item.Name + item.Parent.Name)); b1 = repository.TestEntity.BaseEntity.Query().Where(item => item.ID == b1.ID).Single(); c1 = repository.TestEntity.Child.Query().Where(item => item.ID == c1.ID).Single(); Assert.AreEqual("c1b1", TestUtility.DumpSorted(repository.TestEntity.Child.Query() .Where(c => c.ParentID == b1.ID), item => item.Name + item.Parent.Name)); c1.ParentID = b2.ID; repository.TestEntity.Child.Update(c1); Assert.AreEqual("c1b2", TestUtility.DumpSorted(repository.TestEntity.Child.Query(), item => item.Name + item.Parent.Name)); } }
public void InsertTransient() { using (var container = new RhetosTestContainer()) { var context = container.Resolve <Common.ExecutionContext>(); var repository = container.Resolve <Common.DomRepository>(); var b = new TestEntity.BaseEntity { ID = Guid.NewGuid(), Name = "b" }; var c = new TestEntity.Child { Name = "c", ParentID = b.ID }; repository.TestEntity.BaseEntity.Insert(b); repository.TestEntity.Child.Insert(c); context.EntityFrameworkContext.ClearCache(); Assert.AreNotEqual(default(Guid), c.ID); var report = repository.TestEntity.Child.Query().Where(item => item.ID == c.ID) .Select(item => item.Name + " " + item.Parent.Name); Assert.AreEqual("c b", TestUtility.DumpSorted(report)); } }
public void UpdateTransient() { using (var container = new RhetosTestContainer()) { var context = container.Resolve <Common.ExecutionContext>(); var repository = container.Resolve <Common.DomRepository>(); var b = new TestEntity.BaseEntity { ID = Guid.NewGuid(), Name = "b" }; var c = new TestEntity.Child { Name = "c", ParentID = b.ID }; repository.TestEntity.BaseEntity.Insert(b); repository.TestEntity.Child.Insert(c); var c2 = new TestEntity.Child { ID = c.ID, Name = "c2", ParentID = b.ID }; repository.TestEntity.Child.Update(c2); var report = repository.TestEntity.Child.Query().Where(item => item.ID == c.ID) .Select(item => item.Name + " " + item.Parent.Name); Assert.AreEqual("c2 b", TestUtility.DumpSorted(report)); } }
public void InsertPersistent() { using (var container = new RhetosTestContainer()) { var context = container.Resolve <Common.ExecutionContext>(); var repository = container.Resolve <Common.DomRepository>(); repository.TestEntity.Child.Delete(repository.TestEntity.Child.Load()); repository.TestEntity.BaseEntity.Delete(repository.TestEntity.BaseEntity.Load()); var b = new TestEntity.BaseEntity { ID = Guid.NewGuid(), Name = "b" }; var c = new TestEntity.Child { Name = "c", ParentID = b.ID }; repository.TestEntity.BaseEntity.Insert(b); repository.TestEntity.Child.Insert(c); var c2 = repository.TestEntity.Child.Query() .Select(child => new TestEntity.Child { ID = Guid.NewGuid(), Name = "c2", ParentID = child.ParentID }) .ToList(); repository.TestEntity.Child.Insert(c2); context.EntityFrameworkContext.ClearCache(); var ids = repository.TestEntity.Child.Query().Select(child => child.ID).ToList(); Assert.AreEqual(2, ids.Count()); Assert.AreNotEqual(default(Guid), ids[0]); Assert.AreNotEqual(default(Guid), ids[1]); Assert.AreNotEqual(ids[0], ids[1]); var report = repository.TestEntity.Child.Query() .Select(item => item.Name + " " + item.Parent.Name); Assert.AreEqual("c b, c2 b", TestUtility.DumpSorted(report)); } }
public void InsertTransient() { using (var scope = TestScope.Create()) { var context = scope.Resolve <Common.ExecutionContext>(); var repository = context.Repository; var b = new TestEntity.BaseEntity { ID = Guid.NewGuid(), Name = "b" }; var c = new TestEntity.Child { Name = "c", ParentID = b.ID }; repository.TestEntity.BaseEntity.Insert(b); repository.TestEntity.Child.Insert(c); Assert.AreNotEqual(default(Guid), c.ID); var report = repository.TestEntity.Child.Query().Where(item => item.ID == c.ID) .Select(item => item.Name + " " + item.Parent.Name); Assert.AreEqual("c b", TestUtility.DumpSorted(report)); } }
public void GuidAndReferenceNavigation() { using (var container = new RhetosTestContainer()) { container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestEntity.BaseEntity" }); var repository = container.Resolve<Common.DomRepository>(); var context = container.Resolve<Common.ExecutionContext>(); var b1 = new TestEntity.BaseEntity { Name = "b1" }; var b2 = new TestEntity.BaseEntity { Name = "b2" }; repository.TestEntity.BaseEntity.Insert(new[] { b1, b2 }); var c1 = new TestEntity.Child { Name = "c1", Parent = b1 }; // Insert by navigation property. var c2 = new TestEntity.Child { Name = "c2", ParentID = b2.ID }; // Insert by Guid property. repository.TestEntity.Child.Insert(new[] { c1, c2 }); Assert.AreEqual("c1b1, c2b2", TestUtility.DumpSorted(repository.TestEntity.Child.Query(), item => item.Name + item.Parent.Name)); context.NHibernateSession.Clear(); b1 = repository.TestEntity.BaseEntity.Query().Where(item => item.ID == b1.ID).Single(); b2 = repository.TestEntity.BaseEntity.Query().Where(item => item.ID == b2.ID).Single(); c1 = repository.TestEntity.Child.Query().Where(item => item.ID == c1.ID).Single(); c2 = repository.TestEntity.Child.Query().Where(item => item.ID == c2.ID).Single(); // Query by navigation property. Assert.AreEqual("c1b1", TestUtility.DumpSorted(repository.TestEntity.Child.Query() .Where(c => c.Parent == b1), item => item.Name + item.Parent.Name)); // Query by Guid property. Assert.AreEqual("c1b1", TestUtility.DumpSorted(repository.TestEntity.Child.Query() .Where(c => c.ParentID == b1.ID), item => item.Name + item.Parent.Name)); c1.Parent = b2; // Update by navigation property. c2.ParentID = b1.ID; // Update by Guid property. repository.TestEntity.Child.Update(new[] { c1, c2 }); Assert.AreEqual("c1b2, c2b1", TestUtility.DumpSorted(repository.TestEntity.Child.Query(), item => item.Name + item.Parent.Name), "Update by navigation property."); } }
public void SimpleReferenceProperty() { using (var container = new RhetosTestContainer()) { container.Resolve<ISqlExecuter>().ExecuteSql(new[] { "DELETE FROM TestEntity.BaseEntity" }); var repository = container.Resolve<Common.DomRepository>(); var context = container.Resolve<Common.ExecutionContext>(); var b1 = new TestEntity.BaseEntity { Name = "b1" }; var b2 = new TestEntity.BaseEntity { Name = "b2" }; repository.TestEntity.BaseEntity.Insert(b1, b2); var c1 = new TestEntity.Child { Name = "c1", ParentID = b1.ID }; repository.TestEntity.Child.Insert(c1); Assert.AreEqual("c1b1", TestUtility.DumpSorted(repository.TestEntity.Child.Query(), item => item.Name + item.Parent.Name)); context.EntityFrameworkContext.ClearCache(); b1 = repository.TestEntity.BaseEntity.Query().Where(item => item.ID == b1.ID).Single(); c1 = repository.TestEntity.Child.Query().Where(item => item.ID == c1.ID).Single(); Assert.AreEqual("c1b1", TestUtility.DumpSorted(repository.TestEntity.Child.Query() .Where(c => c.ParentID == b1.ID), item => item.Name + item.Parent.Name)); c1.ParentID = b2.ID; repository.TestEntity.Child.Update(c1); Assert.AreEqual("c1b2", TestUtility.DumpSorted(repository.TestEntity.Child.Query(), item => item.Name + item.Parent.Name)); } }
public void UpdatePersistent() { using (var container = new RhetosTestContainer()) { var context = container.Resolve<Common.ExecutionContext>(); var repository = container.Resolve<Common.DomRepository>(); var b = new TestEntity.BaseEntity { ID = Guid.NewGuid(), Name = "b" }; var c = new TestEntity.Child { Name = "c", ParentID = b.ID }; repository.TestEntity.BaseEntity.Insert(b); repository.TestEntity.Child.Insert(c); var b2 = repository.TestEntity.BaseEntity.Query().Where(item => item.ID == b.ID).Single(); b2.Name = "b2"; // Should not be saved when calling Child.Update. var c2 = repository.TestEntity.Child.Query().Where(item => item.ID == c.ID).Single(); Console.WriteLine("c2.GetType().FullName: " + c2.GetType().FullName); c2.Name = "c2"; c2.Parent.Name = "b3"; // Should not be saved when calling Child.Update. repository.TestEntity.Child.Update(c2); context.EntityFrameworkContext.ClearCache(); var report = repository.TestEntity.Child.Query().Where(item => item.ID == c.ID) .Select(item => item.Name + " " + item.Parent.Name); Assert.AreEqual("c2 b", TestUtility.DumpSorted(report)); } }
public void InsertPersistent() { using (var container = new RhetosTestContainer()) { var context = container.Resolve<Common.ExecutionContext>(); var repository = container.Resolve<Common.DomRepository>(); repository.TestEntity.Child.Delete(repository.TestEntity.Child.Load()); repository.TestEntity.BaseEntity.Delete(repository.TestEntity.BaseEntity.Load()); var b = new TestEntity.BaseEntity { ID = Guid.NewGuid(), Name = "b" }; var c = new TestEntity.Child { Name = "c", ParentID = b.ID }; repository.TestEntity.BaseEntity.Insert(b); repository.TestEntity.Child.Insert(c); var c2 = repository.TestEntity.Child.Query() .Select(child => new TestEntity.Child { ID = Guid.NewGuid(), Name = "c2", ParentID = child.ParentID }) .ToList(); repository.TestEntity.Child.Insert(c2); context.EntityFrameworkContext.ClearCache(); var ids = repository.TestEntity.Child.Query().Select(child => child.ID).ToList(); Assert.AreEqual(2, ids.Count()); Assert.AreNotEqual(default(Guid), ids[0]); Assert.AreNotEqual(default(Guid), ids[1]); Assert.AreNotEqual(ids[0], ids[1]); var report = repository.TestEntity.Child.Query() .Select(item => item.Name + " " + item.Parent.Name); Assert.AreEqual("c b, c2 b", TestUtility.DumpSorted(report)); } }
public void UpdateTransient() { using (var container = new RhetosTestContainer()) { var context = container.Resolve<Common.ExecutionContext>(); var repository = container.Resolve<Common.DomRepository>(); var b = new TestEntity.BaseEntity { ID = Guid.NewGuid(), Name = "b" }; var c = new TestEntity.Child { Name = "c", ParentID = b.ID }; repository.TestEntity.BaseEntity.Insert(b); repository.TestEntity.Child.Insert(c); var c2 = new TestEntity.Child { ID = c.ID, Name = "c2", ParentID = b.ID }; repository.TestEntity.Child.Update(c2); context.EntityFrameworkContext.ClearCache(); var report = repository.TestEntity.Child.Query().Where(item => item.ID == c.ID) .Select(item => item.Name + " " + item.Parent.Name); Assert.AreEqual("c2 b", TestUtility.DumpSorted(report)); } }