<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>ASP.NET MVC</title><link>http://forums.asp.net/1146.aspx</link><description>Discussions regarding Model-View-Controller (MVC) support in ASP.NET.  &lt;a href="http://forums.asp.net/1215.aspx"&gt;T4MVC subforum&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Unit Testing Controls That Use Request/Form/Session parameters</title><link>http://forums.asp.net/thread/3274102.aspx</link><pubDate>Sat, 04 Jul 2009 00:09:20 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274102</guid><dc:creator>gerrylowry</dc:creator><author>gerrylowry</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274102.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274102</wfw:commentRss><description>&lt;p&gt;More refences:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.codeplex.com/xunit"&gt;http://www.codeplex.com/xunit&lt;/a&gt;&amp;nbsp; xUnit.net, authors Brad Wilson and Jim (James?) Newkirk&lt;/p&gt;
&lt;p&gt;&lt;a href="http://code.google.com/p/moq/"&gt;http://code.google.com/p/moq/&lt;/a&gt;&amp;nbsp; Daniel Cazzulino and Clarius Consulting&lt;/p&gt;
&lt;p&gt;&lt;a href="http://weblogs.asp.net/cazzu/archive/2008/04/22/moq-now-uses-xunit-for-its-unit-tests.aspx"&gt;http://weblogs.asp.net/cazzu/archive/2008/04/22/moq-now-uses-xunit-for-its-unit-tests.aspx&lt;/a&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Unit Testing Controls That Use Request/Form/Session parameters</title><link>http://forums.asp.net/thread/3274098.aspx</link><pubDate>Sat, 04 Jul 2009 00:03:15 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274098</guid><dc:creator>gerrylowry</dc:creator><author>gerrylowry</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274098.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274098</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/fan/images/icon-quote.gif"&gt; &lt;strong&gt;Scout7:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;Now that I am getting more comfortable with MVC it is time to turn my attention to unit testing my controllers, (&lt;strong&gt;&lt;span style="BACKGROUND-COLOR:#ffff00;"&gt;TDD&lt;/span&gt;&lt;/strong&gt; I think it is called?).&lt;/div&gt;&lt;/BLOCKQUOTE&gt;
&lt;p&gt;Actually,&amp;nbsp;&lt;strong&gt;&lt;span style="BACKGROUND-COLOR:#ffff00;"&gt;TDD&lt;/span&gt;&lt;/strong&gt; is a special form of unit testing.
&lt;p&gt;&lt;strong&gt;&lt;span style="BACKGROUND-COLOR:#ffff00;"&gt;T&lt;/span&gt;&lt;/strong&gt;est &lt;strong&gt;&lt;span style="BACKGROUND-COLOR:#ffff00;"&gt;D&lt;/span&gt;&lt;/strong&gt;riven &lt;strong&gt;&lt;span style="BACKGROUND-COLOR:#ffff00;"&gt;D&lt;/span&gt;&lt;/strong&gt;evelopment is part of one some people called &lt;em&gt;agile development&lt;/em&gt;.
&lt;p&gt;imo, &lt;em&gt;agile development&lt;/em&gt;&amp;nbsp;is&amp;nbsp;a vulgar* use of &amp;quot;agile&amp;quot;;.&amp;nbsp; See &lt;a href="http://www.answers.com/agile"&gt;http://www.answers.com/agile&lt;/a&gt;.
&lt;p&gt;&amp;nbsp;&amp;nbsp; (*&amp;quot;vulgar&amp;quot; itself is a vulgar word; see &lt;a href="http://www.answers.com/vulgar"&gt;http://www.answers.com/vulgar&lt;/a&gt;).
&lt;p&gt;Simple example, &lt;strong&gt;unit testing&lt;/strong&gt; versus&amp;nbsp;&lt;strong&gt;&lt;span style="BACKGROUND-COLOR:#ffff00;"&gt;TDD&lt;/span&gt;&lt;/strong&gt; for the function squareThisNumber:
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (a) standard unit testing (test &lt;em&gt;&lt;strong&gt;after&lt;/strong&gt;&lt;/em&gt; testing):
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (1)&amp;nbsp; I write my function:&amp;nbsp; int squareThisNumber(int n){return n*n};
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (2)&amp;nbsp;&amp;nbsp;I&amp;nbsp;write a unit test to&amp;nbsp;check that my function in (1) works.
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (b)&amp;nbsp;test driven development&amp;nbsp;testing (test &lt;strong&gt;&lt;em&gt;before&lt;/em&gt;&lt;/strong&gt; testing):&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (1)&amp;nbsp;&amp;nbsp;I&amp;nbsp;write a unit test to&amp;nbsp;check&amp;nbsp;my unwritten function;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; e.g.:&amp;nbsp; testMySquareFunction_2x2_is_4()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (squareThisNumber(2) == 4) signalTestPassed;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (2)&amp;nbsp; I write a &amp;quot;stub&amp;quot; for squareThisNumber so that my unit test will compile;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; the stub might return 3 since 3 is not a square of any int.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (3)&amp;nbsp; I compile and run my test from (1); as expected it will&amp;nbsp;fail.&amp;nbsp; Failure is often graphically signalled in &lt;span style="COLOR:#ff0000;"&gt;&lt;strong&gt;red&lt;/strong&gt;&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (4)&amp;nbsp; I now write my squareThisNumber function; if I get it right,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; testMySquareFunction will pass.&amp;nbsp; Success is often graphically signalled in &lt;strong&gt;&lt;span style="COLOR:#008000;"&gt;green&lt;/span&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The premise of TDD, also called &amp;quot;test &lt;strong&gt;&lt;em&gt;first&lt;/em&gt;&lt;/strong&gt; testing&amp;quot; is that because I write&lt;br /&gt;my test before I write my function, I&amp;#39;ll have give more thought to the design&lt;br /&gt;of my function and therefore I&amp;#39;ll craft better code.&lt;/p&gt;
&lt;p&gt;Note:&amp;nbsp; depending to the complexity of the function I need, I may have to write many unit&amp;nbsp;tests per function.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;span style="BACKGROUND-COLOR:#ffff00;"&gt;TDD&lt;/span&gt;&lt;/strong&gt;&amp;nbsp;is not agile except for someone who is very experienced with it.&amp;nbsp; A great programmer could write an entire system with zero unit tests (whether before or after).&amp;nbsp; Then, along comes Microsoft with .NET Framework 4.0 and something breaks the great programmer&amp;#39;s working code.&amp;nbsp; Had the great programmer written unit tests, she/he would have discovered the new &lt;em&gt;thank you Microsoft&amp;nbsp; bugs&lt;/em&gt; before sending off her/his work of art to unsuspecting end users.&lt;/p&gt;
&lt;p&gt;See &lt;a href="http://stephenwalther.com/blog/archive/2009/04/08/test-after-development-is-not-test-driven-development.aspx"&gt;http://stephenwalther.com/blog/archive/2009/04/08/test-after-development-is-not-test-driven-development.aspx&lt;/a&gt;,&lt;br /&gt;&lt;a href="http://stephenwalther.com/blog/archive/2009/04/11/tdd-tests-are-not-unit-tests.aspx"&gt;http://stephenwalther.com/blog/archive/2009/04/11/tdd-tests-are-not-unit-tests.aspx&lt;/a&gt;, and&lt;br /&gt;&lt;a href="http://martinfowler.com/articles/mocksArentStubs.html"&gt;http://martinfowler.com/articles/mocksArentStubs.html&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Regards, &lt;br /&gt;Gerry (Lowry)&lt;/p&gt;</description></item><item><title>Re: Unit Testing Controls That Use Request/Form/Session parameters</title><link>http://forums.asp.net/thread/3274026.aspx</link><pubDate>Fri, 03 Jul 2009 21:43:19 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3274026</guid><dc:creator>paul.vencill</dc:creator><author>paul.vencill</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3274026.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3274026</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;Moq isn&amp;#39;t a replacement for your unit testing suite (I use the MS tools as well), it&amp;#39;s a mocking framework for doing exactly wha tyou&amp;#39;re trying to do.&amp;nbsp; So...&amp;nbsp; get it, learn it, love it.&amp;nbsp; It&amp;#39;ll make your life *tons* easier.&lt;/p&gt;
&lt;p&gt;Second, it&amp;#39;s really recommended that you don&amp;#39;t use the &amp;#39;environmentals&amp;#39; like Request in your controllers, but sometimes you have to, so...&amp;nbsp; Now, once you have Moq installed, you set a reference to it in your test project, and you can start using it to mock thigns like the Request.&lt;/p&gt;
&lt;p&gt;Good tutorial here:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msbdusers.net/blogs/shahedkhan/archive/2009/05/15/10227.aspx"&gt;http://msbdusers.net/blogs/shahedkhan/archive/2009/05/15/10227.aspx&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Unit Testing Controls That Use Request/Form/Session parameters</title><link>http://forums.asp.net/thread/3273764.aspx</link><pubDate>Fri, 03 Jul 2009 15:31:09 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:3273764</guid><dc:creator>Scout7</dc:creator><author>Scout7</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/3273764.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=1146&amp;PostID=3273764</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;Now that I am getting more comfortable with MVC it is time to turn my attention to unit testing my controllers, (TDD I think it is called?).&lt;/p&gt;
&lt;p&gt;I know, I should have been doing this all along but my brain can only handle learning 1 thing at a time now! &lt;img title="Embarassed" border="0" alt="Embarassed" src="http://forums.asp.net/tiny_mce/jscripts/tiny_mce/plugins/emotions/img/smiley-embarassed.gif" /&gt;.&lt;/p&gt;
&lt;p&gt;Anyway, I have been looking at some tutorials that use things like MOQ but I am only currently using the standard VS Un it testing tools.&lt;/p&gt;
&lt;p&gt;I have started with a very small unit test on controller that has only an Index() that captures a users browsers details as follows,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;ViewData[&amp;quot;UserAgent&amp;quot;] = Request.UserAgent;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Bad time to start looking into this, late on a very hot Friday afternoon, but this tripped up my first little tests when I realised that I didn&amp;#39;t have the Request scope to use, Doh!&lt;/p&gt;
&lt;p&gt;So, to save me a little head scratching I thought I would ask what the best methods and/or testing tools are to use to be able to test controllers that need Request/Form/Session variables. Obviously I need to mock this data somehow. &lt;/p&gt;
&lt;p&gt;Can anyone suggest some good tutorials for someone with as tired brain as mine? &lt;img title="Wink" border="0" alt="Wink" src="http://forums.asp.net/tiny_mce/jscripts/tiny_mce/plugins/emotions/img/smiley-wink.gif" /&gt;&lt;/p&gt;</description></item></channel></rss>