Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,124 | Comments: 45,479

filter by tags archive

NHProfAlive! It is alive!

time to read 2 min | 353 words

I just finished writing the final test for the basic functionality that I want for NHibernate Profiler:

public void SelectBlogById()
StatementModel selectBlogById = observer.Model.Sessions.First()
const string expected = @"SELECT this_.Id as Id3_0_,
this_.Title as Title3_0_,
this_.Subtitle as Subtitle3_0_,
this_.AllowsComments as AllowsCo4_3_0_,
this_.CreatedAt as CreatedAt3_0_
FROM Blogs this_
WHERE this_.Id = @p0

Assert.AreEqual(expected, selectBlogById.Text);

I actually had to invest some thought about the architecture of testing this. This little test has a whole set of ideas behind it, about which I'll talk about at a later date. Suffice to say that this test creates a new process, start to listen to interesting things that are going on there (populating the observer model with data).

Another interesting tidbit is that the output is formatted for readability. By default, NHiberante's SQL output looks something like this:

SELECT this_.Id as Id3_0_, this_.Title as Title3_0_, this_.Subtitle as Subtitle3_0_, this_.AllowsComments as AllowsCo4_3_0_, this_.CreatedAt as CreatedAt3_0_ FROM Blogs this_ WHERE this_.Id = @p0

This is pretty hard to read the moment that you have any sort of complex conditions.

More posts in "NHProf" series:

  1. (02 Dec 2008) What is the role of the DBA?
  2. (01 Dec 2008) The stack is not as simple as you wish it to be
  3. (21 Oct 2008) Logging interception
  4. (13 Oct 2008) Another milestone
  5. (13 Oct 2008) Alive! It is alive!



Would you consider the test to be overspecified since formatting changes would break this test which tests functionality?

Cory Foy

Not even formatting changes. This test will fail on Mono/Linux unless the code is compiled because all of those newlines are \r\n and Linux would be \n. Trust me - that was one of the most difficult challenges we faced with getting NUnit running. System.Environment.NewLine is your friend:


Krzysztof Koźmic

Maybe it's time to introduce WhitespaceIgnoringStringComparer ? To NUnit, not Ayende's tool.

Ken Egozi

Is the code available anywhere?

Ayende Rahien


This is going to be commercial, so I don't think so


I was thinking more along the lines of Query.HasColumns(new string[] { "Column1", "Column1").IsForTable("SomeTable"), etc.

Ayende Rahien


Can you explain more? I don't think that I follow you


Instead of checking the SQL string, check what the SQL string is based on so it isn't dependent on formatting changes, those auto generated aliases, etc., Maybe something like:

Assert.IsTrue(selectBlogById.HasTablesExact(new string[] {



Assert.IsTrue(selectBlogById.HasColumnsExact(new string[] {







Comment preview

Comments have been closed on this topic.


  1. RavenDB 3.5 whirl wind tour: I’ll find who is taking my I/O bandwidth and they SHALL pay - one day from now
  2. The design of RavenDB 4.0: Physically segregating collections - about one day from now
  3. RavenDB 3.5 Whirlwind tour: I need to be free to explore my data - 3 days from now
  4. RavenDB 3.5 whirl wind tour: I'll have the 3+1 goodies to go, please - 6 days from now
  5. The design of RavenDB 4.0: Voron has a one track mind - 7 days from now

And 12 more posts are pending...

There are posts all the way to May 30, 2016


  1. RavenDB 3.5 whirl wind tour (14):
    02 May 2016 - You want all the data, you can’t handle all the data
  2. The design of RavenDB 4.0 (13):
    03 May 2016 - Making Lucene reliable
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats