<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Edward Wilde &#187; unit testing</title>
	<atom:link href="http://blogs.edwardwilde.com/category/unit-testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.edwardwilde.com</link>
	<description>.Net &#38; SharePoint Developer / Architect</description>
	<lastBuildDate>Tue, 07 Feb 2012 08:19:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blogs.edwardwilde.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Edward Wilde &#187; unit testing</title>
		<link>http://blogs.edwardwilde.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blogs.edwardwilde.com/osd.xml" title="Edward Wilde" />
	<atom:link rel='hub' href='http://blogs.edwardwilde.com/?pushpress=hub'/>
		<item>
		<title>Typemock: System.NotSupportedException: Cannot dynamically create an instance of System.Void.</title>
		<link>http://blogs.edwardwilde.com/2010/04/19/typemock-system-notsupportedexception-cannot-dynamically-create-an-instance-of-system-void/</link>
		<comments>http://blogs.edwardwilde.com/2010/04/19/typemock-system-notsupportedexception-cannot-dynamically-create-an-instance-of-system-void/#comments</comments>
		<pubDate>Mon, 19 Apr 2010 12:21:36 +0000</pubDate>
		<dc:creator>Edward Wilde</dc:creator>
				<category><![CDATA[unit testing]]></category>
		<category><![CDATA[typemock]]></category>

		<guid isPermaLink="false">http://edwardwilde.wordpress.com/?p=362</guid>
		<description><![CDATA[Had a problem mocking a call to SPWorkflowActivationProperties.Item today. Turns out to be a bug in the TypeMock library. Problematic unit test When executed it throws the following exception: Fix: I can work around this issue by replacing the line: With: See thread on Typemock forum<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blogs.edwardwilde.com&amp;blog=9417511&amp;post=362&amp;subd=edwardwilde&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Had a problem mocking a call to SPWorkflowActivationProperties.Item today. Turns out to be a bug in the TypeMock library.</p>
<p><b>Problematic unit test</b><br />
<pre class="brush: csharp;">
[Test, Isolated]
        public void PublishToExternalDocumentLibrary_Calls_CopyTo_Correctly()
        {
            ApprovalWorkflow approvalWorkflow = Isolate.Fake.Instance&lt;ApprovalWorkflow&gt;(Members.CallOriginal, ConstructorWillBe.Called);
            SPWorkflowActivationProperties activationProperties = Isolate.Fake.Instance&lt;SPWorkflowActivationProperties&gt;(Members.CallOriginal, ConstructorWillBe.Called);
            SPListItem item = Isolate.Fake.Instance&lt;SPListItem&gt;();

            Isolate.WhenCalled(() =&gt; approvalWorkflow.PublishWhenComplete).WillReturn(true);
            Isolate.WhenCalled(() =&gt; approvalWorkflow.PublishDocumentLibraryUrl).WillReturn(ExternalDocumentLibraryUrl);
            Isolate.WhenCalled(() =&gt; approvalWorkflow.WorkflowActivationProperties).WillReturn(activationProperties);
            Isolate.WhenCalled(() =&gt; activationProperties.Item).WillReturn(item);
           
            Isolate.WhenCalled(() =&gt; item.Name).WillReturn(&quot;test.docx&quot;);
           
            // Fire the workflow completed event
            Isolate.Invoke.Event(() =&gt; approvalWorkflow.Completed += null, new object[] { this, EventArgs.Empty });

            Isolate.Verify.WasCalledWithExactArguments(() =&gt; item.CopyTo(&quot;http://xdev03.trading.ad.int.corp.local/Policies/test.docx&quot;));
        } 
</pre>
</p>
<p>When executed it throws the following exception:<br />
<pre class="brush: csharp;">
System.NotSupportedException: Cannot dynamically create an instance of System.Void.
at System.RuntimeType.CreateInstanceCheckThis()
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at hi.b(MethodBase A_0)
at hi.a(MethodBase A_0, fk A_1)
at a.a(fk A_0)
at a.c(fk A_0)
at fz.a(fk A_0)
at fz.a(Object A_0, MethodBase A_1, Object[] A_2)
at fz.a(Object A_0, String A_1, String A_2, MethodBase A_3, Object[] A_4, Object A_5)
at Microsoft.SharePoint.Security.SharePointPermissionAttribute.CreatePermission()
at System.Security.PermissionSet.CreateSerialized(Object[] attrs, Boolean serialize, Byte[]&amp; nonCasBlob, PermissionSet&amp; casPset, HostProtectionResource fullTrustOnlyResources)
at Microsoft.SharePoint.Workflow.SPWorkflowActivationProperties.get_Item()
at Total.SharePoint.Approval.Workflow.Test.ApprovalWorkflowFixture.&lt;&gt;c__DisplayClassd.&lt;PublishToExternalDocumentLibrary_Calls_CopyTo_Correctly&gt;b__9() in ApprovalWorkflowFixture.cs: line 44
at TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
at TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected)
at Total.SharePoint.Approval.Workflow.Test.ApprovalWorkflowFixture.PublishToExternalDocumentLibrary_Calls_CopyTo_Correctly() in ApprovalWorkflowFixture.cs: line 0 
</pre>
</p>
<p>
<b>Fix:</b><br />
I can work around this issue by replacing the line:<br />
<pre class="brush: csharp;">
Isolate.WhenCalled(() =&gt; activationProperties.Item).WillReturn(item);
</pre></p>
<p>
With:<br />
<pre class="brush: csharp;">
Isolate.NonPublic.WhenCalled(activationProperties, &quot;get_Item&quot;).WillReturn(item); 
</pre>
</p>
<p><a href="http://www.typemock.com/community/viewtopic.php?t=1760&amp;highlight=">See thread on Typemock forum</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edwardwilde.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edwardwilde.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edwardwilde.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edwardwilde.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edwardwilde.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edwardwilde.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edwardwilde.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edwardwilde.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edwardwilde.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edwardwilde.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edwardwilde.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edwardwilde.wordpress.com/362/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edwardwilde.wordpress.com/362/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edwardwilde.wordpress.com/362/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blogs.edwardwilde.com&amp;blog=9417511&amp;post=362&amp;subd=edwardwilde&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blogs.edwardwilde.com/2010/04/19/typemock-system-notsupportedexception-cannot-dynamically-create-an-instance-of-system-void/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/196d33ea9cdaf7817b98b981afe62c16?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Edward Wilde</media:title>
		</media:content>
	</item>
		<item>
		<title>Roy Osherove is giving an hands-on TDD Masterclass in the UK, September 21-25</title>
		<link>http://blogs.edwardwilde.com/2009/08/25/roy-osherove-is-giving-an-hands-on-tdd-masterclass-in-the-uk-september-21-25/</link>
		<comments>http://blogs.edwardwilde.com/2009/08/25/roy-osherove-is-giving-an-hands-on-tdd-masterclass-in-the-uk-september-21-25/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 08:47:04 +0000</pubDate>
		<dc:creator>Edward Wilde</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[unit testing]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://blogs.edwardwilde.com/?p=72</guid>
		<description><![CDATA[Roy Osherove is giving an hands-on TDD Masterclass in the UK, September 21-25. Roy is author of &#8220;The Art of Unit Testing&#8221; (http://www.artofunittesting.com/), a leading tdd &#38; unit testing book; he maintains a blog at http://iserializable.com (which amoung other things has critiqued tests written by Microsoft for asp.net MVC &#8211; check out the testreviews category) [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blogs.edwardwilde.com&amp;blog=9417511&amp;post=74&amp;subd=edwardwilde&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Roy Osherove is giving an hands-on TDD Masterclass in the UK, September 21-25. Roy is author of &#8220;The Art of Unit Testing&#8221; (<a href="http://www.artofunittesting.com/">http://www.artofunittesting.com/</a>), a leading tdd &amp; unit testing book; he maintains a blog at <a href="http://iserializable.com/">http://iserializable.com</a> (which amoung other things has critiqued tests written by Microsoft for <a href="http://asp.net/">asp.net</a> MVC &#8211; check out the testreviews category) and has recently been on the Scott Hanselman podcast (<a href="http://bit.ly/psgYO">http://bit.ly/psgYO</a>) where he educated Scott on best practices in Unit Testing techniques. For a further insight into Roy&#8217;s style, be sure to also check out Roy&#8217;s talk at the recent Norwegian Developer&#8217;s Conference (<a href="http://bit.ly/NuJVa">http://bit.ly/NuJVa</a>).</p>
<p>Full Details here: <a href="http://bbits.co.uk/tddmasterclass">http://bbits.co.uk/tddmasterclass</a></p>
<p>bbits are holding a raffle for a free ticket for the event. To be eligible to win the ticket (worth £2395!) you MUST paste this text, including all links, into your blog and email <a href="mailto:Ian@bbits.co.uk">Ian@bbits.co.uk</a> with the url to the blog entry.  The draw will be made on September 1st and the winner informed by email and on <a href="http://bbits.co.uk/blog">bbits.co.uk/blog</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edwardwilde.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edwardwilde.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edwardwilde.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edwardwilde.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edwardwilde.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edwardwilde.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edwardwilde.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edwardwilde.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edwardwilde.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edwardwilde.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edwardwilde.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edwardwilde.wordpress.com/74/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edwardwilde.wordpress.com/74/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edwardwilde.wordpress.com/74/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blogs.edwardwilde.com&amp;blog=9417511&amp;post=74&amp;subd=edwardwilde&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blogs.edwardwilde.com/2009/08/25/roy-osherove-is-giving-an-hands-on-tdd-masterclass-in-the-uk-september-21-25/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/196d33ea9cdaf7817b98b981afe62c16?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Edward Wilde</media:title>
		</media:content>
	</item>
		<item>
		<title>Unit testing for SharePoint</title>
		<link>http://blogs.edwardwilde.com/2008/12/04/unit-testing-for-sharepoint/</link>
		<comments>http://blogs.edwardwilde.com/2008/12/04/unit-testing-for-sharepoint/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 12:43:22 +0000</pubDate>
		<dc:creator>Edward Wilde</dc:creator>
				<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://blogs.edwardwilde.com/index.php/2008/12/04/unit-testing-for-sharepoint/</guid>
		<description><![CDATA[Typemock are offering their new product for unit testing SharePoint called Isolator For SharePoint, for a special introduction price. it is the only tool that allows you to unit test SharePoint without a SharePoint server. To learn more click here. The first 50 bloggers who blog this text in their blog and tell us about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blogs.edwardwilde.com&amp;blog=9417511&amp;post=65&amp;subd=edwardwilde&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Typemock are offering their new product for <a href="http://www.typemock.com/sharepointpage.php?utm_source=sp_bb&amp;utm_medium=blog_4sp&amp;utm_campaign=sp_bb">unit testing SharePoint</a> called Isolator For SharePoint, for a special introduction price. it is the only tool that allows you to <a href="http://blog.typemock.com/2008/11/newisolatorforsharepointtoolforunittest.html?utm_source=typeblog&amp;utm_medium=sp_bb&amp;utm_campaign=typeblog">unit test SharePoint</a> without a SharePoint server. To learn more <a href="http://www.typemock.com/sharepointpage.php?utm_source=sp_bb&amp;utm_medium=blog_4sp&amp;utm_campaign=sp_bb">click here</a>. </p>
<p><strong>The first 50 bloggers </strong>who blog this text in their blog and tell us about it, will get a Full Isolator license, Free. for rules and info <a href="http://blog.typemock.com/2008/11/newisolatorforsharepointtoolforunittest.html">click here</a>. </p>
<p><span id="more-65"></span></p>
<p>Here&#8217;s an example taken from their introduction article:</p>
</p>
<pre>
[TestMethod]
[Isolated]
public void RepositoryAdd_FakeSPServer_PropertiesAreSetWithCorrectArguments()
{
  var fakeWeb  = Isolate.Fake.Instance<spweb>(Members.ReturnRecursiveFakes);
  var fakeUser = fakeWeb.SiteUsers.GetByID(1);
  var fakeItem = fakeWeb.Lists[""].Items.Add();

  Isolate.WhenCalled(() => fakeItem[0]).WillReturn(1);

  Registration registration = new Registration(){
          CourseId=1234,
          RegistrationStatus = "Pending",
          Title="UnitTest",
          UserId = 100
      };

  RegistrationRepository repository = new RegistrationRepository();
  int id = repository.Add(registration, false, fakeWeb);

  Assert.AreEqual(1, id);
  Isolate.Verify.WasCalledWithExactArguments(()=> fakeItem[Fields.Title] = "UnitTest");
  Isolate.Verify.WasCalledWithExactArguments(()=> fakeItem[Fields.UserId]= 100);
  Isolate.Verify.WasCalledWithExactArguments(()=> fakeItem[Fields.User]= fakeUser);
  Isolate.Verify.WasCalledWithExactArguments(()=> fakeItem[Fields.Status]= "Pending");
}
 </pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/edwardwilde.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/edwardwilde.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/edwardwilde.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/edwardwilde.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/edwardwilde.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/edwardwilde.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/edwardwilde.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/edwardwilde.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/edwardwilde.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/edwardwilde.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/edwardwilde.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/edwardwilde.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/edwardwilde.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/edwardwilde.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blogs.edwardwilde.com&amp;blog=9417511&amp;post=65&amp;subd=edwardwilde&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blogs.edwardwilde.com/2008/12/04/unit-testing-for-sharepoint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/196d33ea9cdaf7817b98b981afe62c16?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Edward Wilde</media:title>
		</media:content>
	</item>
	</channel>
</rss>
