<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>.Hibri - NHibernate</title>
    <link>http://www.hibri.net/</link>
    <description>Thoughts on the craft of building software</description>
    <language>en-gb</language>
    <copyright>Hibri Marzook</copyright>
    <lastBuildDate>Wed, 10 Jun 2009 17:28:07 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>hibri@hibri.net</managingEditor>
    <webMaster>hibri@hibri.net</webMaster>
    <item>
      <trackback:ping>http://www.hibri.net/Trackback.aspx?guid=3e9fe7f4-3d15-4ced-bcbf-d4abc472be99</trackback:ping>
      <pingback:server>http://www.hibri.net/pingback.aspx</pingback:server>
      <pingback:target>http://www.hibri.net/PermaLink,guid,3e9fe7f4-3d15-4ced-bcbf-d4abc472be99.aspx</pingback:target>
      <dc:creator>Hibri</dc:creator>
      <wfw:comment>http://www.hibri.net/CommentView,guid,3e9fe7f4-3d15-4ced-bcbf-d4abc472be99.aspx</wfw:comment>
      <wfw:commentRss>http://www.hibri.net/SyndicationService.asmx/GetEntryCommentsRss?guid=3e9fe7f4-3d15-4ced-bcbf-d4abc472be99</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.nhprof.com">The NHibernate Profiler</a> is a pretty cool tool.
If you are using NHibernate and want to see how your application/website uses NHibernate
this is what you need. 
</p>
        <p>
But, why wait till you use the whole application to start using the profiler. Why
not use it when writing  writing tests , while building your mappings and when
building your NHibernate queries. It’s really easy to do this.
</p>
        <p>
First, get the NHibernate profiler from <a href="http://www.nhprof.com">www.nhprof.com</a>.
Extract the contents to a location. From your test project, add a reference to <strong>HibernatingRhinos.NHibernate.Profiler.Appender.dll</strong> in
the NHProf package.
</p>
        <p>
This is my small test class.
</p>
        <pre class="csharpcode"> [TestFixture]
    <span class="kwrd">public</span><span class="kwrd">class</span> EpisodeTests
: BaseTest { [SetUp] <span class="kwrd">public</span><span class="kwrd">override</span><span class="kwrd">void</span> SetUp()
{ <span class="kwrd">base</span>.SetUp(); ActiveRecordStarter.Initialize(<span class="kwrd">typeof</span>(Episode).Assembly, <span class="kwrd">new</span> XmlConfigurationSource(<span class="str">"activerecord.xml"</span>));
} [Test] <span class="kwrd">public</span><span class="kwrd">void</span> CanPersistTitle()
{ Episode episode = <span class="kwrd">new</span> Episode(); <span class="kwrd">string</span> expectedTitle
= <span class="str">"Dr Who and the Daleks"</span>; episode.Title = expectedTitle;
episode.Save(); Guid savedEpisodeId = episode.Id; episode = ActiveRecordBase&lt;Episode&gt;.Find(savedEpisodeId);
Assert.That(episode.Title, Is.EqualTo(expectedTitle)); } }</pre>
        <p>
        </p>
        <pre class="csharpcode"> </pre>
        <p>
        </p>
        <p>
I’m using Castle ActiveRecord (which uses NHibernate behind the scenes) to demonstrate
this. To enable NHProf to profile the test, add a static constructor to the super
class , <strong>BaseTest</strong>. In the static constructor, add the following code.
</p>
        <pre class="csharpcode">HibernatingRhinos.NHibernate.Profiler.Appender.NHibernateProfiler.Initialize();</pre>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
        <p>
Go to where you extracted NHProf and run the profiler exe. Run the test and watch
the magic.
</p>
        <p>
          <a href="http://www.hibri.net/content/binary/WindowsLiveWriter/UsingNHibernateProfilerwithdatabaseinte_FDC4/image_2.png">
            <img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.hibri.net/content/binary/WindowsLiveWriter/UsingNHibernateProfilerwithdatabaseinte_FDC4/image_thumb.png" width="659" height="509" />
          </a>
        </p>
        <p>
NHProf is now profiling your integration tests. You can leave this running in the
background while you are working on the tests. 
</p>
        <p>
You get immediate feedback NHibernate best practice violations, and you can<em><strong> fix
them while writing tests</strong>. </em>You don’t have to wait till deployment to
profile your code. Although this doesn’t give the whole picture of how your application
is using NHibernate , you still can fix many things early. I highly recommend running
NHProf while running automated acceptance test scenarios.
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3916a100-f10a-4ead-859e-089ef55b9710" class="wlWriterEditableSmartContent">Technorati
Tags: <a href="http://technorati.com/tags/NHibernate" rel="tag">NHibernate</a>,<a href="http://technorati.com/tags/TDD" rel="tag">TDD</a></div>
        <p>
 
</p>
        <style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
      </body>
      <title>Using NHibernate Profiler with database integration tests.</title>
      <guid isPermaLink="false">http://www.hibri.net/PermaLink,guid,3e9fe7f4-3d15-4ced-bcbf-d4abc472be99.aspx</guid>
      <link>http://www.hibri.net/2009/06/10/UsingNHibernateProfilerWithDatabaseIntegrationTests.aspx</link>
      <pubDate>Wed, 10 Jun 2009 17:28:07 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="http://www.nhprof.com"&gt;The NHibernate Profiler&lt;/a&gt; is a pretty cool tool.
If you are using NHibernate and want to see how your application/website uses NHibernate
this is what you need. 
&lt;/p&gt;
&lt;p&gt;
But, why wait till you use the whole application to start using the profiler. Why
not use it when writing&amp;nbsp; writing tests , while building your mappings and when
building your NHibernate queries. It’s really easy to do this.
&lt;/p&gt;
&lt;p&gt;
First, get the NHibernate profiler from &lt;a href="http://www.nhprof.com"&gt;www.nhprof.com&lt;/a&gt;.
Extract the contents to a location. From your test project, add a reference to &lt;strong&gt;HibernatingRhinos.NHibernate.Profiler.Appender.dll&lt;/strong&gt; in
the NHProf package.
&lt;/p&gt;
&lt;p&gt;
This is my small test class.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt; [TestFixture]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; EpisodeTests
: BaseTest { [SetUp] &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SetUp()
{ &lt;span class="kwrd"&gt;base&lt;/span&gt;.SetUp(); ActiveRecordStarter.Initialize(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Episode).Assembly, &lt;span class="kwrd"&gt;new&lt;/span&gt; XmlConfigurationSource(&lt;span class="str"&gt;"activerecord.xml"&lt;/span&gt;));
} [Test] &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; CanPersistTitle()
{ Episode episode = &lt;span class="kwrd"&gt;new&lt;/span&gt; Episode(); &lt;span class="kwrd"&gt;string&lt;/span&gt; expectedTitle
= &lt;span class="str"&gt;"Dr Who and the Daleks"&lt;/span&gt;; episode.Title = expectedTitle;
episode.Save(); Guid savedEpisodeId = episode.Id; episode = ActiveRecordBase&amp;lt;Episode&amp;gt;.Find(savedEpisodeId);
Assert.That(episode.Title, Is.EqualTo(expectedTitle)); } }&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&amp;nbsp;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
I’m using Castle ActiveRecord (which uses NHibernate behind the scenes) to demonstrate
this. To enable NHProf to profile the test, add a static constructor to the super
class , &lt;strong&gt;BaseTest&lt;/strong&gt;. In the static constructor, add the following code.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;HibernatingRhinos.NHibernate.Profiler.Appender.NHibernateProfiler.Initialize();&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;p&gt;
Go to where you extracted NHProf and run the profiler exe. Run the test and watch
the magic.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.hibri.net/content/binary/WindowsLiveWriter/UsingNHibernateProfilerwithdatabaseinte_FDC4/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.hibri.net/content/binary/WindowsLiveWriter/UsingNHibernateProfilerwithdatabaseinte_FDC4/image_thumb.png" width="659" height="509"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
NHProf is now profiling your integration tests. You can leave this running in the
background while you are working on the tests. 
&lt;/p&gt;
&lt;p&gt;
You get immediate feedback NHibernate best practice violations, and you can&lt;em&gt;&lt;strong&gt; fix
them while writing tests&lt;/strong&gt;. &lt;/em&gt;You don’t have to wait till deployment to
profile your code. Although this doesn’t give the whole picture of how your application
is using NHibernate , you still can fix many things early. I highly recommend running
NHProf while running automated acceptance test scenarios.
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3916a100-f10a-4ead-859e-089ef55b9710" class="wlWriterEditableSmartContent"&gt;Technorati
Tags: &lt;a href="http://technorati.com/tags/NHibernate" rel="tag"&gt;NHibernate&lt;/a&gt;,&lt;a href="http://technorati.com/tags/TDD" rel="tag"&gt;TDD&lt;/a&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;</description>
      <comments>http://www.hibri.net/CommentView,guid,3e9fe7f4-3d15-4ced-bcbf-d4abc472be99.aspx</comments>
      <category>.Net Data</category>
      <category>Agile</category>
      <category>NHibernate</category>
    </item>
  </channel>
</rss>