<?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>Milan Nankov’s Blog</title>
	<atom:link href="http://blog.nankov.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nankov.com</link>
	<description>WPF, XNA, MSBuild, and other technologies blog</description>
	<lastBuildDate>Fri, 11 Jun 2010 05:18:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Books I Recommend &#8211; Refactoring: Improving the Design of Existing Code by Martin Fowler</title>
		<link>http://blog.nankov.com/2010/06/11/books-i-recommend-refactoring-improving-the-design-of-existing-code-by-martin-fowler/</link>
		<comments>http://blog.nankov.com/2010/06/11/books-i-recommend-refactoring-improving-the-design-of-existing-code-by-martin-fowler/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 05:18:00 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[clean]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[refactoring]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/2010/06/11/books-i-recommend-refactoring-improving-the-design-of-existing-code-by-martin-fowler/</guid>
		<description><![CDATA[ 
&#160;
Yet another classic. This book is an extensive compilation of refactorings that range from providing meaningful names for variable to collapsing class hierarchies. Every pattern is introduced in three stages – Motivation, Mechanics, and Example. The Motivation section presents the problem that a refactoring is trying to solve. Then the Mechanics section explains how [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/exec/obidos/ASIN/0201485672" target="_blank"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="0201485672" border="0" alt="0201485672" src="http://blog.nankov.com/wp-content/uploads/2010/06/0201485672.jpg" width="380" height="484"></a> </p>
<p>&nbsp;</p>
<p>Yet another classic. This book is an extensive compilation of refactorings that range from providing meaningful names for variable to collapsing class hierarchies. Every pattern is introduced in three stages – <strong>Motivation</strong>, <strong>Mechanics</strong>, and <strong>Example</strong>. The Motivation section presents the problem that a refactoring is trying to solve. Then the Mechanics section explains how a refactoring should be conducted. When a refactoring is a combination of other refactorings the author provides references to those refactorings so that you can easily find them in the book. The last part provides a step-by-step example of how a refactoring can be applied to existing code.</p>
<p>The book is neatly organized and can be used a reference book for your everyday programming endeavors.</p>
<div id="pfButton"><a href="http://blog.nankov.com/2010/06/11/books-i-recommend-refactoring-improving-the-design-of-existing-code-by-martin-fowler/?pfstyle=wp" title="Print an optimized version of this web page" style="text-decoration: none;"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-icon-small.gif" alt="Print"/><span style="font-size: 12px; color: rgb(85, 117, 12);">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2010/06/11/books-i-recommend-refactoring-improving-the-design-of-existing-code-by-martin-fowler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Books I Recommend &#8211; Clean Code by Robert C. Martin</title>
		<link>http://blog.nankov.com/2010/06/10/books-i-recommend-clean-code-by-robert-c-martin/</link>
		<comments>http://blog.nankov.com/2010/06/10/books-i-recommend-clean-code-by-robert-c-martin/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 04:25:54 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[clean]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[readable]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/2010/06/10/books-i-recommend-clean-code-by-robert-c-martin/</guid>
		<description><![CDATA[&#160;
“Even bad code can function. But if code isn’t clean, it can bring a development organization to its knees.”
 
Here is another one of my favorite books. I am not sure if this book needs introduction but if you haven’t heard about it or read it, Clean Code is one of THE books on the [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>“<em>Even bad code can function. But if code isn’t clean, it can bring a development organization to its knees.</em>”</p>
<p><a href="http://www.amazon.com/Clean-Handbook-Software-Craftsmanship-publication/dp/0132350882/" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="0132350882" border="0" alt="0132350882" src="http://blog.nankov.com/wp-content/uploads/2010/06/0132350882.jpg" width="365" height="484"></a> </p>
<p>Here is another one of my favorite books. I am not sure if this book needs introduction but if you haven’t heard about it or read it, <strong>Clean Code</strong> is one of THE books on the art, I would say, of writing code. The book is all about writing clear, readable, and flexible code.</p>
<p>The first part of the book identifies patterns and best practices for writing clean code. Fortunately the book is not simply a compilation of patterns – in the second part of the book Robert C. Martin demonstrates how those patterns fit into real life refactoring scenarios. In the final chapter the author presents a list of code <em>“smells”</em> that can help you identify bad code. </p>
<p>Great book! Enjoy.</p>
<div id="pfButton"><a href="http://blog.nankov.com/2010/06/10/books-i-recommend-clean-code-by-robert-c-martin/?pfstyle=wp" title="Print an optimized version of this web page" style="text-decoration: none;"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-icon-small.gif" alt="Print"/><span style="font-size: 12px; color: rgb(85, 117, 12);">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2010/06/10/books-i-recommend-clean-code-by-robert-c-martin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Visual Studio Code Snippets for TestClass and TestMethod</title>
		<link>http://blog.nankov.com/2010/03/25/visual-studio-code-snippets-for-testclass-and-testmethod/</link>
		<comments>http://blog.nankov.com/2010/03/25/visual-studio-code-snippets-for-testclass-and-testmethod/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 21:40:35 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/2010/03/25/visual-studio-code-snippets-for-testclass-and-testmethod/</guid>
		<description><![CDATA[Tired of writing [TestMethod] and [TestClass] when creating tests? Well, I got tired and wrote two very simple Visual Studio snippets that can create test classes and test methods.
Just copy the two .snippet files into C:\&#60;Program Files Folder&#62;\Microsoft Visual Studio 9.0\VC#\Snippets\1033\Visual C# , restart Visual Studio and you are good to go.
Enjoy.
Download snippets
Print Friendly]]></description>
			<content:encoded><![CDATA[<p>Tired of writing <strong>[TestMethod]</strong> and <strong>[TestClass]</strong> when creating tests? Well, I got tired and wrote two very simple Visual Studio snippets that can create test classes and test methods.</p>
<p>Just copy the two .snippet files into C:\&lt;Program Files Folder&gt;\Microsoft Visual Studio 9.0\VC#\Snippets\1033\Visual C# , restart Visual Studio and you are good to go.</p>
<p>Enjoy.</p>
<p><a href="http://blog.nankov.com/wp-content/uploads/2010/03/testsnippets.zip" target="_blank">Download snippets</a></p>
<div id="pfButton"><a href="http://blog.nankov.com/2010/03/25/visual-studio-code-snippets-for-testclass-and-testmethod/?pfstyle=wp" title="Print an optimized version of this web page" style="text-decoration: none;"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-icon-small.gif" alt="Print"/><span style="font-size: 12px; color: rgb(85, 117, 12);">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2010/03/25/visual-studio-code-snippets-for-testclass-and-testmethod/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Movies To See: The Cove</title>
		<link>http://blog.nankov.com/2009/12/27/movies-to-see-the-cove/</link>
		<comments>http://blog.nankov.com/2009/12/27/movies-to-see-the-cove/#comments</comments>
		<pubDate>Sun, 27 Dec 2009 12:24:45 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[Ramblings]]></category>
		<category><![CDATA[documentary]]></category>
		<category><![CDATA[dolphins]]></category>
		<category><![CDATA[Fisher Stevens]]></category>
		<category><![CDATA[japan]]></category>
		<category><![CDATA[Joshua Ralph]]></category>
		<category><![CDATA[Louie Psihoyos]]></category>
		<category><![CDATA[Oceanic Preservation Society]]></category>
		<category><![CDATA[Richard O'Barry]]></category>
		<category><![CDATA[slaughter]]></category>
		<category><![CDATA[taiji]]></category>
		<category><![CDATA[takepart]]></category>
		<category><![CDATA[the cove]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/?p=227</guid>
		<description><![CDATA[
This is one of those movies that makes you think about our disregard of all living creatures and our arrogance as rulers of Earth. This amazingly well-crafted documentary exposes the annual slaughter of thousands of dolphins in a National Park at Taiji, Wakayama, in Japan. Though killing of dolphins is not banned in Japan the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.thecovemovie.com" target="_blank"><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="The Cove poster" border="0" alt="The Cove poster" src="http://blog.nankov.com/wp-content/uploads/2009/12/TheCoveCovePoster.png" width="315" height="484"></a></p>
<p>This is one of those movies that makes you think about our disregard of all living creatures and our arrogance as rulers of Earth. This amazingly well-crafted documentary exposes the annual slaughter of thousands of dolphins in a National Park at Taiji, Wakayama, in Japan. Though killing of dolphins is not banned in Japan the movie reveals the shocking methods that are used to capture and kill one the most intelligent and magnificent creatures on the planet.&nbsp; </p>
<p><span id="more-227"></span></p>
<p>Not only does this movie deliver an important message but it is also a marvelous piece of filmmaking. Everything from the soundtrack and the spy-thriller-like script, to the shocking final images represents filmmaking at its best. This is definitely one of the greatest documentaries that I have ever seen. </p>
<p>And you would expect no less from the people that were involved: <a href="http://www.psihoyos.com/" target="_blank">Louie Psihoyos</a> (Director) who is regarded as one of top photographers in the world and has worked for National Geographic for 18 years, <a href="http://www.imdb.com/name/nm0001770/" target="_blank">Fisher Stevens</a> (Producer) – an actor and producer who has produced or executive produced over 15 films 5 of which have been nominated for Academy Award, <a href="http://www.jralph.com/" target="_blank">Joshua Ralph</a> (Music) whose scores are included in the Museum of Modern Art’s Permanent collection of film and video in New York, <a href="http://en.wikipedia.org/wiki/Ric_O'Barry" target="_blank">Richard O&#8217;Barry</a> who is one of the top dolphin specialists in the world with his more that 45 years of experience,&nbsp; and many other brave activists and filmmakers.</p>
<p>Some might consider the issues discussed in The Cove as inferior to ones like AIDS, Global Warming, and other ecological catastrophes but the final words of the movie reveal that no issue is too small to be neglected: </p>
<p><strong><em>&#8220;If we can’t stop that, If we can&#8217;t fix that, forget about the bigger issues. There&#8217;s no hope.”</em> – Richard O’Barry</strong></p>
<p><object width="597" height="297" data="http://www.thecovemovie.com/flowplayer/flowplayer-3.1.1.swf?0.0539593492838043" type="application/x-shockwave-flash"><param name="movie" value="http://www.thecovemovie.com/flowplayer/flowplayer-3.1.1.swf?0.0539593492838043" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="flashvars" value="config={&quot;clip&quot;:{&quot;url&quot;:&quot;http://bitcast-b.bitgravity.com/thecovemovie/TheCoveTrailer640x360566.flv&quot;, &quot;autoPlay&quot;:false},&quot;playlist&quot;:[{&quot;url&quot;:&quot;http://bitcast-b.bitgravity.com/thecovemovie/TheCoveTrailer640x360566.flv&quot;}]}" /></object>
<p>&nbsp;</p>
<p>Related links</p>
<p><a href="http://www.thecovemovie.com/" target="_blank">Official website of The Cove</a><br /><a href="http://www.takepart.com/thecove" target="_blank">The Cove at TakePart Social Action Network</a><br /><a href="http://www.opsociety.org/" target="_blank">Oceanic Preservation Society</a></p>
<div id="pfButton"><a href="http://blog.nankov.com/2009/12/27/movies-to-see-the-cove/?pfstyle=wp" title="Print an optimized version of this web page" style="text-decoration: none;"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-icon-small.gif" alt="Print"/><span style="font-size: 12px; color: rgb(85, 117, 12);">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2009/12/27/movies-to-see-the-cove/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mocking The File System to Improve Testability</title>
		<link>http://blog.nankov.com/2009/12/10/mocking-the-file-system-to-improve-testability/</link>
		<comments>http://blog.nankov.com/2009/12/10/mocking-the-file-system-to-improve-testability/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 08:05:17 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[file system]]></category>
		<category><![CDATA[mocking]]></category>
		<category><![CDATA[Moq]]></category>
		<category><![CDATA[MsTest]]></category>
		<category><![CDATA[testability]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/?p=222</guid>
		<description><![CDATA[Recently I started writing a simple application that would help me organize my music files by automatically renaming them using their tags and moving them to their designated folders. 
As expected the program will rely on the file system classes that the .Net Framework provides. Naturally, I wanted to cover the I/O logic with tests [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I started writing a simple application that would help me organize my music files by automatically renaming them using their tags and moving them to their designated folders. </p>
<p>As expected the program will rely on the file system classes that the .Net Framework provides. Naturally, I wanted to cover the I/O logic with tests so that I am confident that when the software is used it will not do damage to my files and will behave according to my requirements. So I started writing tests…</p>
<p><span id="more-222"></span></p>
<p>And here is the catch – in general it is not a good idea to have tests that are performing I/O operations like accessing files and databases. In such situations, but of course not limited to, mock objects are your friend. And before I go into more details about what mocking really is lets find out why mocking I/O is important? Well, for a ton of reasons:</p>
<ul>
<li>Usually faster than performing I/O operations </li>
<li>You do not have have to deal with security issues </li>
<li>You have more control – easily test intricate scenarios </li>
<li>Test setup is far more easier to do&#160; </li>
</ul>
<p>The first thing that most people think about when asked about mocking is interfaces. And that is no surprise since mocking is built around interfaces. Here is a simplified version of the file system interface that I have created for my application:</p>
</p>
<pre class="c#" name="code">public interface IFileSystem
{
    bool FileExists(string path);

    string GetFullPath(string path);

    string GetFileName(string filePath);

    string GetPathRoot(string path);

    string GetDirectoryName(string path);

    string PathCombine(string firstPath, string secondPath);

    void MoveFile(string filePath, string newFilePath);
}</pre>
<p>This interface represents all operations that my application will be able to perform on the file system. As we will see, this interface allows me to create a fake implementation of the file system functionality (mock) which will be the cornerstone of all of my I/O tests.</p>
<p>As you have probably guessed I will be using MSTest to drive my tests but you can use a testing framework of your choice. In addition to a testing framework you also need a mocking framework. My favorite one is called <a href="http://code.google.com/p/moq/" target="_blank">Moq</a> &#8211; it is very powerful and yet easy to use. </p>
<p>Let’s write some tests…</p>
<pre class="c#" name="code">private Mock&lt;IFileSystem&gt; fileSystemMock;
private IFileSystem fileSystem;

[TestInitialize]
public void Initializer()
{
    this.fileSystemMock = new Mock&lt;IFileSystem&gt;();
    this.fileSystem = this.fileSystemMock.Object;
}</pre>
<p>The first thing to do is to create the mock implementation of the interface that we are interested in. This first line of the Initializer&#160; method will create a dummy implementation (mock) of the specified interface (in this case IFileSystem) and you can use the Object property to interact with an instance of the this dummy interface implementation. For convenience we copy the instance reference to “<em>this.fileSystem</em>”.</p>
<p>The mock (“<em>this.fileSystemMock</em>”) allows you to control the behavior of the mocked object and setup assertions which allow you to test the behavior of the mocked object. </p>
<p>The following two tests will assure that the Rename method of the MusicFileConfigurator class behaves according to my specifications. Here is the code that will be tested:</p>
<pre class="c#" name="code">public class MusicFileConfigurator
{
    private IFileSystem fileSystem;

    public MusicFileConfigurator(IFileSystem fileSystem)
    {
        if (fileSystem == null)
            throw new ArgumentNullException(&quot;fileSystem&quot;);

        this.fileSystem = fileSystem;
    }

    public void Rename(string filePath)
    {
        if(!this.fileSystem.FileExists(filePath))
            throw new FileNotFoundException(&quot;File was not found&quot;, filePath);

        var newFilePath = this.AdjustNewFilePath(filePath, &quot;renamed.test.file&quot;);

        if (this.fileSystem.FileExists(newFilePath))
            throw new IOException(&quot;New filename already exists -&gt; &quot; + newFilePath);

        this.fileSystem.MoveFile(filePath, newFilePath);
    }
}</pre>
<p>Notice that the constructor accepts a parameter of type IFileSystem. This is very important, as you will see shortly, since it enables us to plug in different interface implementations. This technique is know as Dependency Injection – in this particular case we use the so called Constructor injection. For the sake of simplicity the Rename method will always rename the specified file to “renamed.test.file”.</p>
<p>Back to the tests… First I want to be sure that if a non-existent file is passed as argument the method will throw an exception. </p>
<pre class="c#" name="code">[TestMethod]
[ExpectedException(typeof(FileNotFoundException))]
public void Rename_ThrowsException_WhenTheSpecifiedFileDoesNotExist()
{
    MusicFileConfigurator creator = new MusicFileConfigurator(this.fileSystem);
    this.fileSystemMock.Setup(fs =&gt; fs.FileExists(It.Is<string>(s =&gt; s == &quot;test.file&quot;))).Returns(false);

    creator.Rename(&quot;test.file&quot;);
}</pre>
<p>The first line, though boring, is crucial for understanding how the test works. Remember that “<em>this.fileSystem</em>” is actually an instance of the mock implementation? Well, now the MusicFileConfigurator is going to use this mock implementation of the IFileSystem.</p>
<p>The second line of the test reveals some of the power of Moq and mocking in general. This line instructs the file system mock to return “false” whenever “test.file” is specified as argument to the FileExists method. By doing that we ensure that the first condition of Rename will not be met and FileNotFoundException will be thrown. </p>
<p>The Setup method is very powerful and allows you to specify how the methods and the properties of your mocked objects behave – what results they returns, whether they throw exceptions and more. </p>
<p>Moving on to a move sophisticated test which asserts that the Rename method can successfully rename the specified file.</p>
<pre class="c#" name="code">[TestMethod]
public void File_IsRenamed_Correctly()
{
    MusicFileConfigurator creator = new MusicFileConfigurator(this.fileSystem);
    this.fileSystemMock.Setup(fs =&gt; fs.FileExists(It.Is<string>(s =&gt; s == &quot;test.file&quot;))).Returns(true);
    this.fileSystemMock.Setup(fs =&gt; fs.FileExists(It.Is<string>(s =&gt; s == &quot;renamed.test.file&quot;))).Returns(false);

    creator.Rename(&quot;test.file&quot;);

    this.fileSystemMock.Verify(fs =&gt; fs.MoveFile(&quot;test.file&quot;, &quot;renamed.test.file&quot;), Times.Exactly(1));
}</pre>
<p>Once again we have almost the same setup with just two additional lines. This time we want to test that when the Rename method executes without any errors it will actually rename the specified file. The two Setup statements ensure that the specified file exists and that the new filename does not (which is required by the Rename method).</p>
<p>So far we have just ensured that the Rename method will run without errors. To be sure that it can really rename files we have to make sure that Rename will call MoveFile with the correct arguments. With Moq this is a piece of cake.</p>
<p>Whenever we want to make sure that certain method has been executed or hasn’t been executed we use the Verify method. In this particular setup I want to assert that the Rename method calls the MoveFile method of the file system exactly one time with the expected arguments. If the conditions are not met – for instance the method is called more times &#8211; Verify will throw exception and the test will fail.&#160; </p>
<p>I do not know if it is just me but I think that this piece of test code is simply beautiful. In addition to the easily readable fluent interface of Moq you are not dealing with the actual file system which spares you a a great deal of time and resources to setup our tests. </p>
<p>You might be wondering how is the MusicFileConfigurator going to working in a real scenario? Well, I have created a special implementation of the IFileSystem interface which uses the actual file system. </p>
<pre class="c#" name="code">public sealed class DefaultFileSystem : IFileSystem
{
    public string GetFullPath(string path)
    {
        return Path.GetFullPath(path);
    }

    public string PathCombine(string firstPath, string secondPath)
    {
        return Path.Combine(firstPath, secondPath);
    }

    public string GetFileName(string filePath)
    {
        return Path.GetFileName(filePath);
    }

    public void MoveFile(string filePath, string newFilePath)
    {
        File.Move(filePath, newFilePath);
    }

    public bool FileExists(string path)
    {
        return File.Exists(path);
    }

    public string GetDirectoryName(string path)
    {
        return Path.GetDirectoryName(path);
    }

    public string GetPathRoot(string path)
    {
        return Path.GetPathRoot(path);
    }
}</pre>
<p>And whenever I initialize the MusicFileConfigurator I do something like that:</p>
<pre class="c#" name="code">class Program
{
    static void Main(string[] args)
    {
        MusicFileConfigurator configurator = new MusicFileConfigurator(new DefaultFileSystem());
    }
}</pre>
<p>I have attached the full source code for this article which includes more tests. </p>
<p>Related links:<br />
  <a href="http://code.google.com/p/moq/" target="_blank">The Moq Project</a><br />
  <a href="http://www.codethinked.com/post/2009/03/08/Beginning-Mocking-With-Moq-3-Part-1.aspx" target="_blank">Beginning Mocking with Moq</a>
</p>
<p> Download File &#8211; <a href="http://blog.nankov.com/wp-content/uploads/2010/01/FileSystemMockingSource.zip" target="_self">FileSystemMockingSource</a></p>
<div id="pfButton"><a href="http://blog.nankov.com/2009/12/10/mocking-the-file-system-to-improve-testability/?pfstyle=wp" title="Print an optimized version of this web page" style="text-decoration: none;"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-icon-small.gif" alt="Print"/><span style="font-size: 12px; color: rgb(85, 117, 12);">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2009/12/10/mocking-the-file-system-to-improve-testability/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Books I Recommend &#8211; I. M. Wright&#8217;s Hard Code by Eric Brechner</title>
		<link>http://blog.nankov.com/2009/12/03/books-i-recommend-i-m-wrights-hard-code-by-eric-brechner/</link>
		<comments>http://blog.nankov.com/2009/12/03/books-i-recommend-i-m-wrights-hard-code-by-eric-brechner/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 06:46:36 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[Software Testing]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Eric Brechner]]></category>
		<category><![CDATA[Hard Code]]></category>
		<category><![CDATA[Managing risk]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Quality]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/2009/12/03/books-i-recommend-i-m-wrights-hard-code-by-eric-brechner/</guid>
		<description><![CDATA[&#160;
I have been yearning to write about this book for a long time since it&#160; had become an all-time favorite. You have got to love this book for its incredible depth, witty jokes, great style, and funky structure. Definitely a must-read for every developer. 
Don’t get fooled by the name though – the author covers [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/gp/product/0735624356/" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="I.M. Wright&#39;s Hard Code" border="0" alt="I.M. Wright&#39;s Hard Code" src="http://blog.nankov.com/wp-content/uploads/2009/12/hardcodesmall.jpg" width="254" height="309" /></a>&#160;</p>
<p>I have been yearning to write about this book for a long time since it&#160; had become an all-time favorite. You have got to love this book for its incredible depth, witty jokes, great style, and funky structure. Definitely a must-read for every developer. </p>
<p>Don’t get fooled by the name though – the author covers a lot of ground and the book could be helpful not only to developers but project/product managers, QAs, HR, even top-level management. </p>
<p><span id="more-218"></span></p>
<p>Hard Code is a compilation of opinion columns written by the fictitious figure I. M. Wright (got to love the name), or as Eric Brechner calls it “my alter ego”.&#160; In addition to topics like dev schedules, managing risk, agile methodologies, and testing the author covers other more esoteric, yet just as important, ones like people issues and team growth. Moreover the book can be considered as The Hitchhiker&#8217;s Guide to Microsoft since it offers quite a few details about the inner-workings of the software giant.</p>
<p>I will leave you with three of my favorite quotes from the book:</p>
<p><em>“A horse walks into a bar and says: I can code that feature in two days.” </em></p>
<p><em>“If you think Agile methods fix all that is wrong with how we build products, you are, in fact, a fool… If you are an anti-Agile curmudgeon who thinks Scrum is an acronym for System of Clueless Reckless Untested Methods, you are as much a fool and just as ignorant” </em></p>
<p><em>“If you treat your test team like trash, trash is likely what you’ll ship and trashy is how you’ll feel. If you prefer a smooth release and want to ship a great product, make your test team your ally. … [testers] They cover areas that you can’t or don’t want to do. They keep you on schedule and track. They keep you honest and represent the customer’s perspective.”</em></p>
<p>Now go read it!</p>
<div id="pfButton"><a href="http://blog.nankov.com/2009/12/03/books-i-recommend-i-m-wrights-hard-code-by-eric-brechner/?pfstyle=wp" title="Print an optimized version of this web page" style="text-decoration: none;"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-icon-small.gif" alt="Print"/><span style="font-size: 12px; color: rgb(85, 117, 12);">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2009/12/03/books-i-recommend-i-m-wrights-hard-code-by-eric-brechner/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Visual Studio Low Contrast Theme &#8211; Zenburn Remixed</title>
		<link>http://blog.nankov.com/2009/09/02/visual-studio-low-contrast-theme-zenburn-remixed/</link>
		<comments>http://blog.nankov.com/2009/09/02/visual-studio-low-contrast-theme-zenburn-remixed/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 06:19:28 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Dark]]></category>
		<category><![CDATA[Low Contrast]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[Zenburn]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/2009/09/02/visual-studio-low-contrast-theme-zenburn-remixed/</guid>
		<description><![CDATA[Several months ago I started my hunt for a decent low contrast theme for Visual Studio and I came across a very extensive article on the subject by Scott Hanselman.  I tried several themes but the one that caught my attention was Oren Ellenbogen&#8217;s Dark Scheme which is based on the Zenburn theme.
One thing that [...]]]></description>
			<content:encoded><![CDATA[<p>Several months ago I started my hunt for a decent low contrast theme for Visual Studio and I came across a very extensive <a href="http://www.hanselman.com/blog/VisualStudioProgrammerThemesGallery.aspx" target="_blank">article</a> on the subject by Scott Hanselman.  I tried several themes but the one that caught my attention was <a href="http://www.lnbogen.com/VisualStudioNet2005Colors.aspx" target="_blank">Oren Ellenbogen&#8217;s Dark Scheme</a> which is based on the <a href="http://www.codinghorror.com/blog/archives/000682.html" target="_blank">Zenburn</a> theme.</p>
<p>One thing that I do not like about the original themes, being a Silverlight and a WPF developer, is the fact that the XML colors were not configured. In addition to that, the output window uses a horrifying green-colored font that can make your eyes pop. Apart from those two problems I consider the two themes to be the best low contrast themes available.</p>
<p>I have made some adjustments to the original themes and I came up with my version which I use every day. Now the output window uses more subtle font color and the XML markup look a lot better. Here is the Zenburn Remixed:<br />
<span id="more-212"></span></p>
<p><a href="http://blog.nankov.com/wp-content/uploads/2009/09/darkthemecode.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Zenburn Low Constrast Theme Remixed Code View" src="http://blog.nankov.com/wp-content/uploads/2009/09/darkthemecode_thumb.png" border="0" alt="Zenburn Low Constrast Theme Remixed Code View" width="565" height="367" /></a></p>
<p><a href="http://blog.nankov.com/wp-content/uploads/2009/09/darkthemexaml.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Zenburn Low Constrast Theme Remixed XML View" src="http://blog.nankov.com/wp-content/uploads/2009/09/darkthemexaml_thumb.png" border="0" alt="Zenburn Low Constrast Theme Remixed XML View" width="667" height="344" /></a></p>
<p><a href="http://blog.nankov.com/wp-content/uploads/2009/09/darkthemeoutput.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Zenburn Low Constrast Theme Remixed Output Window" src="http://blog.nankov.com/wp-content/uploads/2009/09/darkthemeoutput_thumb.png" border="0" alt="Zenburn Low Constrast Theme Remixed Output Window" width="349" height="331" /></a></p>
<p>I have attached a zip file that contains a Visual Studio 2008 setting file that you can use to apply the Zenburn Remixed theme. To do that just open Visual Studio, go to Tools –&gt; Import and Export settings, and follow the wizard.</p>
<p>Many thanks to the guys that compiled the original themes.</p>
<div id="scid:FF7EC618-8FBE-49a5-B908-2339AF2ABCDF:50c96e69-13d0-4de0-96a9-a9632fb23750" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<div>Download File &#8211; <a href="http://blog.nankov.com/wp-content/uploads/2009/09/tmp88F5.zip" target="_self">Zenburn Remixed &#8211; Visual Studio Low Contrast Theme</a></div>
</div>
<div id="pfButton"><a href="http://blog.nankov.com/2009/09/02/visual-studio-low-contrast-theme-zenburn-remixed/?pfstyle=wp" title="Print an optimized version of this web page" style="text-decoration: none;"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-icon-small.gif" alt="Print"/><span style="font-size: 12px; color: rgb(85, 117, 12);">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2009/09/02/visual-studio-low-contrast-theme-zenburn-remixed/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Replacing multiple files with Windows PowerShell</title>
		<link>http://blog.nankov.com/2009/08/23/replacing-multiple-files-with-windows-powershell/</link>
		<comments>http://blog.nankov.com/2009/08/23/replacing-multiple-files-with-windows-powershell/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 13:47:47 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Cmdlet]]></category>
		<category><![CDATA[Commandlet]]></category>
		<category><![CDATA[Files]]></category>
		<category><![CDATA[Multiple]]></category>
		<category><![CDATA[Overwrite]]></category>
		<category><![CDATA[Replace]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/?p=187</guid>
		<description><![CDATA[A couple of days ago I had to overwrite several files with another file and Windows PowerShell came to the rescue. At first it might seem that such task is trivial and it could easily be done in a minute using copy, paste, and Windows Explorer. That might be true if you are dealing with [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago I had to overwrite several files with another file and Windows PowerShell came to the rescue. At first it might seem that such task is trivial and it could easily be done in a minute using copy, paste, and Windows Explorer. That might be true if you are dealing with just a few files but if that is not case – if you are dealing with 50+ files which have different names – you should consider another approach.</p>
<p> <span id="more-187"></span>
<p>I have created a simple PowerShell script that will search for specific files in a directory and after that replace those files with a single file, which is specified in the script. Here is the scripts:</p>
<pre class="python" name="code">$FileName = &quot;C:\new.png&quot;
$TargetDir = &quot;C:\myFolder\&quot;

$FilesToOverride = get-childitem $TargetDir -recurse | where {$_.extension -eq &quot;.png&quot;}

Foreach ($file in $FilesToOverride)
{
    echo (&quot;Replacing &quot; + $file.FullName + &quot; with &quot; + $FileName)
    copy-item $FileName ($file.DirectoryName + &quot;\&quot; + $file.Name)
}</pre>
<p>This version of the script will search recursively for all PNG files in myFolder and overwrite every PNG file with new.png.&#160; </p>
<p>The script is very simple but if you are new to PowerShell (like me) you might not be familiar with all of the script’s building blocks. The first one is the “get-childitem” <a href="http://technet.microsoft.com/en-us/library/aa996589.aspx" target="_blank">cmdlet</a>. It retrieves items from a specified location, which could be anything – directory, registry, etc. The recurse switch indicates that the scripts will retrieve files not only myFolder but also from all of its subfolders. Get-childitem accepts many parameters which allow you fine tune the search query but that is outside the scope of this post. <a href="http://technet.microsoft.com/en-us/library/dd347686.aspx" target="_blank">Here</a> you an find more information about get-childitem. </p>
<p>In its current form get-childitem will return all files in myFolder regardless of their extension. That is where another commandlet comes into play. Where-Object (alias where) cmdlet is used to filter results from other commandlets and I use it in the script to select files with a specific extension (in this case PNG files).</p>
<p>Finally the script goes through the list of all files in FilesToOverride and overwrites each file using the copy-item cmdlet. </p>
<p>Helpful links:<br />
  <br /><a href="http://technet.microsoft.com/en-us/scriptcenter/dd772285.aspx" target="_blank">Guide to Windows PowerShell Cmdlets</a><br />
  <br /><a href="http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/pipe.mspx " target="_blank">Piping and the Pipeline in Windows PowerShell</a><br />
  <br /><a href="http://technet.microsoft.com/en-us/library/dd347686.aspx" target="_blank">Get-ChildItem Cmdlet</a><br />
  <br /><a href="http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/where-object.mspx" target="_blank">Where-Object Cmdlet</a><br />
  <br /><a href="http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/copy-item.mspx" target="_blank">Copy-Item Cmdlet</a></p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:FF7EC618-8FBE-49a5-B908-2339AF2ABCDF:1831c9ad-fcdc-4f94-9d42-f98f7e1c4b1c" class="wlWriterEditableSmartContent">
<div>Download File &#8211; <a href="http://blog.nankov.com/wp-content/uploads/2009/08/tmp591C.zip" target="_self">Replace Files Script</a></div>
</div>
<div id="pfButton"><a href="http://blog.nankov.com/2009/08/23/replacing-multiple-files-with-windows-powershell/?pfstyle=wp" title="Print an optimized version of this web page" style="text-decoration: none;"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-icon-small.gif" alt="Print"/><span style="font-size: 12px; color: rgb(85, 117, 12);">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2009/08/23/replacing-multiple-files-with-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Resizing Virtual Hard Disk (VHD) Files – The Easy Way</title>
		<link>http://blog.nankov.com/2009/08/02/resizing-virtual-hard-disk-vhd-files-the-easy-way/</link>
		<comments>http://blog.nankov.com/2009/08/02/resizing-virtual-hard-disk-vhd-files-the-easy-way/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 17:23:31 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[Virtual Machines]]></category>
		<category><![CDATA[expand]]></category>
		<category><![CDATA[hard disk]]></category>
		<category><![CDATA[partition]]></category>
		<category><![CDATA[resize]]></category>
		<category><![CDATA[VHD]]></category>
		<category><![CDATA[VHD Resizer]]></category>
		<category><![CDATA[vmToolkit]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/2009/08/02/resizing-virtual-hard-disk-vhd-files-the-easy-way/</guid>
		<description><![CDATA[&#160;
Once in a while you have to change the size of a VHD file and I think I have found the perfect tool for the job. It is called VHD Resizer (previously known as VHD Expander) and it very easy to use. You can grab it from the vmToolKit (http://vmtoolkit.com/) website and expand or shrink [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;</p>
<p>Once in a while you have to change the size of a VHD file and I think I have found the perfect tool for the job. It is called <strong>VHD Resizer</strong> (previously known as VHD Expander) and it very easy to use. You can grab it from the <strong>vmToolKit</strong> (<a title="http://vmtoolkit.com/" href="http://vmtoolkit.com/">http://vmtoolkit.com/</a>) website and expand or shrink the size of any Virtual Hard Disk file with just a few clicks.</p>
<p>  <span id="more-165"></span>
<p>Once you start the program you have to select a VHD file to work with and choose how to change the original VHD file.</p>
<p><a href="http://blog.nankov.com/wp-content/uploads/2009/08/vhdresizerwindow.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="VHD Resizer Window" border="0" alt="VHD Resizer Window" src="http://blog.nankov.com/wp-content/uploads/2009/08/vhdresizerwindow-thumb.png" width="467" height="425" /></a></p>
<p>You can choose the type of the VHD file (Dynamic or Fixed) and also the new size of the disk in GB or MB units. Click resize and after a couple of minutes, depending on the size of the disk files, you will have the resized file.</p>
<p>Mount the new file onto your Virtual Machine and you are almost ready to go. If you have expanded your VHD file, most probably, the partition that your Virtual Machine uses is not the correct size and the newly added space is reported as unallocated.</p>
<p><a href="http://blog.nankov.com/wp-content/uploads/2009/08/unallocated.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Unallocated space" border="0" alt="Unallocated space" src="http://blog.nankov.com/wp-content/uploads/2009/08/unallocated-thumb.png" width="603" height="396" /></a></p>
<p>Use your favorite partition management tool, expand the partition, and you are ready to go.</p>
<p>Of course, you could do the geeky thing and use <strong>DiskPart</strong> utility to change the size of a VHD file. There is lengthy description of this utility called “A Description of the Diskpart Command-Line Utility” that you can find <a href="http://support.microsoft.com/kb/300415" target="_blank">here</a> .</p>
<p>Cheers.</p>
<div id="pfButton"><a href="http://blog.nankov.com/2009/08/02/resizing-virtual-hard-disk-vhd-files-the-easy-way/?pfstyle=wp" title="Print an optimized version of this web page" style="text-decoration: none;"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-icon-small.gif" alt="Print"/><span style="font-size: 12px; color: rgb(85, 117, 12);">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2009/08/02/resizing-virtual-hard-disk-vhd-files-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Scheduling multiple builds with a single click (using MSBuild and Team Build 2008)</title>
		<link>http://blog.nankov.com/2009/04/27/scheduling-multiple-builds-with-a-single-click-using-msbuild-and-team-build-2008/</link>
		<comments>http://blog.nankov.com/2009/04/27/scheduling-multiple-builds-with-a-single-click-using-msbuild-and-team-build-2008/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 07:17:05 +0000</pubDate>
		<dc:creator>Milan</dc:creator>
				<category><![CDATA[Build Systems]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[Microsoft Team Build]]></category>
		<category><![CDATA[Team Build]]></category>

		<guid isPermaLink="false">http://blog.nankov.com/2009/04/27/scheduling-multiple-builds-with-a-single-click-using-msbuild-and-team-build-2008/</guid>
		<description><![CDATA[I have just posted an article about scheduling multiple builds with Team Build and MSBuild at my Telerik blog. Here is an excerpt: 
If you are working on a large project it is very probable that the project is composed of several parts/modules which are build separately. What are your options if you want to [...]]]></description>
			<content:encoded><![CDATA[<p>I have just posted an article about scheduling multiple builds with Team Build and MSBuild at my Telerik blog. Here is an excerpt: </p>
<p>If you are working on a large project it is very probable that the project is composed of several parts/modules which are build separately. What are your options if you want to be able to rebuild the whole thing easily? If you are a Quake tournament winner equipped with Razer Copperhead mouse you could probably schedule 10 builds (in the right order) in a matter of seconds but what about your colleagues that are not so gifted? Well, there is the TfsBuild command line tool but in case you are using the 2008 version and you would like to have the freedom to choose a build agent when scheduling a build you are out of luck. It seems that the only viable option is to write a custom tool that talks directly to Team Build. </p>
<p>You can find the whole blog post <a href="http://blogs.telerik.com/milannankov/posts/09-04-27/scheduling_multiple_builds_with_a_single_click_using_msbuild_and_team_build_2008.aspx " target="_blank">here</a>.</p>
<div id="pfButton"><a href="http://blog.nankov.com/2009/04/27/scheduling-multiple-builds-with-a-single-click-using-msbuild-and-team-build-2008/?pfstyle=wp" title="Print an optimized version of this web page" style="text-decoration: none;"><img id="printfriendly" style="border:none; padding:0;" src="http://cdn.printfriendly.com/pf-icon-small.gif" alt="Print"/><span style="font-size: 12px; color: rgb(85, 117, 12);">Print Friendly</span></a></div>]]></content:encoded>
			<wfw:commentRss>http://blog.nankov.com/2009/04/27/scheduling-multiple-builds-with-a-single-click-using-msbuild-and-team-build-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
