<?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>iterativo</title>
	<atom:link href="http://iterativo.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://iterativo.wordpress.com</link>
	<description>Iterative Software Development</description>
	<lastBuildDate>Fri, 30 Sep 2011 01:46:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='iterativo.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>iterativo</title>
		<link>http://iterativo.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://iterativo.wordpress.com/osd.xml" title="iterativo" />
	<atom:link rel='hub' href='http://iterativo.wordpress.com/?pushpress=hub'/>
		<item>
		<title>ASP.NET MVC / Ajax Example</title>
		<link>http://iterativo.wordpress.com/2011/08/01/asp-net-mvc-ajax-example/</link>
		<comments>http://iterativo.wordpress.com/2011/08/01/asp-net-mvc-ajax-example/#comments</comments>
		<pubDate>Mon, 01 Aug 2011 14:40:00 +0000</pubDate>
		<dc:creator>Rafael Torres</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Ajax]]></category>

		<guid isPermaLink="false">https://iterativo.wordpress.com/?p=175</guid>
		<description><![CDATA[Let’s assume you have a page which has a small section that should update its content based on a tab clicked by the user, just like the image below. We could solve it the traditional way, but re-rendering the entire page each time a tab is clicked. Or better yet, we could use Ajax to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=175&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Let’s assume you have a page which has a small section that should update its content based on a tab clicked by the user, just like the image below.</p>
<p><a href="http://iterativo.files.wordpress.com/2011/08/mockup.png"><img src="http://iterativo.files.wordpress.com/2011/08/mockup.png?w=300&#038;h=266" alt="web page with tabbed section" title="web page mockup" width="300" height="266" class="aligncenter size-medium wp-image-180" /></a></p>
<p>We could solve it the traditional way, but re-rendering the entire page each time a tab is clicked. Or better yet, we could use Ajax to only re-render that section. </p>
<p>This is how you could accomplish that if you’re using ASP.NET MVC.</p>
<h3>Create a new Controller/Action</h3>
<p>For simplicity’s sake, let’s assume we already have the code for the main page. All we need to do now is build the logic for the Ajax section. In that case, the first thing we’ll need is a controller/action to handle our Ajax requests. Here’s an example:</p>
<p>&#160;</p>
<pre><pre class="brush: csharp; wrap-lines: false;">
public class MyController : Controller
{
	// Other code

	[HttpGet]
	public PartialViewResult TabSection(int tabId)
	{
		var model = buildViewModel(tabId) // logic to build viewModel based on tabId
		return PartialView(&quot;_TabSection&quot;, model);
	}
}
</pre></pre>
<p>As you can see, our action will just be expecting an http get request with a tabId param. Notice the PartialViewResult return type as opposed to the more common ViewResult. This is because we don’t want to render a full View (with optional master page and complete html markup); instead, we want a partial view (i.e., a sub-section of an entire html page). </p>
<h3>Create a partial to render your Ajax section</h3>
<p>This is the partial that will render the viewModel returned by our MyController.TabSection() action. As you can see in our action implementation, we decided to call it <em>_TabSection.cshtml</em> (assuming you’re using <a href="http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx" target="_blank">razor</a>). I won’t show the code to implement this partial here, since there’s nothing special about it – it is just like any other ASP.NET MVC partial in your project. In fact, there’s nothing that stops you from using this partial in any other (non-Ajax) operation in your website, as long as you pass the correct ViewModel type to it. </p>
<h3>Wire up the code in your main View</h3>
<p>This is the last step to hook up your Ajax control. Using jquery, we can take advantage of its <a href="http://api.jquery.com/jQuery.get/" target="_blank">jQuery.get()</a>. We’ll end up with something like this:</p>
<p>&#160;</p>
<pre><pre class="brush: xml; wrap-lines: false;">
&lt;!-- meta data --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
	$(function(){
		$(&quot;#tabs a&quot;).click(function(){
			var tabId = $(this).attr(&quot;tabId&quot;);
			var ajaxUrl = &quot;/MyController/TabSection?tabId=&quot; + tabId;
			$.get(ajaxUrl, &quot;&quot;,
				function(data){
					$(&quot;#tab_content&quot;).html(data);
				}, &quot;html&quot;);
		});
	});
&lt;/script&gt;
&lt;!-- left nav bar html --&gt;
&lt;div id=&quot;tabs&quot;&gt;
	&lt;a href=&quot;javascript:void(0)&quot; tabid=&quot;1&quot;&gt;One&lt;/a&gt;
	&lt;a href=&quot;javascript:void(0)&quot; tabid=&quot;2&quot;&gt;Two&lt;/a&gt;
	&lt;a href=&quot;javascript:void(0)&quot; tabid=&quot;3&quot;&gt;Three&lt;/a&gt;
&lt;/div&gt;
&lt;div id=&quot;tab_content&quot;&gt;
	&lt;!-- Tab content: to be updated by the Ajax call --&gt;
&lt;/div&gt;
&lt;!-- image and other stuff's html --&gt;
</pre></pre>
<p>Notice the <em>tabId</em> attribute in the tab’s anchor tags. This is not a valid html attribute, but we can use this as a trick to have our jquery code figure out the clicked tab when generating our Ajax request. The jquery.get() abstracts all the logic to generate the Ajax call and process its response. In this example, once the response is received, it updates the html within the <em>tab_content</em> div. </p>
<p>As you may have realized, besides the jquery magic, the beauty is that the tab html content is returned by the MVC framework. In other words, by us just setting a controller action that calls a partial view (which is practically the same process we’d follow to create a new page in our MVC project), we are able to implement an Ajax control in ASP.NET MVC. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iterativo.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iterativo.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iterativo.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iterativo.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iterativo.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iterativo.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iterativo.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iterativo.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iterativo.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iterativo.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iterativo.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iterativo.wordpress.com/175/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iterativo.wordpress.com/175/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iterativo.wordpress.com/175/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=175&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iterativo.wordpress.com/2011/08/01/asp-net-mvc-ajax-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/02bbe34a9a3e2e8cfe043d4e15814832?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Rafael</media:title>
		</media:content>

		<media:content url="http://iterativo.files.wordpress.com/2011/08/mockup.png?w=300" medium="image">
			<media:title type="html">web page mockup</media:title>
		</media:content>
	</item>
		<item>
		<title>Using ASP.NET MVC&#8217;s Html.RenderAction()</title>
		<link>http://iterativo.wordpress.com/2011/07/27/using-asp-net-mvc3s-html-renderaction/</link>
		<comments>http://iterativo.wordpress.com/2011/07/27/using-asp-net-mvc3s-html-renderaction/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 22:30:22 +0000</pubDate>
		<dc:creator>Rafael Torres</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">https://iterativo.wordpress.com/2011/07/27/using-asp-net-mvc3s-html-renderaction/</guid>
		<description><![CDATA[Let’s say that you have a website that has certain “UI snippets” that will be reused across multiple pages. A site layout page could help you with this, but let’s say that (a) you won’t need to reuse these sections across all pages and/or (b) these snippets will be rendered in different parts of the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=172&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Let’s say that you have a website that has certain “UI snippets” that will be reused across multiple pages. A site layout page could help you with this, but let’s say that (a) you won’t need to reuse these sections across all pages and/or (b) these snippets will be rendered in different parts of the markup, depending on the page.</p>
<p>One way to solve that problem is to create a partial and call it specifically from each page where you want it to be rendered. However, let’s say that the partial needs some business data (from the controller). Now the partial-only solution is not that practical. </p>
<p>An alternative would be to add it to the view model object you’re sending back from the page’s controller action and pass it on to the partial. But this means you’ll have to add it to each controller action providing the view model for each page in which you want to add the snippet. So you can see why this is not very DRY. You need a better solution.</p>
<p><strong>Enter Html.RenderAction()</strong></p>
<p>What RenderAction() allows you to do is to call a separate controller action/View from your original View. With this approach you can move the snippet’s business logic to a separate controller/action (which can be unit/integration tested on its own), and create its own View to render the snippet’s content. Then, all you need to do is to call Html.RenderAction() from the page in which you want to inject the snippet. </p>
<p>For example, let’s suppose that we want a little snippet in our website that shows up a summary of the current logged-in user (Name, gender, last time logged in, etc.) If we wanted to use the Html.RenderAction() approach to solve handle this situation, first you’d want to create a controller/action. For example:</p>
<pre><pre class="brush: csharp; wrap-lines: false;">
public class UserController : Controller
{
	[ChildActionOnly]
	public ViewResult SummarySnippet()
	{
		var model = getUserSummaryInfo(); // builds ViewModel object
		return View(model);
	}
}
</pre></pre>
<p>(*Note the ChildActionOnly attribute – it tells MVC that this action can only be called when injected from another page. I.e., it cannot be accessed directly by browsing to it).</p>
<p>This action uses the default view (SummarySnippet.cshtml if you’re using razor), in which you will have the markup for the snippet (not shown here). At this point, you’re pretty much ready to use this snippet in any page you want. All you’ll need to do is call Html.RenderAction in your appropriate page’s markup. For example:</p>
<pre><pre class="brush: xml; wrap-lines: false;">
@{Html.RenderAction(&quot;SummarySnippet&quot;, &quot;User&quot;);}
</pre></pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iterativo.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iterativo.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iterativo.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iterativo.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iterativo.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iterativo.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iterativo.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iterativo.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iterativo.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iterativo.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iterativo.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iterativo.wordpress.com/172/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iterativo.wordpress.com/172/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iterativo.wordpress.com/172/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=172&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iterativo.wordpress.com/2011/07/27/using-asp-net-mvc3s-html-renderaction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/02bbe34a9a3e2e8cfe043d4e15814832?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Rafael</media:title>
		</media:content>
	</item>
		<item>
		<title>The importance of not overloading your employees</title>
		<link>http://iterativo.wordpress.com/2011/05/13/the-importance-of-not-overloading-your-employees/</link>
		<comments>http://iterativo.wordpress.com/2011/05/13/the-importance-of-not-overloading-your-employees/#comments</comments>
		<pubDate>Fri, 13 May 2011 14:42:10 +0000</pubDate>
		<dc:creator>Rafael Torres</dc:creator>
				<category><![CDATA[Management]]></category>

		<guid isPermaLink="false">https://iterativo.wordpress.com/2011/05/13/the-importance-of-not-overloading-your-employees/</guid>
		<description><![CDATA[There&#8217;s a common misconception in traditional-minded companies that your employees should always have something to do. That&#8217;s a very dangerous belief. Why&#8230; you may think (especially if you&#8217;re the one paying the staff or managing them). Let me backtrack first. I know my statement is a very general one. I&#8217;m making that statement under the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=170&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a common misconception in traditional-minded companies that your employees should always have something to do. That&#8217;s a very dangerous belief. Why&#8230; you may think (especially if you&#8217;re the one paying the staff or managing them).</p>
<p>Let me backtrack first. I know my statement is a very general one. I&#8217;m making that statement under the assumption that your work environment is characterized by professional, smart, creative, resourceful workers. Now under that assumption, I believe workers need some &quot;free&quot; time to strive. If you don&#8217;t believe me, look at companies like Google. I&#8217;m sure you&#8217;ve heard of their 20% time project rule. What that means is that they let their employees work on their own projects 1 full day out of a work week. That&#8217;s a pretty impressive number. And if you think that&#8217;s just a waste of time, consider that gmail, google talk and google news were among those projects in their infancy. </p>
<p>Now at this point, you may be thinking &quot;well&#8230; they have the money to afford it.&quot; True, but the reality is that they didn&#8217;t get there just by chance. It is precisely this trust-based and progressive mentality that made them the successful players they now are. What I&#8217;m saying is, if you can&#8217;t afford letting them work on their own projects for 20% of their time, start with a lower percentage. Even if it&#8217;s just 10 or 5% of their time, that&#8217;s better than nothing. What you really can&#8217;t afford is to have a workforce that&#8217;s so overwhelmed by their workload that they become stagnant. Almost like machines or robots in an assembly line, unable to do anything else outside of a box. </p>
<p>The reality is that our brains need a mental break throughout the day. It is under those &quot;calm&quot; times your workers will think about extraordinary things. It is in those times when they will be able to think outside of the box, and consider new processes / solutions / alternatives that had not been considered before. Have you ever been thinking about how to solve a complex problem in your life for days, and then all of a sudden, when you&#8217;re taking a shower, driving, or at the most random moment you think of an alternative that had never crossed your mind? I&#8217;m sure you have. It is precisely the combination of thinking/not-thinking about a particular problem what eventually allows you to come to (at the best) a brilliant solution. </p>
<p>In short, if you&#8217;re a technology company (or for that fact any other kind of &quot;progressive&quot; company), you must make sure there&#8217;s room in your operations to allow your workers to develop new ideas. You must create a culture that supports and encourages such times. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iterativo.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iterativo.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iterativo.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iterativo.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iterativo.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iterativo.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iterativo.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iterativo.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iterativo.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iterativo.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iterativo.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iterativo.wordpress.com/170/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iterativo.wordpress.com/170/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iterativo.wordpress.com/170/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=170&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iterativo.wordpress.com/2011/05/13/the-importance-of-not-overloading-your-employees/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/02bbe34a9a3e2e8cfe043d4e15814832?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Rafael</media:title>
		</media:content>
	</item>
		<item>
		<title>Modeling a discrete property in a Rails entity</title>
		<link>http://iterativo.wordpress.com/2010/12/26/modeling-a-discrete-property-in-a-rails-entity/</link>
		<comments>http://iterativo.wordpress.com/2010/12/26/modeling-a-discrete-property-in-a-rails-entity/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 00:31:54 +0000</pubDate>
		<dc:creator>Rafael Torres</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[modeling]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://iterativo.wordpress.com/?p=131</guid>
		<description><![CDATA[Let&#8217;s assume we have a rails app that has a model entity needing a discrete property. As an example, let&#8217;s pretend it&#8217;s a Person needing a gender. In C# or Java we could accomplish this by using an Enumeration. Unfortunately,  in Ruby there&#8217;s not a built-in enumeration type. There are ways to work around this. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=131&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s assume we have a rails app that has a model entity needing a discrete property. As an example, let&#8217;s pretend it&#8217;s a Person needing a gender. In C# or Java we could accomplish this by using an <a title="Wikipedia definition of the Enumerated type" href="http://en.wikipedia.org/wiki/Enumerated_type" target="_blank">Enumeration</a>. Unfortunately,  in Ruby there&#8217;s not a built-in enumeration type. There are ways to work around this. This post explains one way to accomplish this in Rails 3 (some adjustments may be needed for Rails &lt;= 2).</p>
<h3>The Person Class</h3>
<p>So far, all we have is an empty Person class as generated by Rails scaffolding.<br />
<pre class="brush: ruby; wrap-lines: false;">
class Person &lt; ActiveRecord::Base

end
</pre></p>
<p>What we&#8217;ll need to do is add a gender property to it. </p>
<p>Some solutions I ran into online solve this situation by persisting a String, which in this case would define the gender value (&#8220;Male&#8221; or &#8220;Female&#8221;). I don&#8217;t like that approach for 2 reasons: first it is using a String to represent a discrete value that should only have 2 statuses, and second it will require more resources to persist these data unnecessarily. And that&#8217;s just the beginning &#8211; think about internationalization just to give you more arguments against it. </p>
<p>Other solutions call for adding a totally new entity (Gender) in our rails model and creating a foreign relationship to it. Once again, this wastes unnecessary resources (why do we need a new Gender DB table just to hold two constant values? Moreover, Gender is not really an entity in our domain model.) Not a good solution, IMHO. </p>
<p>In short, what we&#8217;re aiming for is an int that represents our gender that we can easily persist. We&#8217;ll also take care of showing the right string in the Views.</p>
<h3>Adding the Gender Constants and The Appropriate Validation</h3>
<p>If you&#8217;ve already added a gender property (as an int) to your Person entity via scaffolding, the first thing we&#8217;ll do is define our Gender constants. We&#8217;ll define them as Hashes in order to also store their corresponding display name (you&#8217;ll see why when we adjust the Views). We&#8217;ll also add the validation of the gender property. Here&#8217;s what our Person class looks like now:</p>
<p><pre class="brush: ruby; wrap-lines: false;">
class Person &lt; ActiveRecord::Base   
  MALE = { :value =&gt; 0, :display_name =&gt; &quot;Male&quot; }
  FEMALE = { :value =&gt; 1, :display_name =&gt; &quot;Female&quot; }

  validates_inclusion_of :gender, :in =&gt; [MALE[:value], FEMALE[:value]]
end
</pre></p>
<p>The validates_inclusion_of definition in our class will make sure that only 0 or 1 are assigned/persisted to/with our Person instances. The next step is to adjust our Views to use our new convention.</p>
<h3>Fixing our Views</h3>
<p>Let&#8217;s go ahead and add a couple of methods in our Person class to help us with the displaying of gender in our Views. The first one is a class method that will give us the list of options to be displayed when we want to render a dropdown list for our new property. Add this method to your Person class:</p>
<p><pre class="brush: ruby; wrap-lines: false;">
def self.get_genders_dropdown
    options = {
      MALE[:display_name] =&gt; MALE[:value],
      FEMALE[:display_name] =&gt; FEMALE[:value]
    }
end
</pre></p>
<p>The second method will provide us with the corresponding gender string for the Person instance we&#8217;re handling at any point in time. Here it is:</p>
<p><pre class="brush: ruby; wrap-lines: false;">
def gender_displayname
    return gender == MALE[:value] ?
      MALE[:display_name] :
      FEMALE[:display_name]
end
</pre></p>
<p>Now that we&#8217;re armed with these &#8220;helper&#8221; methods (which we can actually unit test), let&#8217;s adjust our views. First, in the _form.html.erb file generated by scaffolding, find the line for our gender input field and replace it with this:</p>
<p><pre class="brush: ruby; wrap-lines: false;">
&lt;%= f.select(:gender, Person.get_genders_dropdown) %&gt;
</pre></p>
<p><em>Note: This will generate a dropdown. You could use radio buttons instead, which would be better in this case. I&#8217;ll leave that to you as an exercise.</em></p>
<p>The last step is to go ahead and display the right string for the instance gender on the Views where the user is shown info about the Person gender. In particular, look for index.html.erb and show.html.erb and use this code line to replace &#8220;person.gender&#8221;:</p>
<p><pre class="brush: ruby; wrap-lines: false;">
&lt;%= person.gender_displayname %&gt;
</pre></p>
<p>That&#8217;s it. This will give us the ability to store gender as 0 or 1 in our DB and display it as Male or Female (correspondingly) for our Person entity.</p>
<h3>Refactoring: Going the extra mile</h3>
<p>You may have noticed that our Person class is a little &#8220;unclean.&#8221; Besides, what if we have another entity in our domain model (e.g., Animal) that also has a gender. We don&#8217;t want to have to retype all that for our second (third, fourth&#8230;nth) entity. In <a title="Stackoverflow post discussing multiple rails models for gender validation" href="http://stackoverflow.com/questions/4383409/gender-validation-in-multiple-rails-models" target="_blank">this Stackoverflow post</a>, <a title="Jaime Bellmyer's blog" href="http://kconrails.com/" target="_blank">Jaime Bellmyer</a> explains a neat way to do this using Rails&#8217; plugin paradigm. Here&#8217;s a summary of the steps:</p>
<p>1) Extracting the common code out of our Person class: Basically add a new module in your rails&#8217; project lib folder that will contain the common code (I called the file acts_as_gendered.rb):</p>
<p><pre class="brush: ruby; wrap-lines: false;">
module ActsAsGendered
  MALE = { :value =&gt; 0, :display_name =&gt; &quot;Male&quot; }
  FEMALE = { :value =&gt; 1, :display_name =&gt; &quot;Female&quot; }
  
  def self.included(base)
    base.extend(ActsAsGenderedMethods)
  end
  
  module ActsAsGenderedMethods
    def acts_as_gendered
      extend ClassMethods
      include InstanceMethods
      
      validates_inclusion_of :gender, :in =&gt; [MALE[:value], FEMALE[:value]]
    end
  end
  
  module ClassMethods
    def get_genders_dropdown
      options = { 
        MALE[:display_name] =&gt; MALE[:value],
        FEMALE[:display_name] =&gt; FEMALE[:value]
      }
    end
  end
  
  module InstanceMethods
    def gender_displayname
      return gender == MALE[:value] ?
        MALE[:display_name] :
        FEMALE[:display_name]
    end
  end
end
</pre><br />
As you can tell some of the code applies to the class, whereas others to an instance of it; hence the need to extend/include the ClassMethods/InstanceMethods inner modules. The self.included method will just take care of the wiring when this module is mixed-in.</p>
<p>2) The next step is to automatically mix-in this new module on all our ActiveRecord::Base classes. This will save us some manual work when we want to add gender to an entity. To do this, add a new file under config/initializers (I called it gender.rb) with this code:</p>
<p><pre class="brush: ruby; wrap-lines: false;">
require 'acts_as_gendered'

ActiveRecord::Base.send(:include, ActsAsGendered)
</pre><br />
<em>Note: This is only called during the environment initialization, so if you already have a server instance running, you&#8217;d need to restart it before being able to use it (i.e., a simple update of an entity and reload of its views in rails won&#8217;t suffice).</em></p>
<p>3) The last step is to actually enable this new code in the appropriate entities. In our example, simple refactor your Person class to have this code:<br />
<pre class="brush: ruby; wrap-lines: false;">
class Person &lt; ActiveRecord::Base
  acts_as_gendered
end
</pre><br />
As you can see the acts_as_gendered() method is the only thing we need now to add gender to our entities. Don&#8217;t forget to use the get_genders_dropdown() and the gender_displayname() methods in the appropriate views and you are set. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iterativo.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iterativo.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iterativo.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iterativo.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iterativo.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iterativo.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iterativo.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iterativo.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iterativo.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iterativo.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iterativo.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iterativo.wordpress.com/131/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iterativo.wordpress.com/131/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iterativo.wordpress.com/131/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=131&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iterativo.wordpress.com/2010/12/26/modeling-a-discrete-property-in-a-rails-entity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/02bbe34a9a3e2e8cfe043d4e15814832?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Rafael</media:title>
		</media:content>
	</item>
		<item>
		<title>Unit-Testing BlackBerry Applications</title>
		<link>http://iterativo.wordpress.com/2010/12/14/unit-testing-blackberry-applications/</link>
		<comments>http://iterativo.wordpress.com/2010/12/14/unit-testing-blackberry-applications/#comments</comments>
		<pubDate>Wed, 15 Dec 2010 05:01:32 +0000</pubDate>
		<dc:creator>Rafael Torres</dc:creator>
				<category><![CDATA[BlackBerry Development]]></category>
		<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[BlackBerry BUnit UnitTesting]]></category>

		<guid isPermaLink="false">https://iterativo.wordpress.com/?p=102</guid>
		<description><![CDATA[I’ve been trying to find an easy way to unit test BlackBerry (BB) applications for a while. It is a little challenging for different reasons (e.g., several network resource dependencies.) Nonetheless, there’s some hope, as described in this post. If you design your app with SOLID principles, your core areas will become easier to unit [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=102&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I’ve been trying to find an easy way to unit test BlackBerry (BB) applications for a while. It is a little challenging for different reasons (e.g., several network resource dependencies.) Nonetheless, there’s some hope, as described in this <a href="http://supportforums.blackberry.com/t5/Java-Development/How-to-do-unit-testing-my-Blackberry-Application/td-p/289585/page/2">post</a>. If you design your app with <a href="http://en.wikipedia.org/wiki/Solid_(object-oriented_design)">SOLID</a> principles, your core areas will become easier to unit test. </p>
<p>There are a few frameworks that can help you unit-test your BB app; one of them is BUnit. This post describes how to use this framework to unit-test a simple BB Hello World app. Hopefully this will make it easier for some people to add automated tests to their BB apps.</p>
<h3>Assumptions</h3>
<p>You should have Java, Eclipse, and BB’s 4.5.0 JDK plugin already installed on your development environment (although it should work with different versions). You should also be familiar with basic BB development concepts. </p>
<h3>Design</h3>
<p>This is a simple HelloWorld app (nothing too fancy here). Below is its sequence diagram. Our unit test will be focusing on the HelloWorldRepository class. If you want to look at the final code source (including the unit test), you can download the source at <a title="git://github.com/iterativo/Blackberry-Hello-World.git" href="//github.com/iterativo/Blackberry-Hello-World.git">git://github.com/iterativo/Blackberry-Hello-World.git</a></p>
<p><a href="http://iterativo.files.wordpress.com/2010/12/helloworldsequencediagram1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:1em;border-width:0;" title="HelloWorldSequenceDiagram" border="0" alt="HelloWorldSequenceDiagram" src="http://iterativo.files.wordpress.com/2010/12/helloworldsequencediagram_thumb1.png?w=484&#038;h=202" width="484" height="202" /></a></p>
<h3>Adding BUnit to your project</h3>
<p>At this point, I’m assuming you’ve already created a BB project in Eclipse. After that, the first thing you’ll need to do is <a href="http://sourceforge.net/projects/b-unittesting/">download BUnit</a> (if you haven’t yet), unzip it and just copy the contents in src/jmunit into a new package folder in your BB project called test. This is what your project structure should look like so far:</p>
<p><a href="http://iterativo.files.wordpress.com/2010/12/projectstructure_1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="ProjectStructure_1" border="0" alt="ProjectStructure_1" src="http://iterativo.files.wordpress.com/2010/12/projectstructure_1_thumb.png?w=244&#038;h=140" width="244" height="140" /></a></p>
<h3>Test-driving the Implementation</h3>
<p>Let’s also assume that you’ve already implemented the HelloWorld and HelloWorldScreen classes in the sequence diagram. The HelloWorldScreen class is making a call to an unimplemented method in HelloWorldRepository. This is what HelloWorldRepository looks like so far:</p>
<pre><pre class="brush: java; wrap-lines: false;">
public class HelloWorldRepository
{
	public String getMessage()
	{
		return null;
	}
}
</pre></pre>
<p>Now let’s say you’re a good boy/girl and you buy into the whole <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a> idea. So before attempting to implement HelloWorldRepository, you want to create a unit test. This is where the fun begins. </p>
<p>So let’s add the first unit test on you test package folder and let’s call the class HelloWorldRepositoryTest. It will have one test for HelloWorldRepository’s getMessage() and another method to hook up a test runner (more on that later). Here’s what the test class looks like:</p>
<pre><pre class="brush: java; wrap-lines: false;">
public class HelloWorldRepositoryTest
{
	public void testShouldGetHelloWorldMessage() throws AssertionFailedException
	{
		HelloWorldRepository repository = new HelloWorldRepository();
		String message = repository.getMessage();
		Assertion.assertEquals(&quot;ShouldGetHelloWorldMessage&quot;, &quot;Hello World&quot;, message);
	}
	
	public void test(int testNumber) throws Throwable
	{
		switch(testNumber)
		{
			case 0: testShouldGetHelloWorldMessage(); break;
			default: break;
		}
	}
}
</pre></pre>
<p>Before we can run this test, we&#8217;ll need to do 3 more things. </p>
<ol>
<li>Add an alternate entry point to our HelloWorld project to be able to run our unit tests as a separate app. </li>
<li>Add a way to report the results. </li>
<li>Add a Test Runner, which will call our test(s). </li>
</ol>
<p>Let’s do this.</p>
<h3>Adding an alternate entry point for our tests</h3>
<p>You could implement a different way to call the unit tests, but I prefer to have a separate app icon on your phone that launches the tests. This is why I added an alternate entry point for this example. If you use this approach in your project, you’ll obviously need to make sure to not include this on your deployment code, but I’ll leave that to you to figure out. In the meantime, this is what your main() method will look like after adding the new entry point:</p>
<pre><pre class="brush: java; wrap-lines: false;">
public static void main(String[] args) 
{
	boolean startApp = false;
	boolean runTests = false;
	
	for (int i = 0; i &amp;lt; args.length; ++i) 
	{
		if (args[i].equals(&quot;helloworld&quot;)) startApp = true;
		if (args[i].equals(&quot;helloworldtest&quot;)) runTests = true; // name of the alternate entry point for your tests app
	}
	
	if (startApp)
	{
	    	HelloWorld theApp = new HelloWorld();
	    	theApp.enterEventDispatcher();
    	}
	
	if (runTests)
	{
		HelloWorldTestRunner testRunner = new HelloWorldTestRunner();
		testRunner.enterEventDispatcher();
	}
}
</pre></pre>
<p>Make sure to make the corresponding changes to BlackBerry_App_Descriptor.xml as well. Notice that this new entry point is calling our test runner. Let’s create it.</p>
<h3>Adding a Test Runner</h3>
<p>This is the class that will be called when the test app launches (through the alternate entry point). Its responsibility is to run the unit tests and delegate the test result reporting to the corresponding class. Here’s what it looks like for our example:</p>
<pre><pre class="brush: java; wrap-lines: false;">
public class HelloWorldTestRunner extends UiApplication
{
	public HelloWorldTestRunner()
	{
		HelloWorldRepositoryTest repositoryTest = new HelloWorldRepositoryTest();
		try 
		{
			repositoryTest.test(0);
       		} catch (Throwable ex) {
            		System.out.println(&quot; ---&gt; &quot;; + ex.toString());
            		ex.printStackTrace();
       		}
        
       		pushScreen(new UnitTestResultsScreen());
	}
}
</pre></pre>
<p>Now the last step is to go ahead and create the test result reporting class. </p>
<h3>Adding a Test Result Reporter</h3>
<p>Straight up from the BUnit example (included in the downloaded zip file), just copy/paste the UnitTestResultScreen class in your test package folder. This is basically the screen that will show up with the test results summary.</p>
<h3>Running the Test </h3>
<p>At this point you should be able to compile/launch your project using the BB simulator. Once your simulator is up, you should see a new icon to launch your tests – it will have the name you gave it when you defined the alternate entry point on your Blackberry_App_Descriptor.xml. Launch it and you should get this screen:</p>
<p><a href="http://iterativo.files.wordpress.com/2010/12/failingtest.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="failingTest" border="0" alt="failingTest" src="http://iterativo.files.wordpress.com/2010/12/failingtest_thumb.png?w=347&#038;h=310" width="347" height="310" /></a></p>
<p>Great! You have a failing test with a descriptive message. You may be thinking whaaaat? Well, remember we’re doing TDD. You’re supposed to get a failing test first. Now let’s make it pass.</p>
<h3>Making the Test Pass</h3>
<p>To do this, let’s fix HelloWorldRepository.getMessage(). Here it is:</p>
<pre><pre class="brush: java; wrap-lines: false;">
public class HelloWorldRepository
{
	public String getMessage()
	{
		return &quot;Hello World&quot;;
	}
}
</pre></pre>
<p>And let&#8217;s run the tests again. This time you should see your test pass: </p>
<p><a href="http://iterativo.files.wordpress.com/2010/12/passingtest.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;" title="passingTest" border="0" alt="passingTest" src="http://iterativo.files.wordpress.com/2010/12/passingtest_thumb.png?w=347&#038;h=298" width="347" height="298" /></a></p>
<p>Voilà!</p>
<h3>Going Forward</h3>
<p>If you’re used to JUnit (or any XUnit framework for that fact), you may have noticed we did some things manually (like wiring up the test to the runner). Unfortunately, BB is based on J2ME, which doesn’t support <a href="http://en.wikipedia.org/wiki/Reflection_(computer_science)">Reflection</a>, so you have to take care of managing the wiring. In our case that means you’ll have to update the TestRunner with any new tests you add. That’s a price you should be willing to pay, as the benefits unit-testing brings you can let you sleep really well at night (especially when your project starts growing). </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iterativo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iterativo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iterativo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iterativo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iterativo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iterativo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iterativo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iterativo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iterativo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iterativo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iterativo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iterativo.wordpress.com/102/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iterativo.wordpress.com/102/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iterativo.wordpress.com/102/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=102&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iterativo.wordpress.com/2010/12/14/unit-testing-blackberry-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/02bbe34a9a3e2e8cfe043d4e15814832?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Rafael</media:title>
		</media:content>

		<media:content url="http://iterativo.files.wordpress.com/2010/12/helloworldsequencediagram_thumb1.png" medium="image">
			<media:title type="html">HelloWorldSequenceDiagram</media:title>
		</media:content>

		<media:content url="http://iterativo.files.wordpress.com/2010/12/projectstructure_1_thumb.png" medium="image">
			<media:title type="html">ProjectStructure_1</media:title>
		</media:content>

		<media:content url="http://iterativo.files.wordpress.com/2010/12/failingtest_thumb.png" medium="image">
			<media:title type="html">failingTest</media:title>
		</media:content>

		<media:content url="http://iterativo.files.wordpress.com/2010/12/passingtest_thumb.png" medium="image">
			<media:title type="html">passingTest</media:title>
		</media:content>
	</item>
		<item>
		<title>Hooking up log4net to ASP.NET using HttpModule</title>
		<link>http://iterativo.wordpress.com/2010/10/14/hooking-up-log4net-to-asp-net-using-httpmodule/</link>
		<comments>http://iterativo.wordpress.com/2010/10/14/hooking-up-log4net-to-asp-net-using-httpmodule/#comments</comments>
		<pubDate>Fri, 15 Oct 2010 00:05:56 +0000</pubDate>
		<dc:creator>Rafael Torres</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[log4net]]></category>

		<guid isPermaLink="false">https://iterativo.wordpress.com/?p=94</guid>
		<description><![CDATA[Caveat: This post is more for future self-reference than anything. A client recently asked us to troubleshoot an asp.net web app that was generating a exception upon validating/submitting a particular windows certificate. The trace log seemed to point to a problem with the certificate itself, but we didn’t have access to it. Unfortunately the existing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=94&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Caveat: This post is more for future self-reference than anything.</p>
<p>A client recently asked us to troubleshoot an asp.net web app that was generating a exception upon validating/submitting a particular windows certificate. The trace log seemed to point to a problem with the certificate itself, but we didn’t have access to it. Unfortunately the existing validation code didn’t have any logging in itself to get more feedback. Another challenge was that this app was mainly written in php with a small web service api written in C#. The code throwing the exception was in this api, so we decided to add some log4net logging to help us with this task. Here’s a summary of what we did:</p>
<h3>Configuring log4net</h3>
<p>We tried multiple configurations we found on the web (via Web.config or even Global.asax), but here’s the one that worked for us:</p>
<p>Using a custom HttpModule:</p>
<p><pre class="brush: csharp; wrap-lines: false;">    
public class Log4NetModule : IHttpModule
{
    private static bool _configured = false;

    public void Init(HttpApplication context)
    {
        context.BeginRequest += new EventHandler(context_BeginRequest);
    }

    void context_BeginRequest(object sender, EventArgs e)
    {
        if (!_configured)
        {
            InitializeLog4Net();
            _configured = true;
        }
    }

    public void Dispose()
    {
        // Do nothing
    }

    private void InitializeLog4Net()
    {
        var layout = new log4net.Layout.PatternLayout(@&quot;%d [%t]%-5p %c [%x] &amp;lt;%X{auth}&amp;gt; - %m%n&quot;);
        var logfile = Path.Combine(Path.Combine(HttpContext.Current.Request.PhysicalApplicationPath, &quot;Logs&quot;), &quot;log.txt&quot;);
        var rollingFileAppender = new RollingFileAppender
        {
            Threshold = Level.All,
            AppendToFile = true,
            Layout = layout,
            File = logfile,
            MaxFileSize = 1000 * 1024
            RollingStyle = RollingFileAppender.RollingMode.Date,
            DatePattern = &quot;Date&quot;,
            StaticLogFileName = true,
        };

        layout.ActivateOptions();
        rollingFileAppender.ActivateOptions();
        log4net.Config.BasicConfigurator.Configure(rollingFileAppender);
    }
}
</pre></p>
<p>Note this line of code:<br />
HttpContext.Current.Request.PhysicalApplicationPath<br />
// This returns the app’s current dir. Use this instead of Directory.GetCurrentDirectory()</p>
<p>Using this approach, this is the only change needed in Web.config:</p>
<p><pre class="brush: xml; wrap-lines: false;">
  &lt;system.web&gt;
    &lt;httpmodules&gt;
      &lt;add name=&quot;Log4NetModule&quot; type=&quot;E222.OrderValidationService.Log4NetModule,E222.OrderValidationService&quot; /&gt;
    &lt;/httpmodules&gt;
  &lt;/system.web&gt;
</pre></p>
<h3>Adding the log statements</h3>
<p>After this, the logging statements were ready to be put in place. E.g.:</p>
<p><pre class="brush: csharp; wrap-lines: false;">
var log = log4net.LogManager.GetLogger(typeof(MyClass));
log.Debug(&amp;quot;My debug message&amp;quot;);
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iterativo.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iterativo.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iterativo.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iterativo.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iterativo.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iterativo.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iterativo.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iterativo.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iterativo.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iterativo.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iterativo.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iterativo.wordpress.com/94/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iterativo.wordpress.com/94/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iterativo.wordpress.com/94/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=94&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iterativo.wordpress.com/2010/10/14/hooking-up-log4net-to-asp-net-using-httpmodule/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/02bbe34a9a3e2e8cfe043d4e15814832?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Rafael</media:title>
		</media:content>
	</item>
		<item>
		<title>Using jquery to Communicate Between Browser Windows</title>
		<link>http://iterativo.wordpress.com/2010/03/24/using-jquery-to-communicate-between-browser-windows/</link>
		<comments>http://iterativo.wordpress.com/2010/03/24/using-jquery-to-communicate-between-browser-windows/#comments</comments>
		<pubDate>Wed, 24 Mar 2010 17:13:54 +0000</pubDate>
		<dc:creator>Rafael Torres</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://iterativo.wordpress.com/?p=84</guid>
		<description><![CDATA[Recently I ran into a scenario in which I wanted some update to happen on a browser window based on an event that happened on a child window (i.e., a popup that had been launched by the main browser window). I did some googling and found this jquery plugin: jquery.windowmsg-1.0.js Here’s a little tutorial on [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=84&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I ran into a scenario in which I wanted some update to happen on a browser window based on an event that happened on a child window (i.e., a popup that had been launched by the main browser window). I did some googling and found this jquery plugin: jquery.windowmsg-1.0.js</p>
<p>Here’s a little <a title="JQuery WindowMsg plugin tutorial" href="http://www.sfpeter.com/2008/03/13/communication-between-browser-windows-with-jquery-my-new-plugin/">tutorial</a> on how to use it.</p>
<p>In my case, since I only needed to communicate from the child window to the parent, this is what I had to do:</p>
<p>On the parent aspx, I added this JS snippet:</p>
<p><pre class="brush: jscript; wrap-lines: false;">
$.initWindowMsg(); // initializes the plugin
$.windowMsg('eventName',  function(message){
	// jquery to respond to the message coming from the child
});
</pre></p>
<p>On the child aspx, here&#8217;s the corresponding snippet:</p>
<p><pre class="brush: jscript; wrap-lines: false;">
$.triggerParentEvent('eventName')
</pre></p>
<p>That&#8217;s it. I actually wrapped the child aspx snippet around a jquery click() event for the intended HTML element, and voilà &#8211; everytime I clicked on that element on the child window a status update would happen on the parent.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iterativo.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iterativo.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iterativo.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iterativo.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iterativo.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iterativo.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iterativo.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iterativo.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iterativo.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iterativo.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iterativo.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iterativo.wordpress.com/84/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iterativo.wordpress.com/84/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iterativo.wordpress.com/84/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=84&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iterativo.wordpress.com/2010/03/24/using-jquery-to-communicate-between-browser-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/02bbe34a9a3e2e8cfe043d4e15814832?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Rafael</media:title>
		</media:content>
	</item>
		<item>
		<title>Strongly-Typed UI tests</title>
		<link>http://iterativo.wordpress.com/2010/03/09/strongly-typed-ui-tests/</link>
		<comments>http://iterativo.wordpress.com/2010/03/09/strongly-typed-ui-tests/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 19:26:17 +0000</pubDate>
		<dc:creator>Rafael Torres</dc:creator>
				<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[Automapper]]></category>
		<category><![CDATA[Autopilot]]></category>
		<category><![CDATA[WatiN]]></category>

		<guid isPermaLink="false">http://iterativo.wordpress.com/2010/03/09/strongly-typed-ui-tests/</guid>
		<description><![CDATA[One of the advantages that writing UI test in the same language as the AUT is written, is the ability to use part of the same View logic to author your tests. Moreover, in our case, this has allowed us to strongly link our View page with our tests. Here’s how: Let me try to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=83&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the advantages that writing UI test in the same language as the AUT is written, is the ability to use part of the same View logic to author your tests. Moreover, in <a title="Headspring, LC" href="http://www.headspring.com">our</a> case, this has allowed us to strongly link our View page with our tests. </p>
<p>Here’s how:</p>
<p><a href="http://iterativo.files.wordpress.com/2010/03/staticallytypeduitests.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="StaticallyTypedUITests" border="0" alt="StaticallyTypedUITests" src="http://iterativo.files.wordpress.com/2010/03/staticallytypeduitests_thumb.png?w=450&#038;h=251" width="450" height="251" /></a> </p>
<p>Let me try to explain this better:</p>
<p><strong>1. Leveraging Automapper</strong></p>
<p>If you’re familiar with tools like WatiN or Selenium, you understand that an important part of testing your web pages is having unique identifiers on your page elements (via id, class, or any other XHTML valid attribute) that allow you to locate them on a page. Imagine having to do this manually for each page/element and keeping it updated with your test code. That’s a significant cost to your project. So the first thing that we did was to automate this generation, through <a href="http://www.codeplex.com/AutoMapper">Automapper</a>, which we already were using to map our Domain Model objects to our UI Model ones (see diagram). All we did was to add a new implementation of IValueFormatter, called SpanWrappingFormatter, whose responsibility is to add an HTML span tag around the mapped elements with a unique identifier resolved from its member name via reflection. Here is what it looks like:</p>
<pre><pre class="brush: csharp; wrap-lines: false;">
public class SpanWrappingFormatter : IValueFormatter
{
	public string FormatValue(ResolutionContext context)
	{
		string camelCaseMemberName = context.MemberName.ToLowerCamelCase();
		return string.Format(@&amp;quot;&lt;span  {0}??&gt;{1}&lt;/span&gt;&amp;quot;, camelCaseMemberName, context.SourceValue);
	}
}
</pre></pre>
<p><strong>2. Strongly-typed views</strong></p>
<p>After having the previous step, it is pretty easy to have ASP.NET MVC add the element identifiers we need for our UI tests, as they are now part of the UI model property values. Simply resolving to the property value on the view does the trick.</p>
<p><strong>3. Strongly-typed UI tests via AutoPilot-dotnet</strong></p>
<p>The last step is to have a middle layer in your UI test engine to help you locate page elements while resolving its corresponding identifier via reflection, based on the provided UI Model Type. In our case, mostly due to Nick Becker’s effort, we built a DSL framework that allows us to do that (via WatiN). If you’re interested in looking at the code for this framework, <a title="Mahendra Mavani&#39;s blog" href="http://www.mahendramavani.com/">Mahendra Mavani</a> has created a google project for it called <a title="AutoPilot source code" href="http://code.google.com/p/autopilot-dotnet/">AutoPilot-dotnet</a>. With that in place, all we need to do is use this api in our UI tests in order to drive browser interaction (see diagram for a code snippet).</p>
<p><strong>Lesson learned</strong></p>
<p>This approach has allowed us to significantly speed up our UI test development time. The fact that we have leveraged different technologies to strongly link our UI Model to our UI/Acceptance tests, along with being able to use a fluent interface to drive them, make our UI test suite easier to create, more robust and more maintainable.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iterativo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iterativo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iterativo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iterativo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iterativo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iterativo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iterativo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iterativo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iterativo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iterativo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iterativo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iterativo.wordpress.com/83/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iterativo.wordpress.com/83/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iterativo.wordpress.com/83/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=83&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iterativo.wordpress.com/2010/03/09/strongly-typed-ui-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/02bbe34a9a3e2e8cfe043d4e15814832?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Rafael</media:title>
		</media:content>

		<media:content url="http://iterativo.files.wordpress.com/2010/03/staticallytypeduitests_thumb.png" medium="image">
			<media:title type="html">StaticallyTypedUITests</media:title>
		</media:content>
	</item>
		<item>
		<title>How to get started with Test Automation</title>
		<link>http://iterativo.wordpress.com/2010/03/02/how-to-get-started-with-test-automation/</link>
		<comments>http://iterativo.wordpress.com/2010/03/02/how-to-get-started-with-test-automation/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 14:55:43 +0000</pubDate>
		<dc:creator>Rafael Torres</dc:creator>
				<category><![CDATA[Software Testing]]></category>

		<guid isPermaLink="false">http://iterativo.wordpress.com/?p=76</guid>
		<description><![CDATA[A buddy of mine, who is in QA, recently asked me for advice on how to get started on test automation on an existing web application. If you’re on the same boat, here’s my advice: Start with small steps. Pick a test scenario (at the UI-level) that you want to automate that will give you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=76&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A buddy of mine, who is in QA, recently asked me for advice on how to get started on test automation on an existing web application. If you’re on the same boat, here’s my advice:</p>
<ol>
<li>Start with small steps. Pick a test scenario (at the UI-level) that you want to automate that will give you a better perspective of the effort required. A great candidate is the (build deploy) smoke tests, as they tend to cover the most commonly traversed paths of your application. Plus it’s a test that you’re prone to use very frequently, so the re-usage tends to be great.</li>
<li>After you have a scenario in mind, pick a tool to do the job. You may want to spend a little time researching this, but don’t overdo it. Don’t fall on the (waterfall-like) trap that “everything” has to be perfect from a design point before implementing code. I guarantee you that if you’re new to test automation, you will not have the necessary experience to pick the “best” tool for your job (if there were such a thing). So the best thing here is to do a little bit of tools research based on your system and start automating asap. To begin with, you may want to consider an open-source tool. They’re free and usually have plenty of online resources to help you along the way. They are also very reliable and use mainstream languages as their input (Ruby, C#, Java…) which may be appealing to your organization. I would suggest you start playing with either Watir (or any of its favors – WatiN, WatiJ…) or Selenium. One more thing: stay away from the record-and-play tools &#8211; their ROI is very low as their output scripts tend to have very low reusability, or they require heavy manipulation after creation to fit your long-term needs. </li>
<li>Once you have a better grasp of UI-test automation, start familiarizing yourself with the application codebase (if you haven’t yet). Traditionally, testers never look at the code they’re trying to test (they operate in a more black-box manner). However, in my experience efficient test automation is done in a white-box manner. If you don’t know the language the application is written in, start with doing some googling on it. Nowadays, chances are the application is written in a <a href="http://en.wikipedia.org/wiki/Object-oriented_programming">OO</a> language. If that’s the case, I would suggest you start with an easy-to-learn OO language to get a better grasp of those concepts in your head before jumping into more in-depth OO languages. If you asked me to give you a straight suggestion here, I would tell you start learning <a href="http://www.ruby-lang.org/en/">Ruby</a>. Get a hold of the <a href="http://www.pragprog.com/titles/ruby/programming-ruby">Pickaxe book</a> and review as much of it as you can (with a hands-on approach). The purpose of all this is to give you a better approach on automating tests as a whole. You will probably come to realize on your own that you should not rely on UI-level tests only. </li>
<li>Keep in mind that a test automation project should be treated as any other software project. You should consider best-practice software design and architecture principles like with any other relevant codebase. At various stages of its lifetime, it will require redesign, refactoring, maintenance&#8230; Basically, treat it as a first-class citizen, or otherwise it will grow up to be a maintenance headache with close-to-little <a href="http://www.investopedia.com/terms/r/returnoninvestment.asp">ROI</a> value. On this matter, search for guidance from more-experienced developers within your organization if possible. Discuss with them alternative design ideas. Show them your code every once in a while and get feedback from them. Get them involved in the automation effort.</li>
</ol>
<p><strong>Common misconceptions</strong></p>
<ul>
<li>a) Automation will replace manual testing: </li>
</ul>
<p>Keep in mind that test automation should NOT and does NOT replace manual testing. There is plenty of research that proves this (read up on <a href="http://www.kaner.com/">Cem Kaner</a>’s material if you’re interested). So if you’re thinking that your test automation effort is going to replace manual testing, think twice. You may be taking a huge risk. What you should strive for is a good/intelligent balance between them (which will depend on your situation).</p>
<ul>
<li>b) Automate “everything”:</li>
</ul>
<p>I’ve heard this statement a few times before. IMHO, this is the wrong approach to test automation. When faced with this idea, consider what is “everything”? It would probably take you eons to figure out all the possible test scenarios your system can be faced with. Then, even if you were to figure them out, it would take you quite a long time to automate them all. Moreover, your system is a living/changing animal. By the time you realize it, your application will have changed so much that previous tests would be outdated at best or obsolete at worst. Instead, consider adopting a <a href="http://en.wikipedia.org/wiki/Pareto_principle">more pragmatic approach</a>, especially when it comes to system-level tests. As mentioned before, an efficient automation approach considers automating tests at different levels (unit, integration, acceptance tests).</p>
<ul>
<li>c) Automation will get rid of all bugs:</li>
</ul>
<p>Like I said before, test automation is effectively a software project on its own; therefore, it is bound to have the same limitations and flaws – from design to implementation. Moreover, some of your scenarios will not be automatable (or simply not good candidates for it). On the other hand, some scenarios will be great candidates for automation. Expect bugs to still flourish even after having an automated test suite. However, learn from them to make your suite more robust. In my experience, having a strong automation suite makes an application way less buggy and enduring. Invest time and money on this front, and you won’t regret it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iterativo.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iterativo.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iterativo.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iterativo.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iterativo.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iterativo.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iterativo.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iterativo.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iterativo.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iterativo.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iterativo.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iterativo.wordpress.com/76/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iterativo.wordpress.com/76/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iterativo.wordpress.com/76/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=76&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iterativo.wordpress.com/2010/03/02/how-to-get-started-with-test-automation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/02bbe34a9a3e2e8cfe043d4e15814832?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Rafael</media:title>
		</media:content>
	</item>
		<item>
		<title>Bypassing JavaScript dialogs for WatiN tests</title>
		<link>http://iterativo.wordpress.com/2010/02/19/bypassing-javascript-dialogs-for-watin-tests/</link>
		<comments>http://iterativo.wordpress.com/2010/02/19/bypassing-javascript-dialogs-for-watin-tests/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 14:07:44 +0000</pubDate>
		<dc:creator>Rafael Torres</dc:creator>
				<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[Environment Configuration]]></category>
		<category><![CDATA[WatiN]]></category>

		<guid isPermaLink="false">http://iterativo.wordpress.com/?p=60</guid>
		<description><![CDATA[As described in a previous blog post, we wanted to implement a practical way to disable JavaScript (JS) dialogs for our automated UI test environments. At first, we were reading the configuration directly from the aspx pages that had some JS, in order to accommodate for the new behavior (a very non-DRY approach). Then we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=60&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As described in a <a href="http://wp.me/pmz6o-L">previous blog post</a>, we wanted to implement a practical way to disable JavaScript (JS) dialogs for our automated UI test environments.</p>
<p>At first, we were reading the configuration directly from the aspx pages that had some JS, in order to accommodate for the new behavior (a very non-DRY approach). Then we figured we could abstract that logic to some helper method and call the method from the aspx’s (a slightly better approach, but still not as simple as we’d like it to be). Then, one day, <a href="http://jeffreypalermo.com/">Jeffrey Palermo</a> shouted “isn’t JS a dynamic language?”. And that was the key to our next approach.</p>
<p>With dynamic languages, it is very easy to override native function/method behavior. Simply declare a new function/method with the same name of the one you want to override (within the scope in which you want to use it), and implement your new desired behavior. I used to do this with Ruby, so it was easy for me to figure out how to do it in JS. </p>
<p>For example, in our case one of the functions we wanted to override was confirm(). All we had to do was add this piece of code in our master pages and voila:</p>
<pre><pre class="brush: csharp; wrap-lines: false;">
&lt;% if (ObjectFactory.GetInstance&lt;iconfiguration&gt;().ShouldAdaptToUiTesting()){ %&gt;
	&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
		/* &lt;![CDATA[ */
			function confirm() { return true }
		/* ]]&gt; */
	&lt;/script&gt;
&lt;% } %&gt;
</pre></pre>
<p>What this is saying is basically, always return true when your page asks for a JS confirmation from the user if you are working in a UI-test environment. What it does is it bypasses any JS confirm box when clicking on an element with this event, as if the user had clicked OK on it. Once we had this in our master page, all of our application pages would automatically inherit this behavior. No more need to have a helper method, or for that matter, having to remember to invoke some other code when creating the aspx&#8217;s in order to do this. IMHO, this is a more elegant and simple way to handle this situation.</p>
<p>Here&#8217;s a broader diagram explaining the approach we used: </p>
<p><a href="http://iterativo.files.wordpress.com/2010/02/overridingjavascriptdialogsinaspnetmvc.png"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="OverridingJavaScriptDialogsInAspNetMvc" border="0" alt="OverridingJavaScriptDialogsInAspNetMvc" src="http://iterativo.files.wordpress.com/2010/02/overridingjavascriptdialogsinaspnetmvc_thumb.png?w=604&#038;h=412" width="604" height="412" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/iterativo.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/iterativo.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/iterativo.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/iterativo.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/iterativo.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/iterativo.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/iterativo.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/iterativo.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/iterativo.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/iterativo.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/iterativo.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/iterativo.wordpress.com/60/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/iterativo.wordpress.com/60/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/iterativo.wordpress.com/60/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=iterativo.wordpress.com&amp;blog=5378152&amp;post=60&amp;subd=iterativo&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://iterativo.wordpress.com/2010/02/19/bypassing-javascript-dialogs-for-watin-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/02bbe34a9a3e2e8cfe043d4e15814832?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Rafael</media:title>
		</media:content>

		<media:content url="http://iterativo.files.wordpress.com/2010/02/overridingjavascriptdialogsinaspnetmvc_thumb.png" medium="image">
			<media:title type="html">OverridingJavaScriptDialogsInAspNetMvc</media:title>
		</media:content>
	</item>
	</channel>
</rss>
