Geeks With Blogs
Lee Brandt's Blog You're only as smart as your last line of code

It’s true, I swear. It’s very simple to test if you can (C)reate, (R)ead, (U)pdate and (D)elete objects using NHibernate, and Fluent NHibernate makes it one (fluent) line of code!

Suppose we have an Employee object and we want to check that we can CRUD it AND reference to the Company (object) they work for in the mapping. It might look like this:

   1:  new PersistenceSpecification<Employee>(Session)
   2:      .CheckProperty(x => x.FirstName, "Dave")
   3:      .CheckProperty(x => x.LastName, "Jones")
   4:      .CheckProperty(x => x.MiddleInitial, "L")
   5:      .CheckProperty(x => x.DateOfBirth, new DateTime(2008, 11, 1))
   6:      .CheckProperty(x => x.Sex, _sex)
   7:      .CheckReference(x => x.Company, new Company{ CompanyID = 999, Name = "Wonder Wheels" })
   8:      .VerifyTheMappings(); 

Okay, it may not LOOK like one line of code, but I swear it is. One, long, fluent line of code.

Super sweet. If you’ve found better ways, post a comment, I LOVE to learn better ways.



Posted on Thursday, May 7, 2009 7:41 PM | Back to top

Comments on this post: Use NHibernate (With Fluent NHibernate) To Test Your CRUD In One Line Of Code

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Lee Brandt | Powered by: