<?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>.Net Life</title>
	<atom:link href="http://david-yancey.com/dy/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://david-yancey.com/dy</link>
	<description>Just another WordPress site</description>
	<lastBuildDate>Thu, 05 Jan 2012 00:45:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Agile and the .NET Community</title>
		<link>http://david-yancey.com/dy/?p=6</link>
		<comments>http://david-yancey.com/dy/?p=6#comments</comments>
		<pubDate>Wed, 04 Jan 2012 00:40:20 +0000</pubDate>
		<dc:creator>davidyancey</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://david-yancey.com/dy/?p=6</guid>
		<description><![CDATA[Why does it seem that the .NET Community isn&#8217;t very active in the Agile community?&#160; I know that there are Agile practitioners in various .NET shops however, it seems that the overall representation is very minimal.&#160; Is it because of a lack of understanding of the Agile methodologies? Or is there a lack of support [...]]]></description>
			<content:encoded><![CDATA[<p>Why does it seem that the .NET Community isn&#8217;t very active in the Agile community?&#160; I know that there are Agile practitioners in various .NET shops however, it seems that the overall representation is very minimal.&#160; Is it because of a lack of understanding of the Agile methodologies? Or is there a lack of support and resources for the .NET community when it comes to Agile practices?</p>
<p>I just got back from the <a href="http://www.sqe.com/agiledevpractices/">Agile Development Practices</a> by <a href="http://www.sqe.com">SQE</a> and I felt like I was in the minority there.&#160; As I went from sessions on TDD to Design Patterns to Refactoring each time it was asked what platform each of the developers were on I was one of 2 or 3 that mentioned .NET.&#160; The majority was Java with a small representation of Ruby developers, which on one hand I&#8217;m glad because I got a great exposure to Java and Ruby, however on the other hand it raises the questions as to why.</p>
<p>So what is Agile?</p>
<p><a href="http://www.agilemanifesto.org/">Agile Manifesto</a>:</p>
<blockquote><p><strong>Individuals and interactions</strong> over processes and tools      <br /><strong>Working software</strong> over comprehensive documentation      <br /><strong>Customer collaboration</strong> over contract negotiation      <br /><strong>Responding to change</strong> over following a plan</p>
<p>That is, while there is value in the items on     <br />the right, we value the items on the left more.</p>
</blockquote>
<p>Looking at the <a href="http://www.agilemanifesto.org/principles.html">principles behind the manifesto</a> we see more of what really is the driving force of the Agile movement and begin to understand why it is important to all developers to grasp this concept.</p>
<blockquote><ol>
<li>Our highest priority is to <strong>satisfy the customer</strong>        <br />through <strong>early and continuous delivery</strong>        <br />of valuable software. </li>
<li><strong>Welcome changing requirements</strong>, even late in        <br />development. Agile processes harness change for        <br />the <strong>customer&#8217;s competitive advantage</strong>. </li>
<li><strong>Deliver working software frequently</strong>, from a        <br />couple of weeks to a couple of months, with a        <br />preference to the shorter timescale. </li>
<li><strong>Business people and developers must work         <br />together</strong> daily throughout the project. </li>
<li><strong>Build projects around motivated individuals</strong>.        <br />Give them the environment and support they need,        <br />and trust them to get the job done. </li>
<li>The most efficient and effective method of       <br />conveying information to and within a development        <br />team is <strong>face-to-face conversation.</strong> </li>
<li><strong>Working software is the primary measure of progress.</strong> </li>
<li>Agile processes <strong>promote sustainable development</strong>.        <br />The sponsors, developers, and users should be able        <br />to maintain a constant pace indefinitely. </li>
<li><strong>Continuous attention to technical excellence         <br />and good design</strong> enhances agility. </li>
<li><strong>Simplicity</strong>&#8211;the art of maximizing the amount        <br />of work not done&#8211;is essential. </li>
<li>The best architectures, requirements, and designs       <br />emerge from<strong> self-organizing teams</strong>. </li>
<li>At regular intervals, the <strong>team reflects</strong> on how        <br />to become more effective, then tunes and adjusts        <br />its behavior accordingly. </li>
</ol>
</blockquote>
<p>The early continuous delivery of quality working software through continuous attention to simplicity, technical excellence, good design where the business and developers form a team to work together frequently reflecting how to become more effective through self organization.</p>
<p>This is just the beginning however, Agile goes beyond just what is stated in the manifesto.&#160; There are methodologies for all aspects of the business, from the executives with <a href="http://www.poppendieck.com/">LEAN</a>, to the team with <a href="http://www.controlchaos.com/">SCRUM</a> down to the individual developers with <a href="http://www.extremeprogramming.org/rules.html">XP (Extreme Programming).</a>&#160; Some of the concepts with in XP will be quite familiar to the .NET community, such as Test Driven Development (TDD) and Pair Programming.</p>
<p>I want to encourage all developers to really look into what Agile has to offer and then take it to your business and challenge them to implement Agile as your new methodology.&#160; If you are already doing Agile then start speaking up about it.&#160; Make your presence known and help evangelize Agile in the .NET community.</p>
<p>David Yancey</p>
]]></content:encoded>
			<wfw:commentRss>http://david-yancey.com/dy/?feed=rss2&#038;p=6</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting to Testable Code</title>
		<link>http://david-yancey.com/dy/?p=4</link>
		<comments>http://david-yancey.com/dy/?p=4#comments</comments>
		<pubDate>Wed, 04 Jan 2012 00:38:32 +0000</pubDate>
		<dc:creator>davidyancey</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Tests]]></category>

		<guid isPermaLink="false">http://david-yancey.com/dy/?p=4</guid>
		<description><![CDATA[While TDD (Test Driven Development) isn’t a new concept for developers, for many it is still a foreign concept. It’s a complete paradigm shift, to change your thinking of writing your test first then the code. What purpose does it serve to write a test you know isn’t going to pass, only to later write the code to make the test pass?]]></description>
			<content:encoded><![CDATA[<p>While TDD (Test Driven Development) isn’t a new concept for developers, for many it is still a foreign concept. It’s a complete paradigm shift, to change your thinking of writing your test first then the code. What purpose does it serve to write a test you know isn’t going to pass, only to later write the code to make the test pass?</p>
<p>Today we are going to look at a different approach to TDD and how we can utilize this approach to guide us to higher quality, testable code.&#160; You will also notice that we will end up with tests that can be included in our unit test suite.</p>
<p>Before we begin however I want to go over a few myths usually associated with TDD.</p>
<p><strong>1. When doing TDD no code should be written that doesn’t have a test associated.</strong></p>
<p>In a perfect world this would be ideal, however we don’t live in a perfect world and this is really just unreasonable. In actuality, what we want to achieve is all code that fulfills a business rule has an associated test. A business rule is defined as a behavior that meets a specific business requirement. For example: Interest calculation based upon the terms of a loan would be a business requirement, where as the color of a button would not.</p>
<p><strong>2. TDD is the same as Unit Test development.</strong></p>
<p>TDD isn’t about testing your code, it is about using test to confirm your functionality and design, where as Unit Test is about the continued confirmation of existing behaviors.&#160; Now that having been said, while TDD isn’t Unit Testing, the tests created during your TDD sessions should morph into behavioral unit tests.</p>
<p><strong>3.&#160; Code Coverage needs to be 95% or better.</strong></p>
<p>If you don’t have 100% code coverage from your TDD code, then you need to re-evaluate your approach.&#160; Where 95% code coverage becomes difficult is when you are building unit tests for your legacy code.&#160; In your unit test development, set your goal to have 90%+ behavioral code coverage.&#160; We will go over some tips on how to approach this later on.</p>
<p><strong>Red | Green | Re-Factor </strong></p>
<p>Red | Green | Re-Factor has been the standard approach to TDD since its inception with good reason.&#160; It teaches you to code only what you need to make the test pass, and then re-factor the code so that it is clean code, is extensible, and doesn’t violate any of the S.O.L.I.D principles.&#160; Do this enough and you will be able to visualize your code meeting these requirements before you write your first test, which will lead to TWD (Test While Developing).&#160; However; be careful, and don’t allow yourself to get “lazy” and not write any tests.</p>
<p><strong>YAGNI</strong></p>
<p>You Ain’t Going to Need It.&#160; This is the concept of developing only what you need, when you need it.&#160; While this is an important principle, and TDD helps meet this principle, it is important to make sure we don’t develop that will force us into violating the Open/Closed principle.</p>
<p><strong>DRY</strong></p>
<p>Don’t Repeat Yourself.&#160; While this concept is self-explanatory, it’s worth mentioning here.&#160; <a href="http://www.netobjectives.com/bio-alan-shalloway">Alan Shalloway</a> created his own <a href="http://www.netobjectives.com/blogs/shalloways-law-and-shalloways-principle">law</a> which goes like :</p>
<blockquote><p>“When N things need to change and N&gt;1, Shalloway will find at most N-1 of these things.”</p>
</blockquote>
<p>Encapsulation helps avoid violating this law.</p>
<p>Business / Behavioral Requirements:&#160; Before you even write your first test, make sure you have your user story complete with any business agreements.&#160; You will also need any User Acceptance Tests (UAT’s) which will help define when the behavior is considered done.&#160; Even if this is a spike session, you need these items to understand what you are going to develop.</p>
<p><strong>The Approach</strong></p>
<p><a href="http://www.david-yancey.com/Media/Default/Windows-Live-Writer/GettingtoTestableCode_13C11/image_2.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://www.david-yancey.com/Media/Default/Windows-Live-Writer/GettingtoTestableCode_13C11/image_thumb.png" width="244" height="184" /></a></p>
<p><strong>Business Case</strong></p>
<p>To better understand how this approach works, we are going to work through typical business case for a financial corporation.&#160; Our financial corporation needs a to calculate a payment schedule for a car loan.&#160; Given that we have the loan amount, interest rate, and term of loan, then we should be able to calculate the amount of payment for the length of the loan.&#160; Note:&#160; we now have a user story and user acceptance test.</p>
<p><strong>Functional Test</strong></p>
<p><img style="border-right-width: 0px; margin: 5px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" align="left" src="http://www.david-yancey.com/Media/Default/Windows-Live-Writer/GettingtoTestableCode_13C11/image_5.png" width="160" height="91" />The formula to determine the payment amount is highly available all over the internet.&#160; In our first test we will be testing our code version of the formula to confirm we have translated the formula over to code correctly.&#160; As you work through your tests remember to keep in mind the core concepts (Red|Green|Re-Factor, Yagni, DRY).</p>
<pre class="csharpcode">[<span class="system">Test</span>]
<span class="kwrd">public</span> <span class="kwrd">void</span> ShouldCalculatePayment()
{
    <span class="kwrd">double</span> actualPayment;
    <span class="kwrd">double</span> expectedPayment = 400.76;
    <span class="kwrd">double</span> interestRate = (7.5/12)/100; <span class="rem">//7.5% interest / month</span>
    <span class="kwrd">int</span> loanTerm = 5*12; <span class="rem">//60 Months of payments</span>
    <span class="kwrd">int</span> loanAmount = 20000;

    <span class="rem">//Formula</span>
    <span class="rem">//A=P*(r*Math.pow(1+r,N))/(Math.pow(1+r,N)-1)</span>

    actualPayment = <span class="system">Math</span>.Round((loanAmount*(interestRate *
        (<span class="system">Math</span>.Pow(1 + interestRate, loanTerm)) /
        <span class="system">Math</span>.Pow(1 + interestRate, loanTerm) - 1))), 2);

    <span class="system">Assert</span>.AreEqual(expectedPayment, actualPayment);
}</pre>
<p><!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .system {color: #00cccc;} .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p><strong>Encapsulate</strong></p>
<p>Next step is to encapsulate our function into a method of its own.&#160; Run your test to make sure that it still passes.</p>
<pre class="csharpcode">[Test]
<span class="kwrd">public</span> <span class="kwrd">void</span> ShouldCalculatePayment()
{
    <span class="kwrd">double</span> actualPayment;
    <span class="kwrd">double</span> expectedPayment = 400.76;

    actualPayment = CalculatePayment();
    Assert.AreEqual(expectedPayment, actualPayment);
}

<span class="kwrd">public</span> <span class="kwrd">double</span> CalculatePayment()
{
    <span class="kwrd">double</span> interestRate = (7.5 / 12) / 100; <span class="rem">//7.5% interest / month</span>
    <span class="kwrd">int</span> loanTerm = 60;
    <span class="kwrd">int</span> loanAmount = 20000;

    <span class="rem">//Formula</span>
    <span class="rem">//A=P*(r*Math.pow(1+r,N))/(Math.pow(1+r,N)-1)</span>

    <span class="kwrd">return</span> Math.Round((loanAmount * (interestRate *
                                        (Math.Pow(1 + interestRate, loanTerm)) /
                                        (Math.Pow(1 + interestRate, loanTerm) - 1))), 2);
}</pre>
<p><strong>Re-Factor</strong></p>
<p>Looking at our CalculatePayment() method we can see that we have some re-factor points.&#160; First of all we have our interestRate, loanTerm, loanAmount hard coded.&#160; We will most likely want to make those variables method level parameters.&#160; Any other re-factoring will happen here that is related to our new method.</p>
<pre class="csharpcode">[Test]
<span class="kwrd">public</span> <span class="kwrd">void</span> ShouldCalculatePayment()
{
    <span class="kwrd">double</span> actualPayment;
    <span class="kwrd">double</span> expectedPayment = 400.76;
    <span class="kwrd">double</span> interestRate = (7.5 / 12) / 100; <span class="rem">//7.5% interest / month</span>
    <span class="kwrd">int</span> loanTerm = 60;
    <span class="kwrd">int</span> loanAmount = 20000;

    actualPayment = CalculatePayment(interestRate, loanTerm, loanAmount);
    Assert.AreEqual(expectedPayment, actualPayment);
}

<span class="kwrd">public</span> <span class="kwrd">double</span> CalculatePayment(<span class="kwrd">double</span> interestRate, <span class="kwrd">int</span> loanTerm, <span class="kwrd">int</span> loanAmount)
{
    <span class="rem">//Formula</span>
    <span class="rem">//A=P*(r*Math.pow(1+r,N))/(Math.pow(1+r,N)-1)</span>

    <span class="kwrd">return</span> Math.Round((loanAmount * (interestRate *
                                        (Math.Pow(1 + interestRate, loanTerm)) /
                                        (Math.Pow(1 + interestRate, loanTerm) - 1))), 2);
}</pre>
<p><strong>Design</strong></p>
<p>Final step is the design step.&#160; This is where we would take our method to an existing class or a new class depending upon what the business requirements are.&#160; I will leave the final step for you to complete in this exercise.&#160; Once you have completed the final step you will have a new unit test for your unit test suite which meets a specific business behavior/requirement.</p>
<p>Note:&#160; If your final test includes interaction with the database/filesystem then you may want to look at re-factoring your test so that you are mocking the database/filesystem instead of directly interacting with them in the test.&#160; The reason for this is that data/files change, which would then cause tests to fail.&#160; These failures would be considered ‘false failures’.</p>
<p><strong>Conclusion</strong></p>
<p>When I talk to developers about TDD/Unit Testing, I generally get one of two reasons that they don’t do either.&#160; One is that they don’t know how to approach TDD/Unit testing, and the other is that it takes too long to do TDD/Unit Testing.&#160; I will answer the later first.&#160; As developers you will test.&#160; If you don’t do any type of TDD/Unit testing, then you will be testing the code when it comes back to you from QA.&#160; But rest assured you will be testing.&#160; You will gain greater confidence in yourself and with your team if you can deliver quality/provable/testable code.&#160; TDD/Unit Testing is a tool that enables you to do just that.&#160; As for the first reason developers don’t do TDD, if you still don’t know how to approach it, re-read this article.</p>
<p>Happy Coding</p>
<p>Dave</p>
<p><a href="http://www.david-yancey.com/blog/wp-content/uploads/2010/09/TestableCode.pdf">TestableCode</a></p>
]]></content:encoded>
			<wfw:commentRss>http://david-yancey.com/dy/?feed=rss2&#038;p=4</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

