<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://agileisrael.org/cs/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>Search results matching tags 'Testing Guidelines' and 'altnet'</title><link>http://agileisrael.org/cs/search/SearchResults.aspx?o=DateDescending&amp;tag=Testing+Guidelines,altnet&amp;orTags=0</link><description>Search results matching tags 'Testing Guidelines' and 'altnet'</description><dc:language>en-US</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>Basic Guidelines for using RowTest and data driven tests</title><link>http://agileisrael.org/cs/blogs/royo/archive/2007/12/18/basic-guidelines-for-using-rowtest-and-data-driven-tests.aspx</link><pubDate>Tue, 18 Dec 2007 23:28:32 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:742</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;I took a look at the code that was used to create the &lt;a href="http://www.andreas-schlapsi.com/projects/rowtest-extension-for-nunit/"&gt;NUnit RowTest Extension&lt;/a&gt; (which is pretty neat) and found this in one of the samples:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://weblogs.asp.net/blogs/rosherove/WindowsLiveWriter/a177d915a4ab_1383/image_2.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="359" alt="image" src="http://weblogs.asp.net/blogs/rosherove/WindowsLiveWriter/a177d915a4ab_1383/image_thumb.png" width="591" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The highlighted areas in the code show something which I feel is problematic and is the manifestation of a unit test anti-pattern which the XUnit book calls &amp;quot;Interacting tests&amp;quot;. basically, there is a dependency that is created by the first and second row, in which the second row cannot run individually. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Bad Naming once again leads to confusion&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;I&amp;#39;m not saying that this test is bad, because perhaps that is what they author was &lt;strong&gt;trying&lt;/strong&gt; to test - that the class level members are not destroyed between each row. I guess we&amp;#39;ll never know because the naming of the test is problematic - it doesn&amp;#39;t say what the expected behavior is, or what the scenario\context is. just what the general object being test is (and I&amp;#39;m not even sure about that). Still, it makes for a nice example for your own tests.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;The symptoms of interacting row tests&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Back to the issue at hand, the symptoms detailed below are caused by the wrong usage (in my mind) of the RowTest facility. The second argument in the RowTest is provided for the sole purpose of changing the behavior of the class under test (changing s_classMember) so that the &lt;strong&gt;next&lt;/strong&gt; row will be able to assert on the string.&lt;/p&gt;  &lt;p&gt;Now this prevents you from doing the following without going into annoying routines of code replacements:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;You can&amp;#39;t remove a row test without making sure you don&amp;#39;t break any other rows&lt;/li&gt;    &lt;li&gt;You can&amp;#39;t just insert a row test randomly in between without possible breaking another row&lt;/li&gt;    &lt;li&gt;You have to read the code in the test to understand what the row test is doing.&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Introducing dependencies between row test essentially makes the specific test method unmaintainable to a large degree. Since row-tests and data driven tests are a fairly new syntax for most of us, here are a few guidelines I try to follow:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Some Basic Guidelines&lt;/strong&gt;&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Treat each test row as if it will be the only one on the test method (so that you don&amp;#39;t feel the need to interact with other rows).&lt;/li&gt;    &lt;li&gt;Test rows must be a simple as possible to understand - that is - have no logic. In this case we &lt;strong&gt;do&lt;/strong&gt; have logic int he test row (pertaining to the next row)&lt;/li&gt; &lt;/ul&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5470426" width="1" height="1" alt="" /&gt;</description></item><item><title>Mocking LINQ Queries, Extension methods and Anonymous Types</title><link>http://agileisrael.org/cs/blogs/royo/archive/2007/11/17/mocking-linq-queries-extension-methods-and-anonymous-types.aspx</link><pubDate>Sat, 17 Nov 2007 21:47:14 GMT</pubDate><guid isPermaLink="false">23a435e0-515b-467d-ba86-b6d13375d82b:649</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;One of the things I wanted to show at my Interactive session on unit testing tips and tricks at TechEd this year was how you can &amp;quot;Stub&amp;quot; out results from LINQ Queries, or mock\stub Extension methods in .NET 3.5 (&lt;a href="http://weblogs.asp.net/rosherove/archive/2007/09/16/mocks-and-stubs-the-difference-is-in-the-flow-of-information.aspx"&gt;what&amp;#39;s the difference&lt;/a&gt; between mocks and stubs?)&lt;/p&gt;  &lt;p&gt;The only mocking framework in existence that can truly stub out LINQ queries and extension methods is &lt;a href="http://www.TypeMock.com"&gt;TypeMock.NET&lt;/a&gt;.&amp;amp;#xA0; Another option, if you use LINQ to SQL, is to be able to mock out the DataContext and the IOrderedQueriable interface, &lt;a href="http://aabs.wordpress.com/2007/06/26/using-mock-objects-when-testing-linq-code/"&gt;as outlined here&lt;/a&gt;, to return a custom query result set.&amp;amp;#xA0; I&amp;#39;ll talk about the first option in this post, since it is much easier to read and understand. I may touch on the second one in a later post.&lt;/p&gt;  &lt;p&gt;TypeMock, I&amp;#39;ve &lt;a href="http://weblogs.asp.net/rosherove/archive/2006/09/27/TypeMock-has-a-blog.aspx"&gt;talked about&lt;/a&gt; it &lt;a href="http://weblogs.asp.net/rosherove/archive/2005/03/20/395261.aspx"&gt;before&lt;/a&gt;, is a very powerful mocking framework. much more so than Rhino Mocks or NMock, because it allows isolating static methods, private methods, constructors, and basically anything you can do in IL, because it uses the .NET Profiler APIs to intercept method calls and do whatever it wants with them.&amp;amp;#xA0; In that regard, it is almost &lt;strong&gt;too&lt;/strong&gt; powerful&lt;strong&gt; &lt;/strong&gt;because it rids of of the need to actually design your code for testability, and just test it as is (how you actually write the tests is another matter for another post).&lt;/p&gt;  &lt;p&gt;But I&amp;#39;d rather have the argument whether TypeMock is good or bad, than not have TypeMock on the scene at all, simply because it&amp;#39;s just too damn valuable as is (disclosure: TypeMock is owned by a friend of mine).&lt;/p&gt;  &lt;p&gt;It&amp;#39;s the only real framework that can deal with real untestable legacy code and still allow you to isolate classes enough to test them without changing the code under test itself.&lt;/p&gt;  &lt;p&gt;It&amp;#39;s the only framework that allows to write unit tests for code that is based on .NET 3.5 and uses LINQ Queries and extension methods, allowing to isolate these two types of code and thus be able to separate things from their dependencies.&lt;/p&gt;  &lt;p&gt;Here are some examples I wanted to show (takes fro the examples that come with the TypeMock download:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;Example: Stubbing out LINQ Query Results&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;First, we&amp;#39;re going to create one fake result to return (array) from the LINQ query, and also introduce the real data source from qhich to query (realCustomerList). note that the customer list has 3 entries, and the fake list has only two entries.&lt;/p&gt;  &lt;pre class="csharpcode"&gt; &lt;span class="rem"&gt;///Two Customer instances used as fake values &lt;/span&gt;&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;&lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Customer fakeCustomer1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Customer { Id = 0, Name = &lt;span class="str"&gt;&amp;quot;Fake1&amp;quot;&lt;/span&gt;, City = &lt;span class="str"&gt;&amp;quot;SF&amp;quot;&lt;/span&gt; };&lt;/pre&gt;

&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Customer fakeCustomer2 = &lt;span class="kwrd"&gt;new&lt;/span&gt; Customer { Id = 1, Name = &lt;span class="str"&gt;&amp;quot;Fake2&amp;quot;&lt;/span&gt;, City = &lt;span class="str"&gt;&amp;quot;Redmond&amp;quot;&lt;/span&gt; }; &lt;span class="rem"&gt;/// A fake list used as return value in the tests&lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; List&amp;lt;Customer&amp;gt; fakeCustomers = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Customer&amp;gt; {fakeCustomer1,fakeCustomer2 }; &lt;span class="rem"&gt;/// A list containing 3 cusotmer use as the &amp;quot;real data&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; List&amp;lt;Customer&amp;gt; realCustomerList = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Customer&amp;gt; { &lt;span class="kwrd"&gt;new&lt;/span&gt; Customer{ Id = 1, Name=&lt;span class="str"&gt;&amp;quot;Dave&amp;quot;&lt;/span&gt;, City=&lt;span class="str"&gt;&amp;quot;Sarasota&amp;quot;&lt;/span&gt; }, &lt;span class="kwrd"&gt;new&lt;/span&gt; Customer{ Id = 2, Name=&lt;span class="str"&gt;&amp;quot;John&amp;quot;&lt;/span&gt;, City=&lt;span class="str"&gt;&amp;quot;Tampa&amp;quot;&lt;/span&gt; }, &lt;span class="kwrd"&gt;new&lt;/span&gt; Customer{ Id = 3, Name=&lt;span class="str"&gt;&amp;quot;Abe&amp;quot;&lt;/span&gt;, City=&lt;span class="str"&gt;&amp;quot;Miami&amp;quot;&lt;/span&gt; } };&lt;/pre&gt;

&lt;p&gt;Here&amp;#39;s how the unit test looks:&lt;/p&gt;

&lt;p&gt;&amp;amp;#xA0;&lt;/p&gt;

&lt;p&gt;&amp;amp;#xA0;&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt;[TestMethod]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; MockSimpleQuery()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (RecordExpectations r = &lt;span class="kwrd"&gt;new&lt;/span&gt; RecordExpectations())&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; var answer = from c &lt;span class="kwrd"&gt;in&lt;/span&gt; realCustomerList select c;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; r.Return(fakeCustomers);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt;&amp;amp;#xA0;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; var actual = from c &lt;span class="kwrd"&gt;in&lt;/span&gt; realCustomerList select c;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; Assert.AreEqual(2, actual.Count&amp;lt;Customer&amp;gt;());&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; Assert.IsTrue(actual.Contains(fakeCustomer1));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt; Assert.IsTrue(actual.Contains(fakeCustomer2));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;&lt;strong&gt;Line 6 &lt;/strong&gt;is the one that tells the TypeMock record what LINQ query to intercept.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Line 7 &lt;/strong&gt;tells TypeMock what value to return when this query is intercepted. that means the query will never really take place. &lt;/p&gt;

&lt;p&gt;finally, we assert that what we got from the query is the fake list of customers. Pretty darn easy.&lt;/p&gt;

&lt;p&gt;&amp;amp;#xA0;&lt;/p&gt;

&lt;p&gt;But is this a good test? Not really. this is only a demo of what you code intercept with typeMock. a real unit test will actually test a piece of code that runs this query, and, instead of providing it with a list of objects to query, will just provide it with the fake return value to receive&lt;/p&gt;

&lt;p&gt;&amp;amp;#xA0;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Example: Test that an anonymous type is created correctly&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt; [TestMethod]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt; [VerifyMocks]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; MockAnonymousTypeTest()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (RecordExpectations rec = &lt;span class="kwrd"&gt;new&lt;/span&gt; RecordExpectations())&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; &lt;span class="rem"&gt;//Mock the creation of the Anonymous Type&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; var p1 = &lt;span class="kwrd"&gt;new&lt;/span&gt; { Name = &lt;span class="str"&gt;&amp;quot;A&amp;quot;&lt;/span&gt;, Price = 3 };&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; rec.CheckArguments(); &lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt;&amp;amp;#xA0;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt; &lt;span class="rem"&gt;//fake the value of the Name Property&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; rec.ExpectAndReturn(p1.Name, &lt;span class="str"&gt;&amp;quot;John&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt; &lt;span class="rem"&gt;//if creation will be done diffrently an exception will be thrown.&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; var target = &lt;span class="kwrd"&gt;new&lt;/span&gt; { Name = &lt;span class="str"&gt;&amp;quot;B&amp;quot;&lt;/span&gt;, Price = 3 };&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt; &lt;span class="rem"&gt;//verify that the fake value is returned&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt; Assert.AreEqual(&lt;span class="str"&gt;&amp;quot;John&amp;quot;&lt;/span&gt;, target.Name);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 18: &lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;&amp;amp;#xA0;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Line 8 &lt;/strong&gt;tells the typemock recorder that this is the anonymous type creation we&amp;#39;d like to intercept.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Line 9 &lt;/strong&gt;tell it to assert internally that the anonymous type is indeed created with the correct &amp;quot;Name&amp;quot; property value and the correct &amp;quot;Price&amp;quot; property value. so if I later initialize the anonymous type with the wrong values, I will get a test exception based on the expected values. Pretty neat.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Line 12 &lt;/strong&gt;is just an example of how you can also intercept and retun whatever value you&amp;#39;d like from the property of an anonymous type. in this case the name will always return &amp;quot;John&amp;quot; even though it may have been initialized differently.&lt;/p&gt;

&lt;p&gt;&amp;amp;#xA0;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Example: Mocking Extension Methods&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Extension methods are static methods, which means you can&amp;#39;t replace them with a different method instance. there are ways to design yoru code so that the calls to the static methods are testable, but assuming you&amp;#39;re testing code that cannot be changed, or that is hard to redesign, intercepting the method call itself is almost the only choice. &lt;/p&gt;

&lt;p&gt;assume you&amp;#39;ve extended the Point class by adding this extension method:&lt;/p&gt;

&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Extend { &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; Point Multiply(&lt;span class="kwrd"&gt;this&lt;/span&gt; Point extendedInstance, &lt;span class="kwrd"&gt;int&lt;/span&gt; scalar) { extendedInstance.X *= scalar; extendedInstance.Y *= scalar; &lt;span class="kwrd"&gt;return&lt;/span&gt; extendedInstance; } }&lt;/pre&gt;

&lt;pre class="csharpcode"&gt;&amp;amp;#xA0;&lt;/pre&gt;

&lt;p&gt;Now you could write a test like this:&lt;/p&gt;

&lt;div class="csharpcode"&gt;
  &lt;pre&gt;&lt;span class="lnum"&gt; 1: &lt;/span&gt; [TestMethod]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 2: &lt;/span&gt; [VerifyMocks]&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 3: &lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; MockExtensionMethod()&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 4: &lt;/span&gt; {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 5: &lt;/span&gt; &lt;span class="kwrd"&gt;using&lt;/span&gt; (RecordExpectations rec = &lt;span class="kwrd"&gt;new&lt;/span&gt; RecordExpectations())&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 6: &lt;/span&gt; {&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 7: &lt;/span&gt; Point mocked = &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(7, 9);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 8: &lt;/span&gt; mocked.Multiply(6);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 9: &lt;/span&gt; rec.Return(&lt;span class="kwrd"&gt;new&lt;/span&gt; Point(5, 5));&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 10: &lt;/span&gt; }&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 11: &lt;/span&gt;&amp;amp;#xA0;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 12: &lt;/span&gt; Point target = &lt;span class="kwrd"&gt;new&lt;/span&gt; Point(7, 9);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 13: &lt;/span&gt; Point actual = target.Multiply(6);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 14: &lt;/span&gt;&amp;amp;#xA0;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 15: &lt;/span&gt; &lt;span class="rem"&gt;//Verify the returned vcalues&lt;/span&gt;&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 16: &lt;/span&gt; Assert.AreEqual(5, actual.X);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 17: &lt;/span&gt; Assert.AreEqual(5, actual.Y);&lt;/pre&gt;

  &lt;pre&gt;&lt;span class="lnum"&gt; 18: &lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, &amp;quot;Courier New&amp;quot;, courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }

&lt;p&gt;&amp;amp;#xA0;&lt;/p&gt;

&lt;p&gt;in line 7 we&amp;#39;re actually using the extension method as part of our recorder, and telling the record to return a specific value. then we later use that value in our code under test (like 13) and assert that we god the mocked value instead of the real one (the extension method is not executed).&lt;/p&gt;

&lt;p&gt;&amp;amp;#xA0;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What about other technologies?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;could you use this to test code that relies on other non testable technologies, like windows workflow, WCF etc? the answer is a big yes. the same principles apply, and most of these frameworks were not built with testability in mind. &lt;/p&gt;

&lt;p&gt;it&amp;#39;s in those cases where people ask &amp;quot;how can I test such code where everything is sealed, private and static?&amp;quot; that I tell them that, currently, TypeMock is the only framework that solves this problem at a satisfactory result.&lt;/p&gt;&lt;img src="http://weblogs.asp.net/aggbug.aspx?PostID=5261344" width="1" height="1" alt="" /&gt;</description></item></channel></rss>