public void ExistsByCriterion() { ActiveRecordStarter.Initialize(GetConfigSource()); ActiveRecordStarter.RegisterTypes(typeof(Blog), typeof(Post)); Recreate(); Blog[] blogs = Blog.FindAll(); Assert.IsNotNull(blogs); Assert.AreEqual(0, blogs.Length); Blog blog = new Blog(); blog.Name = "hammett's blog"; blog.Author = "hamilton verissimo"; blog.Save(); Assert.IsTrue(blog.Id > 0); Assert.IsTrue(Blog.Exists( Expression.Eq("Name", blog.Name), Expression.Eq("Author", blog.Author))); blog = new Blog(); blog.Name = "chad's blog"; blog.Author = "chad humphries"; blog.Save(); Assert.IsTrue(Blog.Exists( Expression.Eq("Name", blog.Name), Expression.Eq("Author", blog.Author))); Assert.IsFalse(Blog.Exists( Expression.Eq("Name", "/\ndrew's Blog"), Expression.Eq("Author", "Andrew Peters"))); }
public void TestName() { ActiveRecordStarter.Initialize(GetConfigSource()); ActiveRecordStarter.RegisterTypes(typeof(Blog), typeof(Post)); Recreate(); Blog blog = new Blog(); blog.Name = null; blog.Author = "hamilton verissimo"; blog.Save(); Blog[] blogs = Blog.FindByProperty("Name", null); Assert.IsTrue(blogs.Length == 1); using (new SessionScope()) { blog.Name = "Hammetts blog"; blog.Save(); } blogs = Blog.FindByProperty("Name", null); Assert.IsTrue(blogs.Length == 0); blogs = Blog.FindByProperty("Name", "Hammetts blog"); Assert.IsTrue(blogs.Length == 1); }
public void RegisterTypeTest() { ActiveRecordStarter.Initialize(GetConfigSource()); ActiveRecordStarter.RegisterTypes(typeof(Blog), typeof(Post)); Recreate(); Post.DeleteAll(); Blog.DeleteAll(); Blog[] blogs = Blog.FindAll(); Assert.IsNotNull(blogs); Assert.AreEqual(0, blogs.Length); Blog blog = new Blog(); blog.Name = "hammett's blog"; blog.Author = "hamilton verissimo"; blog.Save(); blogs = Blog.FindAll(); Assert.IsNotNull(blogs); Assert.AreEqual(1, blogs.Length); Blog retrieved = blogs[0]; Assert.IsNotNull(retrieved); Assert.AreEqual(blog.Name, retrieved.Name); Assert.AreEqual(blog.Author, retrieved.Author); }
public void ExistsTest() { ActiveRecordStarter.Initialize(GetConfigSource()); ActiveRecordStarter.RegisterTypes(typeof(Blog), typeof(Post)); Recreate(); Blog blog = new Blog(); blog.Name = "hammett's blog"; blog.Author = "hamilton verissimo"; blog.Save(); Assert.IsTrue(blog.Id > 0); Assert.IsTrue(Blog.Exists(blog.Id)); blog = new Blog(); blog.Name = "chad's blog"; blog.Author = "chad humphries"; blog.Save(); Assert.IsTrue(Blog.Exists(blog.Id)); Assert.IsFalse(Blog.Exists(1000)); }
public void Subclasses_must_be_registered_with_parent() { // Todo: When refactoring initialization for AR3, consider supporting this functionality. ActiveRecordStarter.Initialize(GetConfigSource(), typeof(Entity), typeof(CompanyEntity)); ActiveRecordStarter.RegisterTypes(typeof(PersonEntity)); }