public void MixingSessionScopeAndTransactionScopes3() { ActiveRecordStarter.Initialize(GetConfigSource(), typeof(PostLazy), typeof(BlogLazy)); Recreate(); PostLazy.DeleteAll(); BlogLazy.DeleteAll(); BlogLazy b = new BlogLazy(); using (new SessionScope()) { b.Name = "a"; b.Author = "x"; b.Save(); using (new TransactionScope()) { for (int i = 1; i <= 10; i++) { PostLazy post = new PostLazy(b, "t", "c", "General"); post.Save(); } } } using (new SessionScope()) { // We should load this outside the transaction scope b = BlogLazy.Find(b.Id); using (TransactionScope transaction = new TransactionScope()) { int total = b.Posts.Count; foreach (PostLazy p in b.Posts) { p.Delete(); } b.Delete(); transaction.VoteRollBack(); } } BlogLazy[] blogs = BlogLazy.FindAll(); Assert.AreEqual(1, blogs.Length); PostLazy[] posts = PostLazy.FindAll(); Assert.AreEqual(10, posts.Length); }
public void Get_with_lazy_classes_does_work() { ActiveRecordStarter.Initialize(GetConfigSource(), typeof(BlogLazy), typeof(PostLazy)); Recreate(); using (new SessionScope()) new BlogLazy { Author = "Mort", Name = "Hourglass" }.Create(); using (new StatelessSessionScope()) { Assert.AreEqual("Mort", BlogLazy.Find(1).Author); // The assert below cannot work, stateless sessions cannot serve proxies. // Assert.AreEqual(0, BlogLazy.Find(1).Posts.Count); } }
public void Updating_stateless_fetched_entities_works() { InitializeLazy(); using (new SessionScope()) CreateLazyBlog(); using (new StatelessSessionScope()) { var blog = BlogLazy.Find(1); Assert.AreEqual("Hourglass", blog.Name); blog.Name = "HOURGLASS"; blog.Update(); } Assert.AreEqual("HOURGLASS", BlogLazy.Find(1).Name); }