<?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>eracer.de &#187; UnitTest</title>
	<atom:link href="http://www.eracer.de/tag/unittest/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.eracer.de</link>
	<description>[insert statement here]</description>
	<lastBuildDate>Mon, 05 Jul 2010 17:09:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>[.NET] HttpContext und UnitTests</title>
		<link>http://www.eracer.de/2009/02/17/net-httpcontext-und-unittests/</link>
		<comments>http://www.eracer.de/2009/02/17/net-httpcontext-und-unittests/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 15:24:33 +0000</pubDate>
		<dc:creator>Stevie</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[HttpContext]]></category>
		<category><![CDATA[UnitTest]]></category>
		<category><![CDATA[UnitTesting]]></category>
		<category><![CDATA[WebServices]]></category>

		<guid isPermaLink="false">http://www.eracer.de/?p=106</guid>
		<description><![CDATA[Da ich Unit Testing sehr mag und mehr oder weniger darauf angewiesen bin musste ich vor kurzem ein nerviges Problem lösen was vorallem des öfteren unter ASP.NET WebSites und WebServices auftritt. Verwendet man in einer Methode oder Funktion das Objekt &#8220;HttpContext&#8221; scheitert der UnitTest kläglich bzw. kann nicht weiter ausgeführt werden da in der UnitTest-Umgebung [...]]]></description>
			<content:encoded><![CDATA[<p>Da ich Unit Testing sehr mag und mehr oder weniger darauf angewiesen bin musste ich vor kurzem ein nerviges Problem lösen was vorallem des öfteren unter ASP.NET WebSites und WebServices auftritt. Verwendet man in einer Methode oder Funktion das Objekt &#8220;HttpContext&#8221; scheitert der UnitTest kläglich bzw. kann nicht weiter ausgeführt werden da in der UnitTest-Umgebung der HttpConext den Wert &#8220;null&#8221; hat. Nach ein wenig Googeln habe ich mir eine annehmbare Lösung gestrickt. Man simuliert einen HttpContext im Konstruktor der Testklasse und gaukelt somit der zu testenten Applikation einen HttpContext vor.</p>
<p>Hier das Code-Beispiel dafür, funktioniert bei mir einwandfrei. Der Inhalt der Variablen ist dabei relativ egal.</p>
<div class="codecolorer-container csharp blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> IrgendwasTest<br />
&nbsp; &nbsp; <span style="color: #008000;">&#123;</span> &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> IrgendwasTest<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> appVirtualDir <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;/&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> appPhysicalDir <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;C:\Users\&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> page <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;localhost&quot;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #6666cc; font-weight: bold;">string</span> query <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextWriter output <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">;</span> &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SimpleWorkerRequest workerRequest <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SimpleWorkerRequest<span style="color: #008000;">&#40;</span>appVirtualDir, appPhysicalDir, page, query, output<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpContext context <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> HttpContext<span style="color: #008000;">&#40;</span>workerRequest<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpContext<span style="color: #008000;">.</span><span style="color: #0000FF;">Current</span> <span style="color: #008000;">=</span> context<span style="color: #008000;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://www.eracer.de/2009/02/17/net-httpcontext-und-unittests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->