<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Valeriu Caraulean - Building Software</title>
	<atom:link href="http://blog.caraulean.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.caraulean.com</link>
	<description>Keep it simple. It will work...</description>
	<pubDate>Sat, 20 Dec 2008 17:52:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=MU</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<image>
		<url>http://www.gravatar.com/blavatar/ebb92897c67d3455530a804313905fe1?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Valeriu Caraulean - Building Software</title>
		<link>http://blog.caraulean.com</link>
	</image>
			<item>
		<title>Password Minder on x64</title>
		<link>http://blog.caraulean.com/2008/12/20/password-minder-on-x64/</link>
		<comments>http://blog.caraulean.com/2008/12/20/password-minder-on-x64/#comments</comments>
		<pubDate>Sat, 20 Dec 2008 17:52:51 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/12/20/password-minder-on-x64/</guid>
		<description><![CDATA[After migration to Windows Vista x64 I&#8217;ve found that I can&#8217;t access anymore my passwords stored by Password Minder (original site), a small tool I&#8217;m using to keep my passwords safe. It goes down when you want to launch it. For sure, it is a x64 compatibility problem. 
Fortunately, it is coming with source code. [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>After migration to Windows Vista x64 I&#8217;ve found that I can&#8217;t access anymore my passwords stored by Password Minder (<a href="http://mercury.pluralsight.com/tools.aspx">original site</a>), a small tool I&#8217;m using to keep my passwords safe. It goes down when you want to launch it. For sure, it is a x64 compatibility problem. </p>
<p>Fortunately, it is coming with source code. In a matter of minutes I had the Password Minder compiled for x64 target and running without any issues on my dev box. </p>
<p>Mission complete, passwords saved! </p>
<p>Lesson learned: don&#8217;t forget, you&#8217;re a developer. Don&#8217;t be afraid to use big guns outside of your work <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/41/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/41/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/41/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&blog=1485392&post=41&subd=varely&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/12/20/password-minder-on-x64/feed/</wfw:commentRss>
	
		<media:content url="http://www.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=identicon" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
		<item>
		<title>NHibernate&#8217;s niceties: hbm2ddl auto mode in unit tests</title>
		<link>http://blog.caraulean.com/2008/12/18/nhibernates-niceties-hbm2ddl-auto-mode-in-unit-tests/</link>
		<comments>http://blog.caraulean.com/2008/12/18/nhibernates-niceties-hbm2ddl-auto-mode-in-unit-tests/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 17:33:17 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
		
		<category><![CDATA[NHibernate]]></category>

		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/12/18/nhibernates-niceties-hbm2ddl-auto-mode-in-unit-tests/</guid>
		<description><![CDATA[Very often you&#8217;re going over a description of some function or new feature and just notice in your mind, &#8220;nice feature&#8221; without seeing a real application for it. Later, you&#8217;re coming with scenario where the trick you&#8217;ve read days ago will fit perfectly.
That was the case when I&#8217;ve seen earlier in Tuna Toksoz&#8217;s weblog a [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Very often you&#8217;re going over a description of some function or new feature and just notice in your mind, &#8220;nice feature&#8221; without seeing a real application for it. Later, you&#8217;re coming with scenario where the trick you&#8217;ve read days ago will fit perfectly.</p>
<p>That was the case when I&#8217;ve seen earlier in <a href="http://www.tunatoksoz.com/">Tuna Toksoz</a>&#8217;s weblog a <a href="http://www.tunatoksoz.com/post/NHibernate-hbm2ddl.aspx">description of &#8220;hbm2ddl.auto&#8221; property</a>. Few days ago, I&#8217;ve put it to work in a way that makes me feel better. By the way, the particular reason that made me happy was that I&#8217;ve deleted a lot of repetitive code from our code base.</p>
<h4>How you can use hbm2ddl.auto property in unit tests</h4>
<p>Our integration tests are run over a real database. For each test we&#8217;re re-creating the database, so that each test will be ran in separation and without interfering with results of previous tests. Also, things are a bit complicated since we&#8217;re working with few databases at the same time, each with his own schema. Before, each test had to use SchemaExport class that exported the database schema built from NHibernate configuration on the way deleting your old database/schema/data. So, each integration test class had same method to call. Redundant and repetitive. Yes, you can make a base class that will do that, but you have to inherit then all tests from that class.</p>
<p><strong>How it works now:</strong> in session configuration (usually in app.config for integration test project) you put:</p>
<blockquote><p>&lt;property name=&#8221;hbm2ddl.auto&#8221;&gt;create&lt;/property&gt;</p>
</blockquote>
<p>&#8230; and you&#8217;re set. Each time your code will build a new SessionFactory, NHibernate will call:</p>
<blockquote><p>new SchemaExport(cfg).Create(false, true);</p>
</blockquote>
<p>This way, before the SessionFactory will be built, your database will be refreshed with a new schema and tests will run in a clean database.</p>
<p>One line of code instead of tens or hundreds. Isn&#8217;t that a good trick?!</p>
<p>&nbsp;</p>
<p>A word of warning - don&#8217;t let this code escape to your production code. It may be dangerous&#8230; But, you know that, we&#8217;re running with scissors&#8230;</p>
<p><a href="http://altdotnet.org/"><img height="180" alt="RWS2-Big" src="http://varely.files.wordpress.com/2008/12/rws2-big.png?w=468&#038;h=180" width="468"></a></p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&blog=1485392&post=40&subd=varely&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/12/18/nhibernates-niceties-hbm2ddl-auto-mode-in-unit-tests/feed/</wfw:commentRss>
	
		<media:content url="http://www.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=identicon" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>

		<media:content url="http://varely.files.wordpress.com/2008/12/rws2-big.png" medium="image">
			<media:title type="html">RWS2-Big</media:title>
		</media:content>
	</item>
		<item>
		<title>Starting point is simplicity&#8230;</title>
		<link>http://blog.caraulean.com/2008/11/23/starting-point-is-simplicity/</link>
		<comments>http://blog.caraulean.com/2008/11/23/starting-point-is-simplicity/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 22:22:59 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
		
		<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/11/23/starting-point-is-simplicity/</guid>
		<description><![CDATA[The 37signals quoted: 
A complex system that works is invariably found to have evolved from a simple system that worked. A complex system designed from scratch never works and cannot be patched up to make it work. You have to start over, beginning with a working simple system.
— John Gall

Reading this remind me principles of [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The <a href="http://www.37signals.com/svn/posts/1414-a-complex-system-that-works-is-invariably">37signals</a> quoted: </p>
<blockquote><p>A complex system that works is invariably found to have evolved from a simple system that worked. A complex system designed from scratch never works and cannot be patched up to make it work. You have to start over, beginning with a working simple system.
<p>— John Gall</p>
</blockquote>
<p>Reading this remind me principles of agile software development, &#8220;release early, release often&#8221; way of Open Source Software world and my own indestructible certainty in the fact that a simple working software released today is much better than a complex and over-engineered beast to-be-released-when-it-is-done.</p>
<p>A software is always a solution. Let&#8217;s build first a solution of client&#8217;s problem, thereafter we&#8217;ll add to application all that crap backed in typical business application, like report designers, integration points with 10 external systems and data export in 100 formats. Do the core. Release it. Then go back and do the rest 80% of application that will be used by less than 20% of customers.</p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&blog=1485392&post=32&subd=varely&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/11/23/starting-point-is-simplicity/feed/</wfw:commentRss>
	
		<media:content url="http://www.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=identicon" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
		<item>
		<title>Unit tests with Automatic Transaction Management</title>
		<link>http://blog.caraulean.com/2008/10/03/unit-tests-with-automatic-transaction-management/</link>
		<comments>http://blog.caraulean.com/2008/10/03/unit-tests-with-automatic-transaction-management/#comments</comments>
		<pubDate>Fri, 03 Oct 2008 16:18:43 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
		
		<category><![CDATA[Castle]]></category>

		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/10/03/unit-tests-with-automatic-transaction-management/</guid>
		<description><![CDATA[In our projects we&#8217;re using Castle&#8217;s Automatic Transaction Management facility (ATM). This facility allows to declaratively define transaction boundaries: by marking a method by a specific attribute the call to this method will be wrapped in a transaction, so that a transaction will be opened before calling the method and committed right after finishing method [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In our projects we&#8217;re using Castle&#8217;s Automatic Transaction Management facility (ATM). This facility allows to declaratively define transaction boundaries: by marking a method by a specific attribute the call to this method will be wrapped in a transaction, so that a transaction will be opened before calling the method and committed right after finishing method execution.</p>
<p>In code, it looks like this:</p>
<pre style="border-right:#cecece 1px solid;border-top:#cecece 1px solid;min-height:40px;overflow:auto;border-left:#cecece 1px solid;width:486px;border-bottom:#cecece 1px solid;height:162px;background-color:#fbfbfb;padding:5px;">
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  1: [Transactional]
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  2: <span style="color:#0000ff;">public</span> <span style="color:#0000ff;">class</span> Foo
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  3: {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  4:     [Transaction]
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  5:     <span style="color:#0000ff;">public</span> virtual void Bar()
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  6:     {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  7:         // <span style="color:#0000ff;">Do</span> something <span style="color:#0000ff;">in</span> a transaction
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  8:     }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  9: }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 10: </pre>
</pre>
<p>Let&#8217;s suppose that later, we want to test this code. Say, we want to verify that code in Foo.Bar() method is executed in a transaction. Moreover, we want to assure that the marking attributes will not be deleted accidentally.</p>
<p>We can test that within two aspects. First - an integration test: a real application part will be spawned and a call will be performed. After, we should verify that changes was committed by transaction. It takes time to run such a test (integration test usually runs slower) and effort to write &amp; verify such a test. Second way to test that - is to check presence or required attributes. This will be a fast unit test that will just check that attribute is still applied to a method.</p>
<p>Those methods complements each other. Ideally, it should be both written.</p>
<p>Let&#8217;s see how we can verify that attributes required by ATM are applied to required methods.</p>
<p>First, we&#8217;ve defined the API that we want to use to do our check:</p>
<pre style="border-right:#cecece 1px solid;border-top:#cecece 1px solid;min-height:40px;overflow:auto;border-left:#cecece 1px solid;width:468px;border-bottom:#cecece 1px solid;height:64px;background-color:#fbfbfb;padding:5px;">
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  1: CustomAssertions.ShouldUseATM&lt;Foo&gt;(foo =&gt; foo.Bar());</pre>
</pre>
<p>Yes, you see it right, we want to make it type save, refactor-able and nice looking.</p>
<p>This helper class should verify next assumptions, all required by ATM:</p>
<ul>
<li>Tested class should be marked with TransactionalAttribute;
<li>Method should be marked by TransactionAttribute;
<li>Method should be virtual.</li>
</ul>
<p>Solution we came to this problem is the next class:</p>
<pre style="border-right:#cecece 1px solid;border-top:#cecece 1px solid;min-height:40px;overflow:auto;border-left:#cecece 1px solid;width:495px;border-bottom:#cecece 1px solid;height:636px;background-color:#fbfbfb;padding:5px;">
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  1: <span style="color:#0000ff;">public</span> static partial <span style="color:#0000ff;">class</span> CustomAssertions
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  2: {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  3:     <span style="color:#0000ff;">public</span> static void ShouldUseATM&lt;T&gt;(Expression&lt;Action&lt;T&gt;&gt; methodExpression) where T : <span style="color:#0000ff;">class</span>
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  4:     {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  5:         ThrowIfTypeNotMarkedAsTransactional(typeof (T));
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  6:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  7:         var methodInfo = ((MethodCallExpression) methodExpression.Body).Method;
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;">  8:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;">  9:         ThrowIfMethodIsNotMarkedWithTransactionAttribute(methodInfo);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 10:         ThrowIfMethodMarkedWithTransactionAttributeIsVirtual(methodInfo);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 11:     }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 12:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 13:     <span style="color:#0000ff;">private</span> static void ThrowIfTypeNotMarkedAsTransactional(Type classType)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 14:     {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 15:         object[] foundAttributes = classType.GetCustomAttributes(typeof (TransactionalAttribute), false);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 16:         <span style="color:#0000ff;">if</span> (foundAttributes.Length == 0)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 17:             Assert.Fail("<span style="color:#8b0000;">The type '{0}' is not marked with [Transactional] attribute</span>", classType.Name);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 18:     }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 19:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 20:     <span style="color:#0000ff;">private</span> static void ThrowIfMethodIsNotMarkedWithTransactionAttribute(MethodInfo info)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 21:     {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 22:         var found = info.GetCustomAttributes(typeof (TransactionAttribute), false);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 23:         <span style="color:#0000ff;">if</span> (found.Length == 0)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 24:             Assert.Fail("<span style="color:#8b0000;">Method '{0}' from '{1}' type is not marked with [Transaction] attribute</span>",
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 25:                         info.Name,
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 26:                         info.DeclaringType.Name);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 27:     }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 28:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 29:     <span style="color:#0000ff;">private</span> static void ThrowIfMethodMarkedWithTransactionAttributeIsVirtual(MethodBase methodInfo)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 30:     {
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 31:         <span style="color:#0000ff;">if</span> (methodInfo.IsVirtual &amp;&amp; !methodInfo.IsFinal)
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 32:             return;
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 33:
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 34:         Assert.Fail("<span style="color:#8b0000;">Method '{0}' from '{1}' type is marked with [Transaction] attribute, but is not declared as virtual.</span>",
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 35:                     methodInfo.Name,
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 36:                     methodInfo.DeclaringType.Name);
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 37:     }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#ffffff;margin:0;"> 38: }
</pre>
<pre style="font-size:12px;width:100%;font-family:consolas,'Courier New',courier,monospace;background-color:#fbfbfb;margin:0;"> 39: </pre>
</pre>
<p>So far, we&#8217;re pleased with how it works for us. </p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&blog=1485392&post=31&subd=varely&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/10/03/unit-tests-with-automatic-transaction-management/feed/</wfw:commentRss>
	
		<media:content url="http://www.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=identicon" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
		<item>
		<title>Additional identity column with NHibernate</title>
		<link>http://blog.caraulean.com/2008/08/26/additional-identity-column-with-nhibernate/</link>
		<comments>http://blog.caraulean.com/2008/08/26/additional-identity-column-with-nhibernate/#comments</comments>
		<pubDate>Tue, 26 Aug 2008 09:51:49 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/08/26/additional-identity-column-with-nhibernate/</guid>
		<description><![CDATA[As always, business requirement went over existing code base to ask for a minor change that wasn&#8217;t compatible with our existing infrastructure: all surrogate keys are unique identifiers (Guid) and all infrastructure was built around that. The business people asked to add to an existing domain entity a natural key - integer identity number (auto [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As always, business requirement went over existing code base to ask for a minor change that wasn&#8217;t compatible with our existing infrastructure: all surrogate keys are unique identifiers (Guid) and all infrastructure was built around that. The business people asked to add to an existing domain entity a natural key - integer identity number (auto increment field), to serve as a reference number.</p>
<p>We had two choices: </p>
<ul>
<li>to generate the identity from business code</li>
<li>to let database manage it for us.</li>
</ul>
<p>The second approach it preferable for us because it&#8217;s the database&#8217;s job to generate the keys.</p>
<p>Out of the box NHibernate doesn&#8217;t support such a thing. Answers to my question in <a href="http://groups.google.com/group/nhusers?hl=en">NHibernate Users discussion group</a> led to the next solution.</p>
<p>Given the class:</p>
<pre class="code"><span style="color:blue;">public class </span><span style="color:#2b91af;">Entity
</span>{
    <span style="color:blue;">public int </span>Id { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
    <span style="color:blue;">public int </span>Id2 { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
}
</pre>
<p>First &#8220;Id&#8221; is the primary key, the second is the key that we want to map to identity column. To have that done we should do two things:</p>
<ul>
<li>Map &#8220;Id2&#8243; property as &#8220;generated&#8221;</li>
<li>Use &#8220;database-object&#8221; to drop the column generated by NHibernate &amp; create new one, with IDENTITY set on.</li>
</ul>
<p>The complete mapping:</p>
<pre class="code"><span style="color:blue;">&lt;</span><span style="color:#a31515;">hibernate-mapping </span><span style="color:red;">xmlns:xsi</span><span style="color:blue;">=</span>"<span style="color:blue;">http://www.w3.org/2001/XMLSchema-instance</span>" <span style="color:red;">xmlns:xsd</span><span style="color:blue;">=</span>"<span style="color:blue;">http://www.w3.org/2001/XMLSchema</span>"
    <span style="color:red;">namespace</span><span style="color:blue;">=</span>"<span style="color:blue;">NHibernate.Playground</span>"
    <span style="color:red;">assembly</span><span style="color:blue;">=</span>"<span style="color:blue;">NHibernate.Playground</span>"
    <span style="color:red;">default-lazy</span><span style="color:blue;">=</span>"<span style="color:blue;">false</span>" <span style="color:red;">xmlns</span><span style="color:blue;">=</span>"<span style="color:blue;">urn:nhibernate-mapping-2.2</span>"<span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">class </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">Entity</span>"<span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">id </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">Id</span>"<span style="color:blue;">&gt;
      &lt;</span><span style="color:#a31515;">generator </span><span style="color:red;">class</span><span style="color:blue;">=</span>"<span style="color:blue;">increment</span>" <span style="color:blue;">/&gt;
    &lt;/</span><span style="color:#a31515;">id</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">property </span><span style="color:red;">name</span><span style="color:blue;">=</span>"<span style="color:blue;">Id2</span>" <span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">int</span>" <span style="color:red;">generated</span><span style="color:blue;">=</span>"<span style="color:blue;">always</span>" <span style="color:red;">insert</span><span style="color:blue;">=</span>"<span style="color:blue;">false</span>" <span style="color:blue;">/&gt;
  &lt;/</span><span style="color:#a31515;">class</span><span style="color:blue;">&gt;
  &lt;</span><span style="color:#a31515;">database-object</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">create</span><span style="color:blue;">&gt;
      </span>ALTER TABLE Entity DROP COLUMN Id2
      ALTER TABLE Entity ADD Id2 INT IDENTITY
    <span style="color:blue;">&lt;/</span><span style="color:#a31515;">create</span><span style="color:blue;">&gt;
    &lt;</span><span style="color:#a31515;">drop</span><span style="color:blue;">&gt;
      </span>ALTER TABLE Entity DROP COLUMN Id2
    <span style="color:blue;">&lt;/</span><span style="color:#a31515;">drop</span><span style="color:blue;">&gt;
  &lt;/</span><span style="color:#a31515;">database-object</span><span style="color:blue;">&gt;
&lt;/</span><span style="color:#a31515;">hibernate-mapping</span><span style="color:blue;">&gt;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a><a href="http://11011.net/software/vspaste"></a></p>
<p>I like the flexibility offered by NHibernate. Even if you don&#8217;t have required feature, you can always use naked ADO.NET or raw SQL.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/varely.wordpress.com/30/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/varely.wordpress.com/30/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&blog=1485392&post=30&subd=varely&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/08/26/additional-identity-column-with-nhibernate/feed/</wfw:commentRss>
	
		<media:content url="http://www.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=identicon" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
		<item>
		<title>No luck with tools lately&#8230;</title>
		<link>http://blog.caraulean.com/2008/08/13/no-luck-with-tools-lately/</link>
		<comments>http://blog.caraulean.com/2008/08/13/no-luck-with-tools-lately/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 12:22:28 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
		
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/08/13/no-luck-with-tools-lately/</guid>
		<description><![CDATA[AnkhSVN
A mate came on me with &#8220;I found a wonderful SVN client which works from Visual Studio. It&#8217;s called AnkhSVN&#8220;. When I tried it last time it was in version 1.x, ugly &#38; buggy. Having a well working TortoiseSVN I had no regrets uninstalling it. 
Lately it passed a major update. It looks nicer, integrates [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h4>AnkhSVN</h4>
<p>A mate came on me with &#8220;I found a wonderful SVN client which works from Visual Studio. It&#8217;s called <a href="http://ankhsvn.open.collab.net/">AnkhSVN</a>&#8220;. When I tried it last time it was in version 1.x, ugly &amp; buggy. Having a well working TortoiseSVN I had no regrets uninstalling it. </p>
<p>Lately it passed a major update. It looks nicer, integrates well in VS and has all functions required for day-by-day work with Subversion. The mate who recommended it said that he found no problems during a week of trying it. </p>
<p>Ok. Having a refactoring to do that will involve moving few files I decided to give it a try. Moving/renaming files is one of the pain points when working with TortoiseSVN. After committing my changes to repository, the TeamCity server failed to build the project - few files was missing or had unmodified content when it should. AnkhSVN didn&#8217;t committed all changed files to repository. In VS they was shown as unmodified, but TortoiseSVN show them as changed files. A commit from TortoiseSVN has fixed the problem. </p>
<p>Still in doubts about it, worth keeping or not&#8230;</p>
<p>&nbsp;</p>
<h4>MBUnit Plugin for Resharper</h4>
<p>I wanted to run test suite of Rhino.Mocks which uses MBUnit. First try - installed last version of <a href="http://code.google.com/p/mbunit-resharper/">MBUnit plugin for Resharper</a>. It worked nice when I run a single test fixture. But failed to find any tests when I choose &#8220;Run Unit Tests&#8221; from context menu of a project or solution. Uninstalled.</p>
<p>&nbsp;</p>
<h4>Gallio Automation platform</h4>
<p>Still wanted to run the Rhino.Mocks&#8217;s unit tests, installed <a href="http://www.gallio.org/">Gallio</a> a bundle that contains among others the MBUnit, a standalone test runner and yet another MBUnit integration into Resharper&#8217;s Test Runner. Results:</p>
<ul>
<li>Integration with Resharper: didn&#8217;t discovered all test from test project, cannot run those discovered.</li>
<li>Standalone test runner - cannot run test suite, FixtureExecutionException.</li>
</ul>
<h3></h3>
<p>The last two tools concerns MBUnit. All I wanted to do is just to run quickly a test suite. I can do it from console, but it&#8217;s painful and I want to do it from VS and have results there. I can do it with TestDriven.NET - but I don&#8217;t like it because found it too intrusive in my work environment. I think this is the reason why we haven&#8217;t moved to MBUnit from NUnit. It&#8217;s it superior as unit test framework, but weak tooling support make it unusable for us.</p>
<p>&amp; no time now to check what is not working and how to fix it. May be later&#8230;</p>
<p>PS: I&#8217;ve seen it one more time: It&#8217;s very important the very first impression about something to be positive. If somebody tries your software and it blows up or doesn&#8217;t do what is it about, you fail. But this is another story&#8230;</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/varely.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/varely.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&blog=1485392&post=29&subd=varely&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/08/13/no-luck-with-tools-lately/feed/</wfw:commentRss>
	
		<media:content url="http://www.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=identicon" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
		<item>
		<title>TortoiseSVN 1.5.x cannot start on Vista because of &#34;Dependent Assembly Microsoft.VC90.CRT could not be found&#34; error</title>
		<link>http://blog.caraulean.com/2008/08/05/tortoisesvn-15x-cannot-start-on-vista-because-of-dependent-assembly-microsoftvc90crt-could-not-be-found-error/</link>
		<comments>http://blog.caraulean.com/2008/08/05/tortoisesvn-15x-cannot-start-on-vista-because-of-dependent-assembly-microsoftvc90crt-could-not-be-found-error/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 09:40:30 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
		
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/08/05/tortoisesvn-15x-cannot-start-on-vista-because-of-dependent-assembly-microsoftvc90crt-could-not-be-found-error/</guid>
		<description><![CDATA[After installation on my Vista box, TortoiseSVN cannot start, giving an entry in event log that says: 
Activation context generation failed for &#8220;C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe&#8221;. Dependent Assembly Microsoft.VC90.CRT,processorArchitecture=&#8221;x86&#8243;,publicKeyToken=&#8221;1fc8b3b9a1e18e3b&#8221;,type=&#8221;win32&#8243;,version=&#8221;9.0.30411.0&#8243; could not be found. 

At first sight, the missing &#8220;Microsoft.VC90&#8243; points to absence of Visual C++ Redistributable Package. Installing all of his versions didn&#8217;t help. After trying to [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>After installation on my Vista box, TortoiseSVN cannot start, giving an entry in event log that says: </p>
<blockquote><p>Activation context generation failed for &#8220;C:\Program Files\TortoiseSVN\bin\TortoiseProc.exe&#8221;. Dependent Assembly Microsoft.VC90.CRT,processorArchitecture=&#8221;x86&#8243;,publicKeyToken=&#8221;1fc8b3b9a1e18e3b&#8221;,type=&#8221;win32&#8243;,version=&#8221;9.0.30411.0&#8243; could not be found. </p>
</blockquote>
<p>At first sight, the missing &#8220;Microsoft.VC90&#8243; points to absence of Visual C++ Redistributable Package. Installing all of his versions didn&#8217;t help. After trying to work out this error, it magically disappeared and TortoiseSVN started successfully and worked well&#8230;</p>
<p>&#8230;until today, when I&#8217;ve upgraded to 1.5.2. Same error. Didn&#8217;t want to start. Now on two PC&#8217;s from office.</p>
<p>After searching for solution, found on a TortoiseSVN&#8217;s discussion lists a recipe that worked OK for me. I&#8217;ll cite it here with explanation, is given by Stefan Küng, one of TortoiseSVN developers:</p>
<blockquote><p>try this: <br />uninstall TSVN, reboot, install it again.
<p>There&#8217;s a problem with the new CRT merge module from MS: it does not recognize always that is has to update itself.</p>
</blockquote>
<p>The good old way: uninstall, reboot, install. So windows95-ish. </p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/varely.wordpress.com/24/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/varely.wordpress.com/24/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/24/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/24/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/24/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&blog=1485392&post=24&subd=varely&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/08/05/tortoisesvn-15x-cannot-start-on-vista-because-of-dependent-assembly-microsoftvc90crt-could-not-be-found-error/feed/</wfw:commentRss>
	
		<media:content url="http://www.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=identicon" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
		<item>
		<title>Configuring NServiceBus using Binsor</title>
		<link>http://blog.caraulean.com/2008/07/13/configuring-nservicebus-using-binsor/</link>
		<comments>http://blog.caraulean.com/2008/07/13/configuring-nservicebus-using-binsor/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 20:58:29 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
		
		<category><![CDATA[Castle]]></category>

		<category><![CDATA[Development]]></category>

		<category><![CDATA[NServiceBus]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/07/13/configuring-nservicebus-using-binsor/</guid>
		<description><![CDATA[I&#8217;m evaluating the NServiceBus communication framework for using it in some parts of application that we&#8217;re working on. I like the messaging infrastructure that it offers and how it all is implemented - behind a simple interface is hidden a modular, extensible, reliable and extremely powerful messaging engine. Sure, like any other framework, it has [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;m evaluating the <a href="http://nservicebus.com/">NServiceBus</a> communication framework for using it in some parts of application that we&#8217;re working on. I like the messaging infrastructure that it offers and how it all is implemented - behind a simple interface is hidden a modular, extensible, reliable and extremely powerful messaging engine. Sure, like any other framework, it has his own pitfalls and places that requires a special knowledge about how things works to use it efficiently. </p>
<p>One of those tricky places is his configuration system. To start use NServiceBus you have to do few steps to properly configure it. You have to use 2-3 &#8220;app.config&#8221; configuration sections with approximately 10-15 various parameters and few configuration classes provided by NServiceBus. </p>
<p>Another place that make me stuck is his integration with IoC (Inversion of Control) container. It has an abstraction over all container stuff, so you can pretty easily create an adapter to use it with container of your choice. I don&#8217;t like how this abstraction is used and implemented, a bit unnatural for my habits on how to put container to work.</p>
<p>Anyway, we have to deal with it, and use the NServiceBus with Castle Windsor container. As I said to do that you have to create an adapter for IBuilder interface. The NServiceBus Contrib project contains a patch that do this, but it is done in a completely wrong way - by mimicking the adapter for Spring framework. Bad, bad, bad&#8230;</p>
<p>So let&#8217;s take our big gun - Binsor from Rhino.Tools (I wrote about <a href="http://blog.caraulean.com/2008/05/14/configuring-nhibernateintegration-facility-with-binsor/">here</a>) that should do all dirty work by configuring NServiceBus and integrating it in our existing Windsor container. The link to VS solution with all code shown here is provided at the end of the page.</p>
<p>Here we go - how to configure a subscriber for Pub/Sub interactions:</p>
<p>1. Binsor configuration (.boo file):</p>
<pre class="code">import System.Reflection
import NServiceBus
import NServiceBus.Unicast
import NServiceBus.Serialization
import NServiceBus.Serializers.Binary
import NServiceBus.Unicast.Transport
import NServiceBus.Unicast.Transport.Msmq
import NServiceBus.Unicast.Subscriptions
import NServiceBus.Unicast.Subscriptions.Msmq

import ObjectBuilder
import nServiceBus.CastleIntegration

component IBus, NServiceBus.Unicast.UnicastBus:
    MessageOwners = {"Messages":"messagebus"}
    MessageHandlerAssemblies = [Assembly.Load("Subscriber1")]

component ITransport, MsmqTransport:
    InputQueue = "worker"
    ErrorQueue = "error"
    NumberOfWorkerThreads = 1
    MaxRetries = 5
    IsTransactional = false
    PurgeOnStartup = false

component IMessageSerializer, MessageSerializer
component IBuilder, Builder
</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p><a href="http://11011.net/software/vspaste"></a>&nbsp;</p>
<p>2. Program initialization:</p>
<pre class="code"><span style="color:blue;">var </span>container = <span style="color:blue;">new </span><span style="color:#2b91af;">WindsorContainer</span>();

<span style="color:#2b91af;">BooReader</span>.Read(container, <span style="color:#a31515;">"nServiceBus.boo"</span>);

container.Register(<span style="color:#2b91af;">SagasAndMessageHandlers</span>.From(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">EventMessageHandler</span>).Assembly));

<span style="color:blue;">var </span>bus = container.Resolve&lt;<span style="color:#2b91af;">IBus</span>&gt;();

bus.Start();
</pre>
<p><a href="http://11011.net/software/vspaste"></a>&nbsp;</p>
<p>That&#8217;s all. Now you can start send/receive messages.</p>
<p>For my taste this is much more readable and maintainable than traditional NServiceBus configuration. Less code, no XML, much cleaner, container friendly.</p>
<p>To make this work you have need for adapter class itself. His responsibility is to forward IBuilder.Build&lt;T&gt; calls to Castle&#8217;s Resolve&lt;T&gt; methods. Also, a small helper class that will register Sagas and MessageHandlers in container. Here it is:</p>
<pre class="code"><span style="color:blue;">public static class </span><span style="color:#2b91af;">SagasAndMessageHandlers
</span>{
    <span style="color:blue;">public static </span><span style="color:#2b91af;">IRegistration</span>[] From(<span style="color:blue;">params </span><span style="color:#2b91af;">Assembly</span>[] assemblies)
    {
        <span style="color:blue;">var </span>registrations = <span style="color:blue;">new </span><span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">ComponentRegistration</span>&gt;();
        <span style="color:blue;">foreach </span>(<span style="color:blue;">var </span>assembly <span style="color:blue;">in </span>assemblies)
        {
            <span style="color:blue;">var </span>types = assembly.GetTypes();
            <span style="color:blue;">foreach </span>(<span style="color:blue;">var </span>type <span style="color:blue;">in </span>types)
            {
                <span style="color:blue;">var </span>implementedInterfaces = type.GetInterfaces();
                <span style="color:blue;">foreach </span>(<span style="color:blue;">var </span>interf <span style="color:blue;">in </span>implementedInterfaces)
                {
                    <span style="color:blue;">if </span>(!interf.IsGenericType)
                        <span style="color:blue;">continue</span>;
                    <span style="color:blue;">var </span>genericArguments = interf.GetGenericArguments();
                    <span style="color:blue;">if </span>(genericArguments.Length != 1)
                        <span style="color:blue;">continue</span>;

                    <span style="color:blue;">if </span>(!<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">IMessage</span>).IsAssignableFrom(genericArguments[0]))
                        <span style="color:blue;">continue</span>;

                    <span style="color:blue;">var </span>sagaHandlerType = <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">ISaga</span>&lt;&gt;).MakeGenericType(genericArguments[0]);
                    <span style="color:blue;">if </span>(sagaHandlerType.IsAssignableFrom(interf))
                    {
                        registrations.Add(CreateRegistration(type, sagaHandlerType));
                        registrations.Add(CreateRegistration(type, type));
                    }

                    <span style="color:blue;">var </span>messageHandlerType = <span style="color:blue;">typeof </span>(<span style="color:#2b91af;">IMessageHandler</span>&lt;&gt;).MakeGenericType(genericArguments[0]);
                    <span style="color:blue;">if </span>(messageHandlerType.IsAssignableFrom(interf))
                        registrations.Add(CreateRegistration(type, type));
                }
            }
        }
        <span style="color:blue;">return </span>registrations.ToArray();
    }

    <span style="color:blue;">private static </span><span style="color:#2b91af;">ComponentRegistration </span>CreateRegistration(<span style="color:#2b91af;">Type </span>type, <span style="color:#2b91af;">Type </span>handlerType)
    {
        <span style="color:blue;">string </span>componentName;
        <span style="color:blue;">if </span>(type == handlerType)
            componentName = type.FullName;
        <span style="color:blue;">else
            </span>componentName = type.FullName + handlerType.FullName;

        <span style="color:blue;">return </span>(<span style="color:#2b91af;">ComponentRegistration</span>)<span style="color:#2b91af;">Component
                                          </span>.For(handlerType)
                                          .ImplementedBy(type)
                                          .LifeStyle.Is(<span style="color:#2b91af;">LifestyleType</span>.Transient)
                                          .Named(componentName);
    }
}
</pre>
<p>&nbsp;</p>
<p>One thing to notice here, NServiceBus required that a saga to be registered as a saga handler ( ISaga&lt;Message&gt;) and as a Saga class itself. A better way will be to use Castle&#8217;s newly added forwarding ability, when a component implementation can be accessed through multiple interfaces all forwarded to component&#8217;s instance. Bud I had no time to play with this feature yet, so this duplication will still here some time given the fact that no bugs showed up.</p>
<p>You can download a Visual Studio solution with all code shown here from <a href="http://cid-dcef5f73996bad79.skydrive.live.com/self.aspx/Blog/nServiceBus.CastleIntegration.zip">this place</a>. It contains all infrastructure code and two working sample projects ported from original NServiceBus samples - Pub/Sub &amp; Saga.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/varely.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/varely.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&blog=1485392&post=23&subd=varely&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/07/13/configuring-nservicebus-using-binsor/feed/</wfw:commentRss>
	
		<media:content url="http://www.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=identicon" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
		<item>
		<title>What integration tests should you write first</title>
		<link>http://blog.caraulean.com/2008/06/18/what-integration-tests-should-you-write-first/</link>
		<comments>http://blog.caraulean.com/2008/06/18/what-integration-tests-should-you-write-first/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 10:18:10 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
		
		<category><![CDATA[Castle]]></category>

		<category><![CDATA[NHibernate]]></category>

		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/06/18/what-integration-tests-should-you-write-first/</guid>
		<description><![CDATA[Generally, the goal of integration tests is to verify that different application parts are glued well together and interacts as expected. Thus, they are a bit different thing from unit tests that tends to test how a small, separate part is acting. Below are two tests that I can&#8217;t classify to be pure integration tests [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Generally, the goal of integration tests is to verify that different application parts are glued well together and interacts as expected. Thus, they are a bit different thing from unit tests that tends to test how a small, separate part is acting. Below are two tests that I can&#8217;t classify to be pure integration tests because they touch a sensible part of application/infrastructure configuration like Windsor&#8217;s configuration files and NHibernate&#8217;s mappings. These simple tests can save a lot of time at very initial development stage when application bits are changed frequently and later, as a guarantee that you&#8217;ve not broken something in a recent refactoring.</p>
<h4>Can_resolve_all_services_in_container()</h4>
<p><a href="http://weblogs.asp.net/bsimser/default.aspx">Bill Simser</a> wrote some time ago about <a href="http://weblogs.asp.net/bsimser/archive/2008/06/04/the-first-spec-you-should-write-when-using-castle.aspx">the first test to be written when using Castle&#8217;s Windsor Container</a>. It&#8217;s a real gem that let&#8217;s you verify if any of services registered in container can be resolved (have all required dependencies). Here is it, a bit improved for skipping verification for generic types, since, at that moment, we don&#8217;t know the generic argument for type to be constructed:</p>
<pre class="code">[<span style="color:#2b91af;">Test</span>]
<span style="color:blue;">public void </span>Can_resolve_all_services_in_container()
{
    <span style="color:blue;">var </span>container = <span style="color:blue;">new </span><span style="color:#2b91af;">WindsorContainer</span>(<span style="color:#a31515;">"container.xml"</span>);
    <span style="color:blue;">foreach </span>(<span style="color:#2b91af;">IHandler </span>handler <span style="color:blue;">in </span>container.Kernel.GetAssignableHandlers(<span style="color:blue;">typeof</span>(<span style="color:blue;">object</span>)))
    {
        <span style="color:blue;">if </span>(handler.ComponentModel.Service.IsGenericType)
            <span style="color:blue;">continue</span>;

        container.Resolve(handler.ComponentModel.Service);
    }
}
</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<h4>Can_compile_NHibernate_mapping_configuration()</h4>
<p>This test was sitting for a long time in our codebase, but I&#8217;ve seen it recently in <a href="http://codebetter.com/blogs/david_laribee/archive/2008/06/17/test-your-nhibernate-mappings.aspx">this post</a> of <a href="http://codebetter.com/blogs/david_laribee/default.aspx">David Larebee</a>. I wrote it in times when writing our first mappings and the only one way to verify if you don&#8217;t have any faults was to write one of CRUD operations and run the test. But that&#8217;s a long process. Shorter response cycle is always better. Here it is:</p>
<pre class="code">[<span style="color:#2b91af;">Test</span>]
<span style="color:blue;">public void </span>Can_compile_NHibernate_mapping_configuration()
{
    <span style="color:#2b91af;">ISessionFactory </span>factory =
        <span style="color:blue;">new </span><span style="color:#2b91af;">Configuration</span>()
            .Configure()
            .AddAssembly(<span style="color:#a31515;">"MyApp.MyDomainAssembly"</span>)
            .BuildSessionFactory();

    <span style="color:#2b91af;">Assert</span>.IsNotNull(factory);
}
</pre>
<p>This test suppose that you have HNibernate configuration in your app.config and tries to register all mappings from given assembly file.</p>
<p>&nbsp;</p>
<p><a href="http://11011.net/software/vspaste"></a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/varely.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/varely.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&blog=1485392&post=22&subd=varely&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/06/18/what-integration-tests-should-you-write-first/feed/</wfw:commentRss>
	
		<media:content url="http://www.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=identicon" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
		<item>
		<title>Configuring NHibernateIntegration facility with Binsor</title>
		<link>http://blog.caraulean.com/2008/05/14/configuring-nhibernateintegration-facility-with-binsor/</link>
		<comments>http://blog.caraulean.com/2008/05/14/configuring-nhibernateintegration-facility-with-binsor/#comments</comments>
		<pubDate>Wed, 14 May 2008 19:15:46 +0000</pubDate>
		<dc:creator>Valeriu Caraulean</dc:creator>
		
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://varely.wordpress.com/2008/05/14/configuring-nhibernateintegration-facility-with-binsor/</guid>
		<description><![CDATA[In our projects we&#8217;re using Binsor to configure services in our Windsor container. Main reason to do that is Binsor&#8217;s extreme expressiveness. It&#8217;s much easier to write and maintain next fragment:
import MyApp.Services
component IMyService, MyService


compared with standard way of configuring components in Windsor:
&#60;component
    id="my_service"
    type="MyApp.Services.IMyService, MyApp"
    service="MyApp.Services.MyService, [...]]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In our projects we&#8217;re using <a href="http://www.ayende.com/Blog/archive/7268.aspx">Binsor</a> to configure services in our Windsor container. Main reason to do that is Binsor&#8217;s extreme expressiveness. It&#8217;s much easier to write and maintain next fragment:</p>
<pre>import MyApp.Services
component IMyService, MyService</pre>
<p><a href="http://11011.net/software/vspaste"></a>
<pre></pre>
<p>compared with standard way of configuring components in Windsor:</p>
<pre><span style="color:blue;">&lt;</span><span style="color:#a31515;">component
    </span><span style="color:red;">id</span><span style="color:blue;">=</span>"<span style="color:blue;">my_service</span>"
    <span style="color:red;">type</span><span style="color:blue;">=</span>"<span style="color:blue;">MyApp.Services.IMyService, MyApp</span>"
    <span style="color:red;">service</span><span style="color:blue;">=</span>"<span style="color:blue;">MyApp.Services.MyService, MyApp</span>" <span style="color:blue;">/&gt;</span></pre>
<p><span style="color:blue;"><font color="#545454">Difference is more evident when you have to maintain files with tens and hundreds of components. Sure, you can use some kind of &#8220;autoregistration&#8221; for components, this can reduce dramatically size of configuration files.</font></span></p>
<p><span style="color:blue;"><font color="#545454">But, since Binsor is a kind of DSL, is not always evident how to configure complex components that have dependencies and configuration properties to specify. The Binsor&#8217;s unit tests are the place where to look for samples, but they don&#8217;t cover everything. </font></span></p>
<p><span style="color:blue;"><font color="#545454">Today, I had to configure a NHibernateIntegration facility from <a href="http://www.castleproject.org/">Castle</a> with Binsor. After some time I had next solution for configuring two factories:</font></span></p>
<pre>import Castle.Facilities.NHibernateIntegration
import Rhino.Commons
import NHibernate.Playground</pre>
<pre>facility NHibernateFacility:
    configuration:
        factory:
            @id = 'factory_1'
            settings(keymap):
                dialect = 'NHibernate.Dialect.MsSql2005Dialect'
                connection.provider = 'NHibernate.Connection.DriverConnectionProvider'
                connection.driver_class = 'NHibernate.Driver.SqlClientDriver'
                connection.connection_string = "Server=.\\SQLEXPRESS;initial catalog=test;Integrated Security=SSPI"
            assemblies:
                assembly = 'NHibernate.Playground'
    configuration:
        factory:
            @id = 'factory_2', alias = 'test2'
            settings(keymap):
                dialect = 'NHibernate.Dialect.MsSql2005Dialect'
                connection.provider = 'NHibernate.Connection.DriverConnectionProvider'
                connection.driver_class = 'NHibernate.Driver.SqlClientDriver'
                connection.connection_string = "Server=.\\SQLEXPRESS;initial catalog=test2;Integrated Security=SSPI"
            assemblies:
                assembly = 'NHibernate.Playground'</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p><span style="color:blue;"><font color="#545454">You can see <a href="http://www.castleproject.org/container/facilities/trunk/nhibernate/configref.html">here</a> the XML way to configure NHibernate facility. </font></p>
<p></span></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/varely.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/varely.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/varely.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/varely.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/varely.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/varely.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/varely.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/varely.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/varely.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/varely.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/varely.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/varely.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.caraulean.com&blog=1485392&post=19&subd=varely&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://blog.caraulean.com/2008/05/14/configuring-nhibernateintegration-facility-with-binsor/feed/</wfw:commentRss>
	
		<media:content url="http://www.gravatar.com/avatar/5d96a7814c830eb5ee8e12b677212cae?s=96&#38;d=identicon" medium="image">
			<media:title type="html">varely</media:title>
		</media:content>
	</item>
	</channel>
</rss>