<?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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Calle Arnesten&#039;s Blog</title>
	<atom:link href="http://www.arnesten.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.arnesten.com</link>
	<description>Web Development, Test Driven Development, NHibernate, ASP.NET MVC, jQuery and more..</description>
	<lastBuildDate>Sun, 10 Jan 2010 18:35:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Kostdagbok / matdagbok på dumbbell.se</title>
		<link>http://www.arnesten.com/2010/01/04/kostdagbok-matdagbok-pa-dumbbellse/</link>
		<comments>http://www.arnesten.com/2010/01/04/kostdagbok-matdagbok-pa-dumbbellse/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 08:56:33 +0000</pubDate>
		<dc:creator>Calle Arnesten</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.arnesten.com/?p=34</guid>
		<description><![CDATA[Som jag nämnde för länge sen så har jag en träningssida som heter dumbbell.se. Från början var den enbart till för att föra träningsdagbok, men sen i höstas går det även att ha kostdagbok / matdagbok där. Det går alltså att registrera sin kost i kostdagboken och sen enkelt se statistik. Man ser bland annat [...]]]></description>
			<content:encoded><![CDATA[<p>Som jag <a href="http://www.arnesten.com/2008/10/12/dumbbellse-ar-slappt/">nämnde</a> för länge sen så har jag en träningssida som heter <a href="http://www.dumbbell.se">dumbbell.se</a>. Från början var den enbart till för att föra träningsdagbok, men sen i höstas går det även att ha <a href="http://www.dumbbell.se/demo/kostdagbok-matdagbok">kostdagbok / matdagbok</a> där. </p>
<p>Det går alltså att registrera sin kost i kostdagboken och sen enkelt se statistik. Man ser bland annat hur många kalorier man får i sig och energifördelningen mellan kolhydrater, fett och protein. Dessutom får man en snabb överblick på hur stor mängd vitaminer och mineraler kosten innehåller jämfört med RDI (Rekommenderat Dagligt Intag). </p>
<p>Både <a href="http://www.dumbbell.se/demo/traningsdagbok">träningsdagboken</a> och kostdagboken är helt gratis, så registrera dig gärna och testa.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arnesten.com/2010/01/04/kostdagbok-matdagbok-pa-dumbbellse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting non-public property with type safety (no more strings)</title>
		<link>http://www.arnesten.com/2008/11/30/setting-non-public-property-with-type-safety-no-more-strings/</link>
		<comments>http://www.arnesten.com/2008/11/30/setting-non-public-property-with-type-safety-no-more-strings/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 12:45:53 +0000</pubDate>
		<dc:creator>Calle Arnesten</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.arnesten.com/?p=32</guid>
		<description><![CDATA[Sometimes I have a property where the get-part is public and the set-part is private or protected. Like this: public class Forum { &#160; &#160; public virtual int TopicCount { get; protected set; } &#160; &#160; &#160; // More code... } There can be various reasons for this design. For me it is often when [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes I have a property where the get-part is public and the set-part is private or protected. Like this:</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Forum</span>
<p style="margin: 0px;">{
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">public</span> <span style="color: blue;">virtual</span> <span style="color: blue;">int</span> TopicCount { <span style="color: blue;">get</span>; <span style="color: blue;">protected</span> <span style="color: blue;">set</span>; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: green;">// More code...</span>
<p style="margin: 0px;">}
</div>
</pre>
<p>There can be various reasons for this design. For me it is often when I make database optimizations where I don&#8217;t want to be able to change a property directly in the code, but instead do it directly against the database.</p>
<p>Still, sometimes I want to set the value in unit tests. How do I do that?</p>
<p>Before C# 3.0 I had to rely on having a string with the property name and then use reflection. The main disadvantage with this approach is that if you rename the property you have to make sure that the string is also changed, which is time-consuming and error-prone.</p>
<p>So, with C# 3.0 you no longer need that string. You could use the new Expression-tree feature like this instead:</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">protected</span> <span style="color: blue;">static</span> <span style="color: blue;">void</span> SetProperty&lt;TObj, TValue&gt;(TObj obj, 
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: #2b91af;">Expression</span>&lt;<span style="color: #2b91af;">Func</span>&lt;TObj, TValue&gt;&gt; property, TValue value)
<p style="margin: 0px;">{
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">var</span> propertyInfo = (<span style="color: #2b91af;">PropertyInfo</span>)((<span style="color: #2b91af;">MemberExpression</span>)property.Body).Member;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<p style="margin: 0px;">&nbsp; &nbsp; propertyInfo.SetValue(obj, value, <span style="color: blue;">null</span>);
<p style="margin: 0px;">}
</div>
</pre>
<p>I have placed this method in my BaseTest class, since I only use it in my tests. Now you can write code like this to set the property:</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">var</span> forum = <span style="color: blue;">new</span> <span style="color: #2b91af;">Forum</span>();
<p style="margin: 0px;">SetProperty(forum, f =&gt; f.TopicCount, 2);
</div>
</pre>
<p>This is only a scratch on the surface of what you can accomplish with Expression-trees.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arnesten.com/2008/11/30/setting-non-public-property-with-type-safety-no-more-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing your NHibernate data access code using SQLite</title>
		<link>http://www.arnesten.com/2008/11/25/testing-your-nhibernate-data-access-code-using-sqlite/</link>
		<comments>http://www.arnesten.com/2008/11/25/testing-your-nhibernate-data-access-code-using-sqlite/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 21:28:54 +0000</pubDate>
		<dc:creator>Calle Arnesten</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NHibernate]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.arnesten.com/?p=30</guid>
		<description><![CDATA[Ever since I started working professionally at a software company (which is roughly 3 years ago) I’ve been doing unit testing. I really consider automatic testing one of the most (if not THE most) important trends of software development the last decade. But, despite that, I’ve let code close to the data access be left [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since I started working professionally at a software company (which is roughly 3 years ago) I’ve been doing unit testing. I really consider automatic testing one of the most (if not THE most) important trends of software development the last decade. </p>
<p>But, despite that, I’ve let code close to the data access be left untested. This has been due to the pain I thought it would be to create and maintain those tests. And also I’ve thought that those tests would be way to slow to have among my other unit tests (which we want to be fast, so that we run them often).</p>
<p>For the first two years of my career this was not a big problem. We rarely had bugs in our data access code as it mostly consisted of simple, straight forward code. So I hadn’t really given it much thought. Until lately that is.</p>
<p>Then we started to get performance issues as we got some really large organizations to use or software. To resolve the performance issues we made our data access smarter so it could make more efficient queries to the database. As smarter often means more code, or at least added complexity, I saw the need of automatic tests to guarantee the quality of the code.</p>
<p>So, I read some articles on using SQLite with NHibernate. After some pain setting it all up, I accomplished my goal of easy data access testing. So say that I want to test GetCustomerByName in the following class (in real life I wouldn&#8217;t test methods that are this simple, but it&#8217;s just to show the idea):</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">CustomerDao</span>
<p style="margin: 0px;">{
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">private</span> <span style="color: blue;">readonly</span> <span style="color: #2b91af;">INHibernateManager</span> _sessionManager;
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">public</span> CustomerDao(<span style="color: #2b91af;">INHibernateManager</span> sessionManager)
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; _sessionManager = sessionManager;
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">public</span> <span style="color: #2b91af;">Customer</span> GetCustomerByName(<span style="color: blue;">string</span> name)
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> session = _sessionManager.CurrentSession;
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> session.CreateQuery(<span style="color: #a31515;">&quot;from Customer where Name = :name&quot;</span>)
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .SetParameter(<span style="color: #a31515;">&quot;name&quot;</span>, name)
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .UniqueResult&lt;<span style="color: #2b91af;">Customer</span>&gt;();
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">}
</div>
</pre>
<p>Then I can write a test like this:</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">CustomerDaoTest</span> : <span style="color: #2b91af;">BaseTest</span>
<p style="margin: 0px;">{
<p style="margin: 0px;">&nbsp; &nbsp; [<span style="color: #2b91af;">Test</span>]
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> CanGetCustomerByName()
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; Database.Init();
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> customerA = <span style="color: blue;">new</span> <span style="color: #2b91af;">Customer</span> { Name = <span style="color: #a31515;">&quot;A&quot;</span> };
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> customerB = <span style="color: blue;">new</span> <span style="color: #2b91af;">Customer</span> { Name = <span style="color: #a31515;">&quot;B&quot;</span> };&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; Database.Save(customerA, customerB);&nbsp; &nbsp; &nbsp; &nbsp; 
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> customerDao = <span style="color: blue;">new</span> <span style="color: #2b91af;">CustomerDao</span>(Database);
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> result = customerDao.GetCustomerByName(<span style="color: #a31515;">&quot;B&quot;</span>);
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2b91af;">Assert</span>.That(result, <span style="color: #2b91af;">Is</span>.EqualTo(customerB));
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">}
</div>
</pre>
<p>For this to work I have a class called TestDatabase with the following code:</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">TestDatabase</span> : <span style="color: #2b91af;">INHibernateManager</span>
<p style="margin: 0px;">{
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">ISessionFactory</span> m_sessionFactory;&nbsp; &nbsp; &nbsp; &nbsp; 
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">SchemaExport</span> SchemaExport;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">private</span> <span style="color: #2b91af;">ISession</span> m_session;
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Init()
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">if</span> (m_sessionFactory == <span style="color: blue;">null</span>)
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2b91af;">Configuration</span> config = CreateNHibernateConfig();
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_sessionFactory = config.BuildSessionFactory();
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SchemaExport = <span style="color: blue;">new</span> <span style="color: #2b91af;">SchemaExport</span>(config);
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">if</span> (m_session != <span style="color: blue;">null</span>)
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; m_session.Close();
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; m_session = m_sessionFactory.OpenSession();
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; m_session.BeginTransaction();
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> connection = m_session.Connection;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; SchemaExport.Execute(<span style="color: blue;">false</span>, <span style="color: blue;">true</span>, <span style="color: blue;">false</span>, <span style="color: blue;">false</span>, connection, <span style="color: blue;">null</span>);
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">Configuration</span> CreateNHibernateConfig()
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2b91af;">Configuration</span> config = <span style="color: blue;">new</span> <span style="color: #2b91af;">Configuration</span>();
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; config.Properties.Clear();
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; config.SetProperty(<span style="color: #a31515;">&quot;hibernate.connection.driver_class&quot;</span>, 
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a31515;">&quot;NHibernate.Driver.SQLite20Driver&quot;</span>);
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; config.SetProperty(<span style="color: #a31515;">&quot;hibernate.dialect&quot;</span>, <span style="color: #a31515;">&quot;NHibernate.Dialect.SQLiteDialect&quot;</span>);
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; config.SetProperty(<span style="color: #a31515;">&quot;hibernate.connection.connection_string&quot;</span>, 
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #a31515;">&quot;Data Source=:memory:;Version=3;New=True;&quot;</span>);
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; config.SetProperty(<span style="color: #a31515;">&quot;hibernate.cache.use_second_level_cache&quot;</span>, <span style="color: #a31515;">&quot;false&quot;</span>);
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; config.SetProperty(<span style="color: #a31515;">&quot;hibernate.hbm2ddl.auto&quot;</span>, <span style="color: #a31515;">&quot;create&quot;</span>);
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; config.AddAssembly(<span style="color: #a31515;">&quot;MyAssembly&quot;</span>); <span style="color: green;">// Change this to your assembly</span>
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> config;
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">public</span> <span style="color: #2b91af;">ISession</span> Session
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">get</span> { <span style="color: blue;">return</span> m_session; }
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">public</span> <span style="color: blue;">void</span> Save(<span style="color: blue;">params</span> <span style="color: blue;">object</span>[] entities)
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">foreach</span> (<span style="color: blue;">var</span> entity <span style="color: blue;">in</span> entities)
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Session.Save(entity);
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; Session.Flush();
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: #2b91af;">ISession</span> <span style="color: #2b91af;">INHibernateManager</span>.CurrentSession
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">get</span> { <span style="color: blue;">return</span> m_session; }
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">}
</div>
</pre>
<p>And I’ve also added the following field to my BaseTest class:</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;">[<span style="color: #2b91af;">TestFixture</span>]
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">BaseTest</span>
<p style="margin: 0px;">{
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">protected</span> <span style="color: blue;">readonly</span> <span style="color: #2b91af;">TestDatabase</span> Database = <span style="color: blue;">new</span> <span style="color: #2b91af;">TestDatabase</span>();
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: green;">// More code here...</span>
<p style="margin: 0px;">}
</div>
</pre>
<p>So, in summary, I&#8217;ve shown a pretty easy way of doing database testing. Even though the method under test was really simple in the example, the same technique could be used for much more complex scenarios.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arnesten.com/2008/11/25/testing-your-nhibernate-data-access-code-using-sqlite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Home from Öredev 2008</title>
		<link>http://www.arnesten.com/2008/11/23/home-from-oredev-2008/</link>
		<comments>http://www.arnesten.com/2008/11/23/home-from-oredev-2008/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 18:31:41 +0000</pubDate>
		<dc:creator>Calle Arnesten</dc:creator>
				<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://www.arnesten.com/?p=26</guid>
		<description><![CDATA[Friday night I came home from Öredev, a 3 day conference in Malmö. Overall, a great experience which has made me and the team I work with inspired. The following are the most interesting experiences that I will take with me: The Power of Value by Dan Bergh Johnsson. One of the best sessions of [...]]]></description>
			<content:encoded><![CDATA[<p>Friday night I came home from <a href="http://www.oredev.se">Öredev</a>, a 3 day conference in Malmö. Overall, a great experience which has made me and the team I work with inspired.</p>
<p>The following are the most interesting experiences that I will take with me:</p>
<ul>
<li><b>The Power of Value by Dan Bergh Johnsson</b>. One of the best sessions of Öredev. An eye-opener for what value objects can do. A value object is an immutable object where you are not interested in tracking its identity. I will now begin to think more of this when developing.
</li>
<li><b>Agile Architecture by James Coplien</b>. James Coplien was a strange and arrogant person, for example claiming that he was 1 of 15 in the world who really understood object-orientation. But his ideas how architecture should be was really, really interesting. I think he is on to something with his gluing of Methodful Roles, Identifiers and Methodless Roles onto simple classes. Will definitely need to study this more as I only got a vague understanding of it.
</li>
<li><b>Clean Code by Robert C. Martin</b>. Uncle Bob (as he is also called) made two inspiring talks: the keynote and Clean Code III. I&#8217;ve had the pleasure of seeing him before at <a href="http://www.arnesten.com/2007/09/30/jaoo-2007-%e2%80%93-tdd-tutorial-with-robert-c-martin/">JAOO 2007</a>, but despite that got more tips for writing good code. The rest of the team I work with, were also inspired, so we will try to enforce a clean code policy at work.
</li>
<li><b>The Pomodoro Technique by Staffan Nöteberg</b>. Staffan was a good speaker, using dolls and hats to make the speech fun. The Pomodoro technique is a process for improving one&#8217;s personal work. It&#8217;s main idea is to only be allowed to focus on one thing at a time. Will try this soon, both at work and at home.
</li>
<li><b>The Lean thinking</b>. Lean was mentioned by many speakers, Scott Bellware and James Coplien for example. It seems to be the new buzzword. I need to check up more on this, but I think I got the basic idea of it at least. Which is produce more value and eliminate waste.
</li>
<li><b>Behaviour Driven Design</b>. Got some ideas in this area from various sessions. MSpec as a framework looks interesting, especially the HTML-reports it can generate. AutoHotkey seems like a good utility for writing underscores more efficiently. Will start to use BDD-style both at work and at home.
</li>
<li><b>T-person</b>. Was mentioned by Scott Bellware. It basically is a person which is good at other things than his main speciality. Like a developer that also is skilled at design and testing. Then he can help in both of those areas if needed and also his understanding will make hand-offs smoother.
</li>
<li><b>Design Debt</b>. Got a good scetch model to illustrate how design debt works for people that don&#8217;t understand it (like managers).
</li>
</ul>
<p>I learned many more things during the conference, but I have to stop now. Probably there will be more posts later on as I try out some of the new ideas I&#8217;ve got.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arnesten.com/2008/11/23/home-from-oredev-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AutoStub parameters using Rhino Mocks</title>
		<link>http://www.arnesten.com/2008/11/16/autostub-parameters-using-rhino-mocks/</link>
		<comments>http://www.arnesten.com/2008/11/16/autostub-parameters-using-rhino-mocks/#comments</comments>
		<pubDate>Sun, 16 Nov 2008 19:46:49 +0000</pubDate>
		<dc:creator>Calle Arnesten</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Rhino Mocks]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.arnesten.com/2008/11/16/autostub-parameters-using-rhino-mocks/</guid>
		<description><![CDATA[For the last years I’ve been using dependency injection for my service classes. More recently (by the introduction of ASP.NET MVC) that have also been the case for my controller classes. I take in their dependencies via the constructor and then let a Dependency Injection/Inversion of Control (DI/IoC) framework automatically resolve and create the classes. [...]]]></description>
			<content:encoded><![CDATA[<p>For the last years I’ve been using dependency injection for my service classes. More recently (by the introduction of ASP.NET MVC) that have also been the case for my controller classes. I take in their dependencies via the constructor and then let a Dependency Injection/Inversion of Control (DI/IoC) framework automatically resolve and create the classes. I’ve been using Castle Windsor for this, which has worked really well.</p>
<p>However, when it comes to testing service/controller classes, I’ve previously created (often stubbed) the parameters needed when testing, and then given them manually to the constructor. Like this:</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">var</span> customerDao = Stub&lt;<span style="color: #2b91af;">OrderDao</span>&gt;();
<p style="margin: 0px;"><span style="color: blue;">var</span> orderDao = Stub&lt;<span style="color: #2b91af;">OrderDao</span>&gt;();
<p style="margin: 0px;"><span style="color: blue;">var</span> controller = <span style="color: blue;">new</span> <span style="color: #2b91af;">CustomerController</span>(customerDao, orderDao);
</div>
</pre>
<p>This has proven to be quite fragile as the dependencies to the service/controller class has changed. Often, the case has been that more dependencies have been added as parameters to the constructor. I know, I know, that might be a code smell that the service/controller should be split into smaller classes… But anyway, code smell or not, the fragility of the tests is a problem.</p>
<p>A while back I read about an AutoMocking container, but thought it was a bit cumbersome to have to use both a Mocking framework and a DI/IoC container in my tests. So, I thought that this should be possibly to accomplish with only a mocking framework and a bit of reflection magic. And it actually turned out to be really easy to do.</p>
<p>As a mocking framework I use Rhino Mocks (btw, I love the new AAA syntax in 3.5!). All my test inherit from a class called BaseTest, which is where I decided to put the autostubbing. The code comes here:</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;">[<span style="color: #2b91af;">TestFixture</span>]
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">BaseTest</span>
<p style="margin: 0px;">{
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">protected</span> <span style="color: blue;">static</span> T Stub&lt;T&gt;(<span style="color: blue;">params</span> <span style="color: blue;">object</span>[] parameters) <span style="color: blue;">where</span> T : <span style="color: blue;">class</span>
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> <span style="color: #2b91af;">MockRepository</span>.GenerateStub&lt;T&gt;(parameters);
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">protected</span> <span style="color: blue;">static</span> T Mock&lt;T&gt;(<span style="color: blue;">params</span> <span style="color: blue;">object</span>[] parameters) <span style="color: blue;">where</span> T : <span style="color: blue;">class</span>
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> <span style="color: #2b91af;">MockRepository</span>.GenerateMock&lt;T&gt;(parameters);
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">protected</span> <span style="color: blue;">static</span> T CreateAndAutoStubParameters&lt;T&gt;(<span style="color: blue;">params</span> <span style="color: blue;">object</span>[] parameters)
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> (T)CreateAndAutoStubParameters(<span style="color: blue;">typeof</span>(T), parameters);
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">protected</span> <span style="color: blue;">static</span> <span style="color: blue;">object</span> CreateAndAutoStubParameters(<span style="color: #2b91af;">Type</span> type, 
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">params</span> <span style="color: blue;">object</span>[] parameters)
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> constructor = type.GetConstructors(
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2b91af;">BindingFlags</span>.Public | <span style="color: #2b91af;">BindingFlags</span>.Instance)[0];
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> parameterInfos = constructor.GetParameters();
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> constructorParams = GetConstructorParameters(
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parameterInfos, parameters);
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> constructor.Invoke(constructorParams.ToArray());
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: #2b91af;">List</span>&lt;<span style="color: blue;">object</span>&gt; GetConstructorParameters(<span style="color: #2b91af;">ParameterInfo</span>[] parameterInfos, 
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">params</span> <span style="color: blue;">object</span>[] parameters)
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> constructorParams = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span>&lt;<span style="color: blue;">object</span>&gt;();
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">foreach</span> (<span style="color: blue;">var</span> info <span style="color: blue;">in</span> parameterInfos)
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; constructorParams.Add(GetParameter(info, parameters));
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> constructorParams;
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">private</span> <span style="color: blue;">static</span> <span style="color: blue;">object</span> GetParameter(<span style="color: #2b91af;">ParameterInfo</span> info, 
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">object</span>[] candidateParameters)
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">foreach</span> (<span style="color: blue;">var</span> candidate <span style="color: blue;">in</span> candidateParameters)
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">if</span> (info.ParameterType.IsAssignableFrom(candidate.GetType()))
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> candidate;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> AutoStub(info.ParameterType);
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">protected</span> <span style="color: blue;">static</span> T AutoStub&lt;T&gt;() <span style="color: blue;">where</span> T : <span style="color: blue;">class</span>
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> (T)AutoStub(<span style="color: blue;">typeof</span>(T));
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">protected</span> <span style="color: blue;">static</span> <span style="color: blue;">object</span> AutoStub(<span style="color: #2b91af;">Type</span> type)
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">if</span> (type.IsInterface)
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> <span style="color: #2b91af;">MockRepository</span>.GenerateStub(type);
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> constructor = type.GetConstructors(
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #2b91af;">BindingFlags</span>.Public | <span style="color: #2b91af;">BindingFlags</span>.Instance)[0];
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> parameterInfos = constructor.GetParameters();
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">var</span> constructorParams = GetConstructorParameters(parameterInfos);
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: blue;">return</span> <span style="color: #2b91af;">MockRepository</span>.GenerateStub(type, constructorParams.ToArray());
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">}
</div>
</pre>
<p>So, now let us assume you want to test a CustomerController with dependencies like this:</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">public</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">CustomerController</span>
<p style="margin: 0px;">{
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: blue;">public</span> CustomerController(<span style="color: #2b91af;">CustomerDao</span> customerDao, <span style="color: #2b91af;">OrderDao</span> orderDao)
<p style="margin: 0px;">&nbsp; &nbsp; {
<p style="margin: 0px;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: green;">// Code here..</span>
<p style="margin: 0px;">&nbsp; &nbsp; }
<p style="margin: 0px;">&nbsp;
<p style="margin: 0px;">&nbsp; &nbsp; <span style="color: green;">// Code here..</span>
<p style="margin: 0px;">}
</div>
</pre>
<p>Then you only have to write this:</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">var</span> controller = CreateAndAutoStubParameters&lt;<span style="color: #2b91af;">CustomerController</span>&gt;();
</div>
</pre>
<p>to create the controller with stubs automatically created as constructor parameters.<br />
Often, you might want to have some control over one of the parameters, and then you could write like this:</p>
<pre class="csharpcode">
<div style="font-family: Courier New; font-size: 8pt; color: black; background: white;">
<p style="margin: 0px;"><span style="color: blue;">var</span> customerDao = AutoStub&lt;<span style="color: #2b91af;">CustomerDao</span>&gt;();
<p style="margin: 0px;">customerDao.Stub(c =&gt; c.GetById(1)).Return(<span style="color: blue;">new</span> <span style="color: #2b91af;">Customer</span>());
<p style="margin: 0px;"><span style="color: blue;">var</span> controller = CreateAndAutoStubParameters&lt;<span style="color: #2b91af;">CustomerController</span>&gt;(customerDao);
</div>
</pre>
<p>This way of testing service and controller classes has removed some of the pain of starting to test classes with dependencies that need to be mocked or stubbed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arnesten.com/2008/11/16/autostub-parameters-using-rhino-mocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dumbbell.se är släppt</title>
		<link>http://www.arnesten.com/2008/10/12/dumbbellse-ar-slappt/</link>
		<comments>http://www.arnesten.com/2008/10/12/dumbbellse-ar-slappt/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 16:00:50 +0000</pubDate>
		<dc:creator>Calle Arnesten</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://www.arnesten.com/2008/10/12/dumbbellse-ar-slappt/</guid>
		<description><![CDATA[Igår la jag upp www.dumbbell.se för allmänheten. Dumbbell.se är en träningscommunity där man kan mata in sina träningspass, se statistik hur man utvecklas och diskutera med andra träningsintresserade människor. Siten kommer byggas ut gradvis närmsta tiden. Rent tekniskt så har jag använt mig av ASP.NET MVC, NHibernate och jQuery i en härlig symbios :) Jag [...]]]></description>
			<content:encoded><![CDATA[<p>Igår la jag upp <a href="http://www.dumbbell.se">www.dumbbell.se</a> för allmänheten. Dumbbell.se är en träningscommunity där man kan mata in sina träningspass, se statistik hur man utvecklas och diskutera med andra träningsintresserade människor. Siten kommer byggas ut gradvis närmsta tiden.</p>
<p>Rent tekniskt så har jag använt mig av ASP.NET MVC, NHibernate och jQuery i en härlig symbios :)</p>
<p>Jag kommer troligtvis skriva fler inlägg om dumbbell.se här i framtiden, men detta får vara tillräckligt för stunden.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arnesten.com/2008/10/12/dumbbellse-ar-slappt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Validating HTTP method in ASP.NET MVC</title>
		<link>http://www.arnesten.com/2008/07/10/validating-http-method-in-aspnet-mvc/</link>
		<comments>http://www.arnesten.com/2008/07/10/validating-http-method-in-aspnet-mvc/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 09:29:11 +0000</pubDate>
		<dc:creator>Calle Arnesten</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://www.arnesten.com/2008/07/10/validating-http-method-in-aspnet-mvc/</guid>
		<description><![CDATA[On the web it&#8217;s considered a good practice that the GET method never changes the state on the server. When state should be changed the POST method should be used. It is good to follow this practice, otherwise there might be problems when search engines tries to visit links (which are GET by default). By [...]]]></description>
			<content:encoded><![CDATA[<p>On the web it&#8217;s considered a good practice that the GET method never changes the state on the server. When state should be changed the POST method should be used. It is good to follow this practice, otherwise there might be problems when search engines tries to visit links (which are GET by default).<br />
By default in ASP.NET MVC any public method on the controller can be accessed both by GET and POST. So I _could_ access my DeleteUser() method by an ordinary link (which is GET). </p>
<p>So, how do I restrict a method in ASP.NET MVC to be only GET or only POST? I could use ActionFilterAttribute and tag each method with it. But tagging every method is a bit noisy in my opinion. The thing I want is GET to be the default way to access methods, and then I want to mark POST methods only with attributes.</p>
<p>In my MVC projects I always have a BaseController, that all my controllers inherit from. With that in place it is actually quite easy to accomplish the above. I just need to override OnActionExecuting like this:</p>
<pre class="csharpcode">
<span class="kwrd">public</span> <span class="kwrd">class</span> BaseController : Controller
{
    <span class="kwrd">protected</span> <span class="kwrd">override</span> <span class="kwrd">void</span> OnActionExecuting(ActionExecutingContext filterContext)
    {
        var attributes = filterContext.ActionMethod.GetCustomAttributes(
            <span class="kwrd">typeof</span>(POSTAttribute), <span class="kwrd">false</span>);
        var method = filterContext.HttpContext.Request.HttpMethod;
        <span class="kwrd">if</span> (attributes.Length &gt; 0 &amp;&amp; method != <span class="str">"POST"</span>)
        {
            ThrowIllegalMethodException(<span class="str">"POST"</span>, filterContext);
        }
        <span class="kwrd">else</span> <span class="kwrd">if</span> (attributes.Length == 0 &amp;&amp; method != <span class="str">"GET"</span>)
        {
            ThrowIllegalMethodException(<span class="str">"GET"</span>, filterContext);
        }
    }

    <span class="kwrd">private</span> <span class="kwrd">static</span> <span class="kwrd">void</span> ThrowIllegalMethodException(<span class="kwrd">string</span> expectedHttpMethod,
        ActionExecutingContext filterContext)
    {
        var controllerName = filterContext.Controller.GetType().Name;
        var controllerMethod = filterContext.ActionMethod.Name;
        var httpMethod = filterContext.HttpContext.Request.HttpMethod;

        var message = <span class="kwrd">string</span>.Format(<span class="str">"Only {0} method allowed for {1}.{2}, but {3} was used."</span>,
            expectedHttpMethod, controllerName, controllerMethod, httpMethod);
        <span class="kwrd">throw</span> <span class="kwrd">new</span> SecurityException(message);
    }
}</pre>
<p>And also I need a POSTAttribute which is simplest possible:</p>
<pre class="csharpcode">
<span class="kwrd">public</span> <span class="kwrd">class</span> POSTAttribute : Attribute
{
}</pre>
<p>So, now I can write [POST] above methods like this: </p>
<pre class="csharpcode">
<span class="kwrd">public</span> <span class="kwrd">class</span> MyController : BaseController
{
    [POST]
    <span class="kwrd">public</span> ActionResult SaveMyEntity()
    {
        <span class="rem">// Code..</span>
    }
}</pre>
<p>Pretty cool that you can change the behaviour of the MVC framework this easy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arnesten.com/2008/07/10/validating-http-method-in-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Model View Controller from Microsoft</title>
		<link>http://www.arnesten.com/2007/10/06/model-view-controller-from-microsoft/</link>
		<comments>http://www.arnesten.com/2007/10/06/model-view-controller-from-microsoft/#comments</comments>
		<pubDate>Sat, 06 Oct 2007 21:31:59 +0000</pubDate>
		<dc:creator>Calle Arnesten</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://www.arnesten.com/2007/10/06/model-view-controller-from-microsoft/</guid>
		<description><![CDATA[Just read this. This is great news! I don&#8217;t like the way WebForms work today, I think its hard to get testable code close to the UI. I know there are alternatives like MonoRail, but I find the disadvantage of not having third party components like Telerik too big. But if a framework for Model [...]]]></description>
			<content:encoded><![CDATA[<p>Just read <a href="http://igloocoder.com/archive/2007/10/06/alt.net-day-2-session-3----ms-mvc-preview.aspx">this</a>. This is great news! I don&#8217;t like the way WebForms work today, I think its hard to get testable code close to the UI. I know there are alternatives like <a href="http://www.castleproject.org/monorail/">MonoRail</a>, but I find the disadvantage of not having third party components like <a href="http://www.telerik.com">Telerik</a> too big. But if a framework for Model View Controller comes from Microsoft, I&#8217;m sure that third party component companies will start develop components for it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arnesten.com/2007/10/06/model-view-controller-from-microsoft/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAOO 2007 – TDD tutorial with Robert C. Martin</title>
		<link>http://www.arnesten.com/2007/09/30/jaoo-2007-%e2%80%93-tdd-tutorial-with-robert-c-martin/</link>
		<comments>http://www.arnesten.com/2007/09/30/jaoo-2007-%e2%80%93-tdd-tutorial-with-robert-c-martin/#comments</comments>
		<pubDate>Sun, 30 Sep 2007 20:50:39 +0000</pubDate>
		<dc:creator>Calle Arnesten</dc:creator>
				<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.arnesten.com/2007/09/30/jaoo-2007-%e2%80%93-tdd-tutorial-with-robert-c-martin/</guid>
		<description><![CDATA[I arrived yesterday to Aarhus in Denmark for the ongoing JAOO conference. I’m here for two tutorials, one about Test-driven development (TDD) which I went to today, and one about domain-driven development (DDD) which I will visit tomorrow. The TDD tutuorial was held by Robert C. Martin, also called Uncle Bob, whom have written a [...]]]></description>
			<content:encoded><![CDATA[<p>I arrived yesterday to Aarhus in Denmark for the ongoing JAOO conference. I’m here for two tutorials, one about Test-driven development (TDD) which I went to today, and one about domain-driven development (DDD) which I will visit tomorrow.</p>
<p>The TDD tutuorial was held by <a href="http://www.objectmentor.com/omTeam/martin_r.html">Robert C. Martin</a>, also called Uncle Bob, whom have written a couple of books (none of which I have read yet, unfortunately). I found Robert to be charismatic, loud-mouthed (not in a negative way) and generally a funny guy. </p>
<p>The tutorial begun with a short introduction of TDD and then went on with a presentation of the requirements to a game called “Hunt the Wumpus” (wtf is a Wumpus?!). The requirements were written in a tool called <a href="http://www.fitnesse.org">FitNesse</a>. FitNesse is a popular tool for writing what is called acceptance tests. These acceptance tests should non-programmers, typically QA or management people, be able to write. </p>
<p>After the introduction we were given an incomplete implementation of the game, along with a lot of acceptance tests which didn’t pass. Our objective was to use TDD and write code to make the acceptance tests pass. Every change we made to the game code had to be as an effect of creating a unit test that failed.</p>
<p>I’ve personally been writing unit tests for two years now, but haven’t done any real TDD until very recently. So I’m still in the process of re-learning the way to write code. In TDD you should <b>“Write the test that force you write the code you want”</b> as Robert so elegantly put it. More formally there are three rules of TDD which are:</p>
<ol>
<li>You are not allowed to write any production code unless it is to make a failing unit test pass.</li>
<li>You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.</li>
<li>You are not allowed to write any more production code than is sufficient to pass the one failing unit test.</li>
</ol>
<p>If you practice TDD properly you should, accordingly to Robert, produce <b>more than 1000 unit tests per year</b>. That is a lot more than what I’ve produced my last year! And then I actually thought that I had been writing a lot of tests.. But when you think about it, it’s not really an unreasonable amount. Knock it out over a year and it’s just about 4 tests per day. Now it didn’t sound so much, did it?</p>
<p>Throughout the day, Robert interrupted regularly to ask the audience questions and share his opinions about difference aspects of software development. I will present some of the nuggets here:</p>
<p><b>“Comments are dirt in code”</b>. My favourite! What he means is that most of the time comments in code try to make up for poor design. If the design was really good, the comments wouldn’t be needed. I really agree with this reasoning when it regards that comments shouldn’t be needed inside code blocks. However, public comments that clarifies, for example what state a parameter must have (not null is common), I still think are needed sometimes, especially for APIs where you don’t have access to the source code.</p>
<p><b>“Implement new functionality in priority order, not what is convenient from a design point-of-view”</b>. This sentence stuck since we’ve been discussing this lately at the company I work for. The reasoning behind it (besides the obvious point that high priorities are more important than low priorites) is that the design should be refactored continually so that the best possibly design will emerge independently of the order that the tasks are implemented.</p>
<p>He also gave so guidelines of method design. <b>A well-designed method should:</b></p>
<ul>
<li>not be longer than 5 lines of code</li>
<li>not have indentation depth (like for and if statements) of more than 2</li>
<li>not have more than 2-3 parameters</li>
</ul>
<p>Personally, I&#8217;m not quite there yet when it comes to the first two statements. I try to make my methods short, but sometimes they are up to 30 lines of code.. And my indentation depth often goes up to three or sometimes even four.</p>
<p>At the end of the tutorial, there was time for reflections of working with TDD and a question from the audience was that they had gotten redundancies where some unit tests were almost identical as some of the acceptance tests. This was okay, according to Robert.</p>
<p>On the negative side I don&#8217;t have much to say.. Perhaps only that he at one time used exception handling for taking care of bad user input from the command line. In my book*, exception handling should only be used for exceptional events, not such a common case as when a user misspells a command..</p>
<p>All in all, I found the tutorial very giving and inspirational. How much the tutorial will affect my development process, I don&#8217;t know yet.. But I think I&#8217;ve gotten enough knowledge and energy to really start doing real test-driven development from now on. It will be fun to reflect upon this in a couple of weeks.</p>
<p>* No, I haven’t written any books. I mean the figure of speech.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arnesten.com/2007/09/30/jaoo-2007-%e2%80%93-tdd-tutorial-with-robert-c-martin/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using NHibernate 1.2 with Cuyahoga</title>
		<link>http://www.arnesten.com/2007/05/25/using-nhibernate-12-with-cuyahoga/</link>
		<comments>http://www.arnesten.com/2007/05/25/using-nhibernate-12-with-cuyahoga/#comments</comments>
		<pubDate>Fri, 25 May 2007 15:20:55 +0000</pubDate>
		<dc:creator>Calle Arnesten</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Cuyahoga]]></category>
		<category><![CDATA[NHibernate]]></category>

		<guid isPermaLink="false">http://www.arnesten.com/2007/05/25/using-nhibernate-12-with-cuyahoga/</guid>
		<description><![CDATA[One of the things I missed when I started to look at Cuyahoga two weeks ago was that it didn&#8217;t use NHibernate 1.2. As I was used to NHibernate 1.2 from my work with its support for generics, I wanted to use that with Cuyahoga as well. So I decided to make a patch that [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I missed when I started to look at Cuyahoga two weeks ago was that it didn&#8217;t use NHibernate 1.2. As I was used to NHibernate 1.2 from my work with its support for generics, I wanted to use that with Cuyahoga as well. So I decided to make a patch that would enable me to use it.</p>
<p>Besides using the files from the NHibernate 1.2 release, I had to download the subversion source code for Castle.Facilities.NHibernateIntegration.dll. Then I had to make a few adjustments to the code for it to compile against NHibernate 1.2.</p>
<p>After I had upgraded the dll&#8217;s, the Cuyahoga compiled. But when I run it NHibernate complained on some things like missing virtuals and wrong mapping scheme (urn:nhibernate-mapping-2.0 instead of urn:nhibernate-mapping-2.2). After that it seems to be working nice.</p>
<p>You can download the patch for Cuyahoga 1.5 source code <a href='http://www.arnesten.com/wordpress/wp-content/patch-cuyahoga-150-nhibernate-12.zip' title='Patch-Cuyahoga-1.5.0-NHibernate 1.2.zip'>here.</a> And for Cuyahoga&#8217;s latest trunk <a href='http://www.arnesten.com/wordpress/wp-content/patch-cuyahoga-trunk-nhibernate-12.zip' title='Patch-Cuyahoga-trunk-NHibernate-1.2.zip'>here</a>. </p>
<p>Unfortunately, I&#8217;ve been having some problem applying the entire patches. It complains about some strange character in the beginning of some of the repository files, so you might have to manually edit some files. (The patch file is actually quite human-readable so it can be of help in the manual process). But for those that start from scratch I&#8217;ve also created a ready package of Cuyahoga 1.5 with patch applied. Download it <a href='http://www.arnesten.com/wordpress/wp-content/cuyahoga-150-with-nhibernate-12.zip' title='Cuyahoga-1.5.0-with-NHibernate-1.2.zip'>here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.arnesten.com/2007/05/25/using-nhibernate-12-with-cuyahoga/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

