<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Unit Testing Simple ASP.NET MVC Controllers</title>
	<atom:link href="http://lostechies.com/chrismissal/2010/02/05/unit-testing-simple-asp-net-mvc-controllers/feed/" rel="self" type="application/rss+xml" />
	<link>http://lostechies.com/chrismissal/2010/02/05/unit-testing-simple-asp-net-mvc-controllers/</link>
	<description>Thoughts while working and playing as a Software Developer</description>
	<lastBuildDate>Thu, 11 Apr 2013 16:53:00 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
	<item>
		<title>By: Lakeview Personal Trainer</title>
		<link>http://lostechies.com/chrismissal/2010/02/05/unit-testing-simple-asp-net-mvc-controllers/#comment-324</link>
		<dc:creator>Lakeview Personal Trainer</dc:creator>
		<pubDate>Mon, 27 Feb 2012 08:12:00 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chrismissal/archive/2010/02/05/unit-testing-simple-asp-net-mvc-controllers.aspx#comment-324</guid>
		<description>Good news.This is a great post. I like this topic.This site has lots of advantage.
I found many interesting things from this site. It helps me many away.</description>
		<content:encoded><![CDATA[<p>Good news.This is a great post. I like this topic.This site has lots of advantage.<br />
I found many interesting things from this site. It helps me many away.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MVC developr</title>
		<link>http://lostechies.com/chrismissal/2010/02/05/unit-testing-simple-asp-net-mvc-controllers/#comment-162</link>
		<dc:creator>MVC developr</dc:creator>
		<pubDate>Sat, 27 Nov 2010 11:24:47 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chrismissal/archive/2010/02/05/unit-testing-simple-asp-net-mvc-controllers.aspx#comment-162</guid>
		<description>Hey, i found this after some digging around
http://kbochevski.blogspot.com/2010/06/unit-testing-mvcnet.html
My colleagues found this very helpful too. It covers all the layers with unit testing and uses Rhino and MVC contrib, The source code is a good start for beginners like me</description>
		<content:encoded><![CDATA[<p>Hey, i found this after some digging around<br />
<a href="http://kbochevski.blogspot.com/2010/06/unit-testing-mvcnet.html" rel="nofollow">http://kbochevski.blogspot.com/2010/06/unit-testing-mvcnet.html</a><br />
My colleagues found this very helpful too. It covers all the layers with unit testing and uses Rhino and MVC contrib, The source code is a good start for beginners like me</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Klaus Hebsgaard</title>
		<link>http://lostechies.com/chrismissal/2010/02/05/unit-testing-simple-asp-net-mvc-controllers/#comment-161</link>
		<dc:creator>Klaus Hebsgaard</dc:creator>
		<pubDate>Mon, 15 Feb 2010 19:56:04 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chrismissal/archive/2010/02/05/unit-testing-simple-asp-net-mvc-controllers.aspx#comment-161</guid>
		<description>I have found that using the testdata builder pattern works great for controllers.
I would create the controller in a test data builder class, in a fluent like style, like:
 var controller = new AdminControllerTestDataBuilder()
.WithSimpleFacilityrepository()
.WithMeetingRepository()
.withXYZ()
.Build();

And then I could insert instances where needed using :
WithFacilityrepository(facilityRepository.Object)</description>
		<content:encoded><![CDATA[<p>I have found that using the testdata builder pattern works great for controllers.<br />
I would create the controller in a test data builder class, in a fluent like style, like:<br />
 var controller = new AdminControllerTestDataBuilder()<br />
.WithSimpleFacilityrepository()<br />
.WithMeetingRepository()<br />
.withXYZ()<br />
.Build();</p>
<p>And then I could insert instances where needed using :<br />
WithFacilityrepository(facilityRepository.Object)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sukant Hajra</title>
		<link>http://lostechies.com/chrismissal/2010/02/05/unit-testing-simple-asp-net-mvc-controllers/#comment-160</link>
		<dc:creator>Sukant Hajra</dc:creator>
		<pubDate>Wed, 10 Feb 2010 19:07:45 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chrismissal/archive/2010/02/05/unit-testing-simple-asp-net-mvc-controllers.aspx#comment-160</guid>
		<description>the way you&#039;re doing Arrange-Act-Assert is pretty much the same as how I&#039;ve been doing Given-When-Then in unit tests (without BDD-framework bloat)</description>
		<content:encoded><![CDATA[<p>the way you&#8217;re doing Arrange-Act-Assert is pretty much the same as how I&#8217;ve been doing Given-When-Then in unit tests (without BDD-framework bloat)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wes</title>
		<link>http://lostechies.com/chrismissal/2010/02/05/unit-testing-simple-asp-net-mvc-controllers/#comment-159</link>
		<dc:creator>Wes</dc:creator>
		<pubDate>Fri, 05 Feb 2010 21:13:13 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chrismissal/archive/2010/02/05/unit-testing-simple-asp-net-mvc-controllers.aspx#comment-159</guid>
		<description>This type of controller approach tends to work as a service layer in an application (when concerns are properly separated).  In this case the controller is bringing together repositories and a user session which are components of the domain.

Mock based testing of service layers is often tedious and fragile as the tests duplicate the code in the service layer, any change to that code requires a change to the tests to make them pass.  I constantly ran into this problem when mocking service layers or worse when I left domain logic in service layers. 

Time has shown that focusing on invariants (state based testing), is the best way, at least for me, to do testing.  In the case of a service layer, the invariants revolve around integrating components and as such testing should be from the integration perspective instead of a unit.  If I find myself excessively mocking/stubbing in a service layer, it is often a smell that I have domain logic to extract (fat service calls).  This helps maximize the testing surface of domain logic.

I usually work with a smoke test of the integration components to avoid duplicating the unit tests of the components it brings together.  This allows the underlying component architecture to change, so long as the service still fulfills the same invariant.

In this example, a good smoke test for a controller action to add an item might be to check if it exists in the repository after the call.  The repository would be stubbed instead of mocked, with an in memory version or a real database.

Another problem that frequently occurs with mock testing is the ignoring of argument values.  These are important if our tests solely rely on the interaction of components instead of the invariants.  In the example above, any Meeting object could have been added to the repository and the test would pass.

Just some thoughts on the pain points we&#039;ve experienced with different testing strategies.</description>
		<content:encoded><![CDATA[<p>This type of controller approach tends to work as a service layer in an application (when concerns are properly separated).  In this case the controller is bringing together repositories and a user session which are components of the domain.</p>
<p>Mock based testing of service layers is often tedious and fragile as the tests duplicate the code in the service layer, any change to that code requires a change to the tests to make them pass.  I constantly ran into this problem when mocking service layers or worse when I left domain logic in service layers. </p>
<p>Time has shown that focusing on invariants (state based testing), is the best way, at least for me, to do testing.  In the case of a service layer, the invariants revolve around integrating components and as such testing should be from the integration perspective instead of a unit.  If I find myself excessively mocking/stubbing in a service layer, it is often a smell that I have domain logic to extract (fat service calls).  This helps maximize the testing surface of domain logic.</p>
<p>I usually work with a smoke test of the integration components to avoid duplicating the unit tests of the components it brings together.  This allows the underlying component architecture to change, so long as the service still fulfills the same invariant.</p>
<p>In this example, a good smoke test for a controller action to add an item might be to check if it exists in the repository after the call.  The repository would be stubbed instead of mocked, with an in memory version or a real database.</p>
<p>Another problem that frequently occurs with mock testing is the ignoring of argument values.  These are important if our tests solely rely on the interaction of components instead of the invariants.  In the example above, any Meeting object could have been added to the repository and the test would pass.</p>
<p>Just some thoughts on the pain points we&#8217;ve experienced with different testing strategies.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jag Reehal</title>
		<link>http://lostechies.com/chrismissal/2010/02/05/unit-testing-simple-asp-net-mvc-controllers/#comment-158</link>
		<dc:creator>Jag Reehal</dc:creator>
		<pubDate>Fri, 05 Feb 2010 10:20:07 +0000</pubDate>
		<guid isPermaLink="false">/blogs/chrismissal/archive/2010/02/05/unit-testing-simple-asp-net-mvc-controllers.aspx#comment-158</guid>
		<description>Hi Chris,

Yep behavior tests can be used for ASP.NET MVC Controllers and I especially like the AAA syntax :)

I did a similar post and covered other controller unit tests such as returning the correct view, and the Post-Redirect-Get pattern.

See http://www.arrangeactassert.com/how-to-unit-test-asp-net-mvc-controllers/</description>
		<content:encoded><![CDATA[<p>Hi Chris,</p>
<p>Yep behavior tests can be used for ASP.NET MVC Controllers and I especially like the AAA syntax :)</p>
<p>I did a similar post and covered other controller unit tests such as returning the correct view, and the Post-Redirect-Get pattern.</p>
<p>See <a href="http://www.arrangeactassert.com/how-to-unit-test-asp-net-mvc-controllers/" rel="nofollow">http://www.arrangeactassert.com/how-to-unit-test-asp-net-mvc-controllers/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
