<?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>AndrewBlogs</title>
	<atom:link href="http://andrewblogs.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewblogs.com/blog</link>
	<description></description>
	<lastBuildDate>Tue, 07 Sep 2010 23:05:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>How To: Dropbox and VirtualBox, Ubuntu</title>
		<link>http://andrewblogs.com/blog/how-to-dropbox-and-virtualbox-ubuntu/</link>
		<comments>http://andrewblogs.com/blog/how-to-dropbox-and-virtualbox-ubuntu/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 17:00:33 +0000</pubDate>
		<dc:creator>Andrew Kharlamov</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[dropbox vm]]></category>
		<category><![CDATA[installing virtual machine on dropbox]]></category>
		<category><![CDATA[Ubuntu in dropbox]]></category>
		<category><![CDATA[virtualbox ubuntu dropbox]]></category>

		<guid isPermaLink="false">http://andrewblogs.com/blog/?p=626</guid>
		<description><![CDATA[Not for the faint hearted. The idea of having a portable environment is really neat, it&#8217;s even better when you don&#8217;t have to pay through your nose to have it and use it with privacy. If you don&#8217;t have a 32GB flash drive, DropBox is a good way to go. I wanted to do the [...]]]></description>
			<content:encoded><![CDATA[<p>Not for the faint hearted.</p>
<p>The idea of having a portable environment is really neat, it&#8217;s even better when you don&#8217;t have to pay through your nose to have it and use it with privacy.</p>
<p>If you don&#8217;t have a 32GB flash drive, DropBox is a good way to go.</p>
<p><img src="http://andrewblogs.com/images/dropboxsnap.jpg" alt="Ubuntu through dropbox" /></p>
<p><span id="more-626"></span></p>
<p><strong>I wanted to do the following:</strong></p>
<ol>
<li>Install Ubuntu via VirtualBox (VMWare).</li>
<li>Setup the envoirnment with the necessary software.</li>
<li>Sync it to dropbox.</li>
<li>Add files from within the image to dropbox. <em>(without redownloading the virtual machine image in the virtual machine)</em></li>
<li> Sync it across multiple computers.</li>
</ol>
<p><em> </em></p>
<p><em>I made the unfortunate mistake of syncing Ubuntu after it installed, and then again after 3gb of software installs. Don&#8217;t let it sync until everything is done!</em></p>
<p><strong>How I did it:</strong></p>
<p>With the 50gb dropbox, create a folder called: &#8220;Operating Systems&#8221;, &#8220;OS&#8221; whatever you want.</p>
<ol>
<li>Download the latest ubuntu install.</li>
<li>Download the latest image of VirtualBox. For me it was: &#8220;VirtualBox-3.2.8-64453-Win.exe&#8221;</li>
<li>Install it and sync it in your &#8220;Operating Systems&#8221; folder.</li>
<li>In VirtualBox, click new, give your OS Image a name and select Ubuntu.</li>
<li>Allocate at least 1024mb of memory, Create a new hard disk in your dropbox folder, select dynamically expanding storage, with at least 8gb of space.</li>
<li>Click start select your ubuntu iso, set it up.</li>
<li>After you have installed Ubuntu, mount the VirtualBox additions, and install them.</li>
<li>After that is done, go ahead and install all your packages and software.</li>
<li>In your regular OS go to C:\Users\..\.VirtualBox replace .. with your username.</li>
<li>Yank out all the files in there and sync them to your &#8220;Operating Systems&#8221; folder.</li>
<li>Shutdown ubuntu, close down VirtualBox. Let Dropbox sync your finished product.</li>
<li>On another computer, let dropbox sync everything.</li>
<li>Install Virtualbox, copy the necessary files to C:\Users\..\.VirtualBox with .. being your username.</li>
<li>Start VirtualBox your OS should be listed, make sure your paths are all correct in your images prefrences, start it up and you should be good to go.</li>
</ol>
<p>Adding files to dropbox is simple with VirtualBox shared network, all you have to do is navigate to your dropbox folder. In ubuntu Places &gt; Network. Locate your dropbox folder and add items there. I even went as far as creating a simple alias to the location and added a dropbox icon to the alias.</p>
<p><strong>To wrap it up, some of the drawbacks:</strong></p>
<ul>
<li>If you change the image to much it has to re sync the entire image.</li>
<li>Indexing large files takes forever.</li>
<li>The initial sync takes a while.</li>
</ul>
<p>For those of you who are going to ask, syncing minor changes to the image are quick after the indexing is complete.</p>
<p>Another positive note, in Dropbox&#8217;s votebox there are already a lot of requests to manually sync files.</p>
<p>Good Luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewblogs.com/blog/how-to-dropbox-and-virtualbox-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Zen Coding PHP, Zen Coding custom snippet example.</title>
		<link>http://andrewblogs.com/blog/zen-coding-php-zen-coding-custom-snippet-example/</link>
		<comments>http://andrewblogs.com/blog/zen-coding-php-zen-coding-custom-snippet-example/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 01:37:32 +0000</pubDate>
		<dc:creator>Andrew Kharlamov</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[add custom zen coding tags]]></category>
		<category><![CDATA[customize zen coding]]></category>
		<category><![CDATA[make zen coding abbreviations]]></category>
		<category><![CDATA[zen coding php]]></category>
		<category><![CDATA[zen coding snippets]]></category>
		<category><![CDATA[zen coding snippets & php]]></category>
		<category><![CDATA[zen coding snippets and php]]></category>
		<category><![CDATA[Zencoding PHP]]></category>
		<category><![CDATA[zencoding snippets]]></category>

		<guid isPermaLink="false">http://andrewblogs.com/blog/?p=577</guid>
		<description><![CDATA[By now you are probably a big fan of Zen Coding, and want more. I am going to run through a tutorial on how to create custom snippets using the &#8220;Zen Coding.js&#8221; file. At the end of this tutorial I have a link to a PHP version I wrote for personal use, feel free to [...]]]></description>
			<content:encoded><![CDATA[<p>By now you are probably a big fan of Zen Coding, and want more. I am going to run through a tutorial on how to create custom snippets using the &#8220;Zen Coding.js&#8221; file.</p>
<p>At the end of this tutorial I have a link to a PHP version I wrote for personal use, feel free to download, edit, destroy, and share it.</p>
<p>Lets dive in.</p>
<p><span id="more-577"></span></p>
<p>If you are using Notepad++, &#8220;Zen Coding.js&#8221; is located here:</p>
<p><em>..\Notepad++\plugins\NppScripting\includes\Zen Coding.js</em></p>
<p>You will need to edit this file to add your own custom snippets/abbreviations.</p>
<p>Locate the following code <em>(contents have been replaced with &#8220;//there is code here&#8221;)</em>:</p>
<pre class="brush:php">
	'html': {
		'filters': 'html',
		'snippets': {
			//there is code here
		},
		'abbreviations': {
			//there is code here
		},
		'element_types': {
		}
	},
	'xsl': {
		'extends': 'html',
		'filters': 'html, xsl',
		'abbreviations': {
			//there is code here
		}
	},</pre>
<p>These are all of the existing html and xsl abbreviations and snippets provided with Zen Coding. </p>
<p>For the sake of time, we are going to add a PHP section right before this line:</p>
<pre class="brush:php">
	'xsl': {</pre>
<p>This will look like this:</p>
<pre class="brush:php">
	'html': {
		'filters': 'html',
		'snippets': {
			//there is code here
		},
		'abbreviations': {
			//there is code here
		},
		'element_types': {
		}
	},
	'php': {
		'filters': 'php, html',
		'snippets': {
			//we will write snippets here
		}
	},
	'xsl': {
		'extends': 'html',
		'filters': 'html, xsl',
		'abbreviations': {
			//there is code here
		}
	},</pre>
<p>Make sure your curly braces, comas, etc. are correct otherwise you will get an error loading the file.</p>
<p>Now locate:</p>
<pre class="brush:php">
	var know_syntaxes = {
		'html': 1,
		//there is more code here

	};
</pre>
<p>Add &#8216;php&#8217;: 1 to this code, like this: </p>
<pre class="brush:php">
	var know_syntaxes = {
		'html': 1,
		'php': 1,
		//there is more code here
	};
</pre>
<p>Finally, lets add a snippet, I am going to create one for an inline function as my blog won&#8217;t let me write out actual php code without rendering it, if you would like to wrap your code in a php tag go right ahead.</p>
<p>So lets try something like this:</p>
<pre class="brush:php">
	'php': {
		'filters': 'php, html',
		'snippets': {
			//we will write snippets here
			'php:func':	'function |() {\n\t\n}',
		}
	},</pre>
<p><strong>|</strong> is the position of your mouse cursor.</p>
<p><strong>\n</strong> is new line</p>
<p><strong>\t</strong> is tab</p>
<p>See simple.</p>
<p>Save your &#8220;Zen Coding.js&#8221; file, restart your application in our case Notepad++. </p>
<p>Now if you were to type in php:func then click Ctrl+E, this would expand to:</p>
<pre class="brush:php">
function () {

}</pre>
<p>tada, and now as promised:</p>
<h3>My attempt at PHP snippets!</h3>
<p>Download/Preview the PHP section, via copy paste from here: <a href="http://andrewblogs.com/zen-coding/Zen%20Coding%20Php.txt" target="_tab">Preview/Download</a>.</p>
<p>Or</p>
<p>Download the entire <a href="http://andrewblogs.com/zen-coding/Zen%20Coding.js" target="_tab">Zen Coding.js</a> file, by right click save as.</p>
<p>&#8212;</p>
<p>As you can see there is so much room for editing and customizing your own abbreviations and snippets. I haven&#8217;t even touched the tip of the iceberg. So go explore and good luck, just make sure to make a backup file. <img src='http://andrewblogs.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://andrewblogs.com/blog/zen-coding-php-zen-coding-custom-snippet-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Amazing Website Designs of 2010</title>
		<link>http://andrewblogs.com/blog/amazing-website-designs-of-2010/</link>
		<comments>http://andrewblogs.com/blog/amazing-website-designs-of-2010/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 06:30:41 +0000</pubDate>
		<dc:creator>Andrew Kharlamov</dc:creator>
				<category><![CDATA[Graphic Design]]></category>
		<category><![CDATA[amazing websites]]></category>
		<category><![CDATA[top designs of 2010]]></category>
		<category><![CDATA[top website designs of 2010]]></category>
		<category><![CDATA[top websites 2010]]></category>
		<category><![CDATA[website gallery]]></category>
		<category><![CDATA[websites 2010]]></category>

		<guid isPermaLink="false">http://andrewblogs.com/blog/?p=552</guid>
		<description><![CDATA[When I first started designing websites at twelve; I would stare at others work for hours. Mom said I would go blind, I&#8217;m pretty sure she was right. Aside from that I have developed a keen eye for what a good design is. Throughout this year, I will be adding great website designs right here, [...]]]></description>
			<content:encoded><![CDATA[<p>When I first started designing websites at twelve; I would stare at others work for hours. Mom said I would go blind, I&#8217;m pretty sure she was right. Aside from that I have developed a keen eye for what a good design is.</p>
<p>Throughout this year, I will be adding great website designs right here, so make sure to tune in. <span style="text-decoration: underline;">Click continue reading, to see the rest</span>.</p>
<p><strong>Hold on to your 56k modems, this could get slow.</strong></p>
<p><a href="http://thedarlingstarling.com/" target="_blank">The Darling Starling</a></p>
<p><img src="http://www.andrewblogs.com/sitedesigns2010/thedarlingstarling.jpg" alt="The darling starling" /></p>
<p><span id="more-552"></span></p>
<p><a href="http://31three.com/" target="_blank">31Three</a></p>
<p><img src="http://andrewblogs.com/sitedesigns2010/31three.jpg" alt="31Three" /></p>
<p><a href="http://www.thepixel.com/blog/" target="_blank">The Pixel Blog</a></p>
<p><img src="http://andrewblogs.com/sitedesigns2010/thepixel.jpg" alt="The Pixel Blog" /></p>
<p><a href="http://foxie.ru/" target="_blank">Foxie</a></p>
<p><img src="http://andrewblogs.com/sitedesigns2010/foxiegraphic.jpg" alt="Foxie Graphic" /></p>
<p><a href="http://www.morphix.si/" target="_blank">Morphix</a></p>
<p><img src="http://andrewblogs.com/sitedesigns2010/morphix.jpg" alt="Morphix" /></p>
<p><a href="http://www.cult-f.net/" target="_blank">Cult Foo</a></p>
<p><img src="http://andrewblogs.com/sitedesigns2010/cultfoo.jpg" alt="Cult Foo" /></p>
<p><a href="http://www.kulturbanause.de/" target="_blank">Kulturbanause</a></p>
<p><img src="http://andrewblogs.com/sitedesigns2010/kulturbanause.jpg" alt="Kulturbanause" /></p>
<p>More to come!</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewblogs.com/blog/amazing-website-designs-of-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>In other news, QTAgent32.exe Virus?</title>
		<link>http://andrewblogs.com/blog/in-other-news-qtagent32-exe-virus/</link>
		<comments>http://andrewblogs.com/blog/in-other-news-qtagent32-exe-virus/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 21:36:24 +0000</pubDate>
		<dc:creator>Andrew Kharlamov</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Dell Computer Slow]]></category>
		<category><![CDATA[Humor]]></category>
		<category><![CDATA[QTAgent32.exe]]></category>
		<category><![CDATA[QTAgent32.exe Solution]]></category>
		<category><![CDATA[Virus]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[VS 2010 QTAgent32]]></category>
		<category><![CDATA[VS10 QTAgent32]]></category>

		<guid isPermaLink="false">http://cowfarm.net/?p=318</guid>
		<description><![CDATA[Microsoft, has officially re-released a self aware Dell Hardware destroying Virus in Visual Studio 2010. This virus will effect your computer if you start running Unit Tests, it is currently masquerading around as what appears to be a QuickTimeAgent32 process, to divert the blame on Apple. Over time it will slowly make your hardware less [...]]]></description>
			<content:encoded><![CDATA[<p>Microsoft, has <del datetime="2010-06-23T21:28:00+00:00">officially</del> re-released a self aware Dell Hardware destroying Virus in Visual Studio 2010. This virus will effect your computer if you start running Unit Tests, it is currently masquerading around as what appears to be a QuickTimeAgent32 process, to divert the blame on Apple. </p>
<p>Over time it will slowly make your hardware less functional and will make you want to crawl under your desk, or go after your computer with a baseball bat.</p>
<p>The <a href="http://connect.microsoft.com/VisualStudio/feedback/details/465633/qtagent32-exe-crashes-when-running-a-unit-test-that-calls-itself" target="_blank">current fix</a> is to not run Unit Tests, or if you really have to, you can use ReSharper:</p>
<p> <strong>ReSharper -> Unit Tests -> Run All Tests from Solution.</strong></p>
<p>Yes, this is a <strong>joke</strong>, well the virus part anyway!</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewblogs.com/blog/in-other-news-qtagent32-exe-virus/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Moq Testing Tutorial</title>
		<link>http://andrewblogs.com/blog/moq-testing-tutorial/</link>
		<comments>http://andrewblogs.com/blog/moq-testing-tutorial/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 18:59:18 +0000</pubDate>
		<dc:creator>Andrew Kharlamov</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Mock Objects]]></category>
		<category><![CDATA[Mock q]]></category>
		<category><![CDATA[Mocking]]></category>
		<category><![CDATA[Moq]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://cowfarm.net/?p=156</guid>
		<description><![CDATA[If your reading this then I assume you are either looking for or have an interest in a mocking framework for testing your .NET Applications. In this tutorial I will step you through a framework called Moq for (.NET) released under the New BSD License. I will not be discussing what Mocking is here as [...]]]></description>
			<content:encoded><![CDATA[<p>If your reading this then I assume you are either looking for or have an interest in a mocking framework for testing your .NET Applications.</p>
<p>In this tutorial I will step you through a framework called <strong>Moq</strong> for (.NET) released under the <a href="http://www.opensource.org/licenses/bsd-license.php" target="_blank">New BSD License</a>. I will not be discussing what Mocking is here as that&#8217;s outside the scope of this tutorial. <a href="http://en.wikipedia.org/wiki/Mock_object" target="_blank">What is mocking/mock object?</a></p>
<p>Before we jump in to the code, here are some important links:</p>
<p><a href="http://code.google.com/p/moq/" target="_blank">Get Moq.</a></p>
<p><a href="http://code.google.com/p/moq-contrib/" target="_blank">Get Moq Contrib</a></p>
<p><a href="http://www.clariusconsulting.net/labs/moq/index.html" target="_blank">Moq API.</a></p>
<p>So lets dive in, assuming you already added a reference to the Moq DLL and Moq.Contrib DLL in your project. Let&#8217;s start out by creating a new Abstract class to your project. During this session I am going to call this class: UnitBaseAbstractClass for readability.</p>
<p><span id="more-156"></span></p>
<h3>Creating A Base Test Class</h3>
<p><b>UnitBaseAbstractClass:</b> This class is in charge of setting up a Moq based environment for each of your TestClass&#8217;.</p>
<p>1. First let&#8217;s add the Moq and Moq.Contrib namespaces to this UnitBaseAbstractClass class.</p>
<pre name="code" class="brush:c-sharp">

using Moq;
using Moq.Contrib;
</pre>
<p>That was simple!</p>
<p>2. Now lets add the</b> [TestClass] attribute to the top of this class, for anything extending it will now need to be a test.</p>
<pre name="code" class="brush:c-sharp">
using Moq;
using Moq.Contrib;

namespace MyUnitTests
{
    [TestClass]
    public abstract class UnitBaseAbstractClass
    {
    }
}
</pre>
<p>3. This maybe a bit confusing but bare with me; we are now going to add two public members to our UnitBaseAbstractClass class these are of type MockFactory and AutoMockContainer. See the next example:</p>
<p><b>MockFactory:</b> A utility factory used to manage a mocks lifecycle.</p>
<p><b>AutoMockContainer:</b> A container used to automatically inject mocks into desired objects.</p>
<pre name="code" class="brush:c-sharp">
using Moq;
using Moq.Contrib;

namespace MyUnitTests
{
    [TestClass]
    public abstract class UnitBaseAbstractClass
    {

            public MockFactory _factory;
            public AutoMockContainer _container;

    }
}
</pre>
<p>tada&#8230;</p>
<p>4. We will now need to create a method called &#8220;Setup&#8221; which will take in a MockBehavior enum. In this tutorial we will only use: MockBehavior.Default.</p>
<p><b>MockBehavior:</b> Tells the MockFactory how to behave. The <strong>Strict</strong> behavior throws an exception if a mock isn&#8217;t setup exactly like its mocked object. <strong>Loose</strong> will never throw an exception and <strong>Default</strong> is setup to use the Loose behavior. </p>
<p><i>(If you don&#8217;t understand what this means it&#8217;s alright to move on, as it will not affect you yet.)</i></p>
<p>5. We are going to use Setup to instantiate both MockFactory and AutoMockContainer the factory will need the behavior passed into Setup and the AutoMockContainer will need the MockFactory. </p>
<p>Like this:</p>
<pre name="code" class="brush:c-sharp">
using Moq;
using Moq.Contrib;

namespace MyUnitTests
{
    [TestClass]
    public abstract class UnitBaseAbstractClass
    {

    public MockFactory _factory;
    public AutoMockContainer _container;

        public void Setup(MockBehavior behavior)
        {
            _factory = new MockFactory(behavior);
            _container = new AutoMockContainer(_factory);
        }

    }
}
</pre>
<p>6. Last but not least we want to implement our [TestCleanup]. We will call this method VerifyAll, all it will do is verify that all of our mocks were used and that they were used correctly. Making the final code look something like this:</p>
<pre name="code" class="brush:c-sharp">
using Moq;
using Moq.Contrib;

namespace MyUnitTests
{
    [TestClass]
    public abstract class UnitBaseAbstractClass
    {

    public MockFactory _factory;
    public AutoMockContainer _container;

        public void Setup(MockBehavior behavior)
        {
            _factory = new MockFactory(behavior);
            _container = new AutoMockContainer(_factory);
        }

        [TestCleanup]
        public void VerifyAll()
        {
            _factory.VerifyAll();
        }

    }
}
</pre>
<p>Nice, small, and powerful.</p>
<h3>A Test Class using our Base Class</h3>
<p>The fun part!</p>
<p>1. Let&#8217;s start by writing some tests against this pseudo PersonService class:</p>
<pre name="code" class="brush:c-sharp">
namespace MyRear
{

    public class PersonService
    {
        private readonly IRepository _repository;

        public PersonService(IRepository repository)
        {
              _repository = repository;
        }
        public bool SavePerson(Person person)
        {
        		try{
        		   return _repository.Save(person);
        		}
	        	catch (Exception ex){
	        	   throw new CustomException(ex);
	        	}
        }
    }
}
</pre>
<p>2. Lets create our test class using UnitBaseAbstractClass. Our [TestInitialize] will be using the base Setup method we created in UnitBaseAbstractClass and we will use the</b> AutoMockContainer to create a new instance of our PersonService class. We will also create a new person.</p>
<p>That was a mouthful, like this:</p>
<pre name="code" class="brush:c-sharp">
namespace MyRearTests
{
    [TestClass]
    public class PersonServiceTests : UnitBaseAbstractClass
    {
        private readonly PersonService _service;
	     private Person _person;

        [TestInitialize]
        public void SetupPerson()
        {
            Setup(MockBehavior.Default);
            _service = _container.Create&lt;PersonService&gt;();
	         _person = new Person();
	    }

    }
}
</pre>
<p>3. Time to write the tests! Before that though, I want to show you how to mock _repository.Save the code that calls the Database. Which in this case we do not want to access in our testing environment.</p>
<p>This code:</p>
<pre name="code" class="brush:c-sharp">

return _repository.Save(person);
</pre>
<p>4. First we want to get a mock object for IRepository because this is how we are going to call Save.</p>
<p>We do this with this line of code:</p>
<pre name="code" class="brush:c-sharp">

 _container.GetMock&lt;IRepository&gt;()
</pre>
<p>6. We then want to make sure that we can mock Save. We accomplish this via some Linq we call the Expect method.</p>
<p>In it we call Save and pass our _person object.</p>
<pre name="code" class="brush:c-sharp">

 _container.GetMock&lt;IRepository&gt;()
	    .Expect(s => s.Save(_person))
</pre>
<p>7. We then need to tell the object what to return (in this case I return a bool, lets say true). After calling the Returns method make sure to verify that this mock was even needed via Verifiable method.</p>
<pre name="code" class="brush:c-sharp">
 _container.GetMock&lt;IRepository&gt;()
	    .Expect(s => s.Save(_person))
	    .Returns(true)
	    .Verifiable();
</pre>
<p>8. Lets make it a test now!</p>
<pre name="code" class="brush:c-sharp">
namespace MyRearTests
{
    [TestClass]
    public class PersonServiceTests : UnitBaseAbstractClass
    {
        private readonly PersonService _service;
	    private Person _person;

        [TestInitialize]
        public void PersonServiceSetup()
        {
            Setup(MockBehavior.Default);
            _service = _container.Create&lt;PersonService&gt;();
	        _person = new Person();
	    }

        [TestMethod]
        public void SavePersonSuccess()
        {
 	        var result =
        	        _container.GetMock&lt;IRepository&gt;()
		            .Expect(s => s.Save(_person))
	            	    .Returns(true)
		            .Verifiable();

            Assert.IsTrue(result, "Person should have saved.");
        }

    }
}
</pre>
<p>9. Lets add another test that returns false, a failed save.</p>
<pre name="code" class="brush:c-sharp">
namespace MyRearTests
{
    [TestClass]
    public class PersonServiceTests : UnitBaseAbstractClass
    {
        private readonly PersonService _service;
	    private Person _person;

        [TestInitialize]
        public void PersonServiceSetup()
        {
            Setup(MockBehavior.Default);
            _service = _container.Create&lt;PersonService&gt;();
	        _person = new Person();
	    }

        [TestMethod]
        public void SavePersonSuccess()
        {
 	        var result =
        	    _container.GetMock&lt;IRepository&gt;()
		            .Expect(s => s.Save(_person))
		            .Returns(true)
		            .Verifiable();

            Assert.IsTrue(result, "Person should save.");
        }

        [TestMethod]
        public void SavePersonFail()
        {
 	        var result =
        	        _container.GetMock&lt;IRepository&gt;()
		            .Expect(s => s.Save(_person))
		            .Returns(false)
		            .Verifiable();

            Assert.IsFalse(result, "Person should not save.");
        }

    }
}
</pre>
<p>10. The last test is a bit tricky its why we wrapped Save in PersonService with a try catch and threw a custom exception. </p>
<p>First lets write something like this:</p>
<pre name="code" class="brush:c-sharp">

 _container.GetMock&lt;IRepository&gt;()
	    .Expect(s => s.Save(_person))
</pre>
<p>11. Handling exceptions is different then normal asserts throwing them is different too. </p>
<p>In order to throw an exception we need to call the Throws method instead of returns.</p>
<pre name="code" class="brush:c-sharp">
 _container.GetMock&lt;IRepository&gt;()
	    .Expect(s => s.Save(_person))
	    .Throws(new Exception("Save Threw Up"))
	    .Verifiable();
</pre>
<p>12. Lets make sure we handle the code. We do this with the [ExpectedException] attribute on our test methods.</p>
<p>Like so:</p>
<pre name="code" class="brush:c-sharp">
        [TestMethod]
        [ExpectedException(typeof(CustomException))]
        public void SavePersonException()
        {
		        _container.GetMock&lt;IRepository&gt;()
		        .Expect(s => s.Save(_person))
		        .Throws(new Exception("Save Threw Up"))
		        .Verifiable();
	        }
</pre>
<p>13. The Final Test looks like this:</p>
<pre name="code" class="brush:c-sharp">
namespace MyRearTests
{
    [TestClass]
    public class PersonServiceTests : UnitBaseAbstractClass
    {
        private readonly PersonService _service;
	    private Person _person;

        [TestInitialize]
        public void PersonServiceSetup()
        {
            Setup(MockBehavior.Default);
            _service = _container.Create&lt;PersonService&gt;();
	        _person = new Person();
	    }

        [TestMethod]
        public void SavePersonSuccess()
        {
 	        var result =
        	    _container.GetMock&lt;IRepository&gt;()
		    .Expect(s => s.Save(_person))
		    .Returns(true)
		    .Verifiable();

            Assert.IsTrue(result, "Person should save.");
        }

        [TestMethod]
        public void SavePersonFail()
        {
 	        var result =
        	    _container.GetMock&lt;IRepository&gt;()
		    .Expect(s => s.Save(_person))
		    .Returns(true)
		    .Verifiable();

            Assert.IsFalse(result, "Person should not save.");
        }

        [TestMethod]
        [ExpectedException(typeof(CustomException))]
        public void SavePersonException()
        {
		    _container.GetMock&lt;IRepository&gt;()
		     .Expect(s => s.Save(_person))
		     .Throws(new Exception("Save Threw Up"))
		     .Verifiable();
	    }
    }
}
</pre>
<p>I hope this helped you out a bit more in understanding the Moq Framework. Good Luck, let me know if I need to change anything in the tutorial or make anything clearer!</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewblogs.com/blog/moq-testing-tutorial/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Consume a WordPress RSS Feed in C# and cache it.</title>
		<link>http://andrewblogs.com/blog/consume-wordpress-rss-feed-in-c-sharp-and-cache-it/</link>
		<comments>http://andrewblogs.com/blog/consume-wordpress-rss-feed-in-c-sharp-and-cache-it/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 15:22:02 +0000</pubDate>
		<dc:creator>Andrew Kharlamov</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[how do I load an rss feed in c#]]></category>
		<category><![CDATA[load rssfeed C#]]></category>
		<category><![CDATA[rss feed C#]]></category>
		<category><![CDATA[rssfeed in c#]]></category>
		<category><![CDATA[wordpress feed]]></category>
		<category><![CDATA[wordpress rss feed in c#]]></category>

		<guid isPermaLink="false">http://cowfarm.net/?p=396</guid>
		<description><![CDATA[I couldn&#8217;t find a simple example of reading a WordPress Blog Feed in C# and caching it. So I decided to write out my own. Here is an example to get you started. I wrote it in two parts: A Class that Consumes a Feed (FeedReader) An Object representing a Feed Item (FeedViewModel). And so [...]]]></description>
			<content:encoded><![CDATA[<p>I couldn&#8217;t find a simple example of reading a WordPress Blog Feed in C# and caching it. So I decided to write out my own.</p>
<p>Here is an example to get you started. I wrote it in two parts:</p>
<p><strong>A Class that Consumes a Feed</strong> (FeedReader)<br />
<strong>An Object representing a Feed Item</strong> (FeedViewModel).</p>
<p>And so we begin:</p>
<p><span id="more-396"></span></p>
<pre class="brush:c-sharp">using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

namespace FeedExample
{

	public class FeedReader
	{
		public static IList&lt;FeedViewModel&gt; GetBlogFeed(string feedUrl, int feedCount)
		{
			//Load feed via a feedUrl.
			var doc = XDocument.Load(feedUrl); 

			//Get all the "items" in the feed.
			var feeds = doc.Descendants("item").Select(x =&gt;
					new FeedViewModel
					{
					     //Get title, pubished date, and link elements.
						Title = x.Element("title").Value, //3
						PublishedDate = DateTime.Parse(x.Element("pubDate").Value),
						Url = x.Element("link").Value
					} //  Put them into an object (FeedViewModel)
					)
					// Order them by the pubDate (FeedViewModel.PublishedDate).
					.OrderByDescending(x=&gt; x.PublishedDate)
					//Only get the amount specified, the top (1, 2, 3, etc.) via feedCount.
					.Take(feedCount);

 			//Convert the feeds to a List and return them.
			return feeds.ToList();
		}
	}

	public class FeedViewModel
	{
		public string Title { get; set; }
		public string Url { get; set; }
		public DateTime PublishedDate { get; set; }
	}

}
</pre>
<p>You can get some more items from the feed like: title, link, comments, pubDate, dc:creator, category, guid, description, content:encoded, etc&#8230;</p>
<p>To prevent your website from slowing down you can cache your feed like this:</p>
<pre class="brush:c-sharp">//Check if feed exists
if (HttpRuntime.Cache["Feed"] == null)
				{
					//If it is, insert it into the cache, cache for 10 minutes
					HttpRuntime.Cache.Insert("Feed",
						FeedReader.GetBlogFeed("url", 5), null, SystemTime.Now().AddMinutes(10), Cache.NoSlidingExpiration);
				}

//retrieve cached feeds
var cachedFeeds = (List&lt;FeedItemViewModel&gt;) HttpRuntime.Cache["Feed"]
</pre>
<p>HttpRuntime.Cache is part of the System.Web namespace.</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewblogs.com/blog/consume-wordpress-rss-feed-in-c-sharp-and-cache-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC Email Template Solution</title>
		<link>http://andrewblogs.com/blog/asp-net-mvc-email-solution/</link>
		<comments>http://andrewblogs.com/blog/asp-net-mvc-email-solution/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 15:23:25 +0000</pubDate>
		<dc:creator>Andrew Kharlamov</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ASP Email]]></category>
		<category><![CDATA[ASP.NET EMAIL Templates]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[email template engine]]></category>
		<category><![CDATA[EmailTemplates]]></category>
		<category><![CDATA[MVC Email]]></category>
		<category><![CDATA[Spark]]></category>
		<category><![CDATA[Spark Email]]></category>
		<category><![CDATA[spark template engine]]></category>
		<category><![CDATA[Spark View Engine]]></category>

		<guid isPermaLink="false">http://cowfarm.net/?p=188</guid>
		<description><![CDATA[If you are like me then you have probably ran into a wall with using ASP.NET MVC View Engine to render your awesome Dynamic HTML Email Templates. At least you put up a fight using a lot of fake data. It is actually possible to get around it! var oldContext = HttpContext.Current; HttpContext.Current = new [...]]]></description>
			<content:encoded><![CDATA[<p>If you are like me then you have probably ran into a wall with using ASP.NET MVC View Engine to render your awesome Dynamic HTML Email Templates. At least you put up a fight using a lot of fake data. It is actually possible to get around it!</p>
<pre name="code" class="brush:c-sharp">

        var oldContext = HttpContext.Current;
        HttpContext.Current = new HttpContext(HttpContext.Current.Request,
        fakeResponse);

        var html = new HtmlHelper(new ViewContext(fakeControllerContext,
        new FakeView(), fakeViewDataDictionary, new TempDataDictionary()),
        new ViewPage());

        html.RenderPartial(viewName, viewData, viewDataDictionary);
        HttpContext.Current = oldContext; //yay 
</pre>
<p>Though, because you’re reading this you&#8217;re like me and you never give up! So how, how do you get around all of this? The answer is Spark. Eeek, another DLL? Yes, Spark is its own View Engine which is an entire different framework. Yes, you have to go to their website download the DLLS, put it in your Lib folder and reference it in your code. Let me tell you now, it is well worth it. Let&#8217;s dive in!</p>
<p>Let&#8217;s write the code to render our email using the Spark. We want our code to take in the template name, something like: &#8220;ForgotUsernameEmail.spark&#8221; and we also want it to reuse our current ViewData Object which is of type ViewDataDictionary and contains Person data, we will need to add this into our own implementation of AbstractSparkView. See samples bellow: </p>
<p><span id="more-188"></span></p>
<p><strong>Render Email Method:</strong></p>
<pre name="code" class="brush:c-sharp">

public string RenderEmail(string sparkViewName, ViewDataDictionary
viewData)
{
     var email = new StringWriter();
     var view = (EmailTemplateBase) _engine.CreateInstance(new
     SparkViewDescriptor().AddTemplate(sparkViewName));
     view.ViewData = viewData;

     try
     {
         view.RenderView(email);
     }
     finally
     {
         _engine.ReleaseInstance(view);
     }
     return email.ToString();
}
</pre>
<p><em>Oops thanks Arnis, forgot to mention EmailTemplateBase is just an extended version of AbstractSparkView that includes the ASP.NET MVC ViewDataDictionary.</em></p>
<p><strong>Custom Spark AbstractSparkView with ViewData implementation:</strong></p>
<pre name="code" class="brush:c-sharp">

    public abstract class EmailTemplateBase : AbstractSparkView
    {
        public ViewDataDictionary ViewData { get; set; }

        public object Eval(string expression)
        {
            return ViewData.Eval(expression);
        }

        public string Eval(string expression, string format)
        {
            return ViewData.Eval(expression, format);
        }

    }
</pre>
<p>So that&#8217;s done, let’s make the template… In my MVC Web Project I am going to add into my Views folder or maybe even Views/Email <img src='http://andrewblogs.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  a file called &#8220;ForgotUsernameEmail.spark&#8221;.</p>
<pre name="code" class="brush:html">

Dear ${#name}:


Your username is ${#userName}.


Thank You.
<use file="~/Views/Email/Signature"/>
</pre>
<p>I also put in a use tag to pull down a Signature file, since this is the same in everyone of my emails. Now let’s actually write the code to call it:</p>
<pre name="code" class="brush:c-sharp">

string email = RenderEmail("ForgotUsernameEmail.spark",ViewData);
</pre>
<p>And that’s all you need to do, well besides read up on spark syntax: <a href ="http://www.sparkviewengine.com/documentation/configuring" target="_blank">http://www.sparkviewengine.com/documentation/configuring</a></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewblogs.com/blog/asp-net-mvc-email-solution/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ASP.NET View Testing (MVC)</title>
		<link>http://andrewblogs.com/blog/aspnet-view-testing-mvc/</link>
		<comments>http://andrewblogs.com/blog/aspnet-view-testing-mvc/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 15:59:01 +0000</pubDate>
		<dc:creator>Andrew Kharlamov</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://cowfarm.net/?p=16</guid>
		<description><![CDATA[I have recently been introduced to a company by the name of <a href="http://www.artoftest.com">ArtOfTest</a> a Microsoft Gold Certified Partner and for a good reason. The company has two products: “Automation Design Canvas” and the “WebAii” Framework, both incredibly useful tools. ]]></description>
			<content:encoded><![CDATA[<p>There comes a time in our lives where front-end testing is a must for our web applications&#8230; </p>
<p>I have recently been introduced to a company by the name of <a href="http://www.artoftest.com">ArtOfTest</a> a Microsoft Gold Certified Partner and for a good reason. The company has two products: “Automation Design Canvas” and the &#8220;WebAii&#8221; Framework, both incredibly useful tools. </p>
<p>The one I am going to write and sample today is the WebAii Framework, available as a free download from: <a href="http://www.artoftest.com/webaiifxproduct.aspx">ArtOfTest WebAii</a>. </p>
<p><strong>Overview:</strong><br />
This light weight testing framework is perfect for writing tests in NUnit or Visual Studio Team Test because it seamlessly integrates with your current project and really doesn&#8217;t take any setup due to the provided Visual Studio Templates that come with the installer. All you need to do is write the tests.</p>
<p>So let’s dive into some quick code snippets from the website:</p>
<p><span id="more-16"></span></p>
<p><strong>Ajax JavaScript Automation Testing:</strong></p>
<pre name="code" class="brush:c-sharp">
[TestMethod] //Define your test method (VS Test)
public void AjaxJsAutomation()
{
      // Wait for a specific element with id 'containing' foo to exist
      Element e = new Element(new FindParam("id=~foo"), ActiveBrowser);
      e.Wait.ForExists();

      // Convert the generic element to an HtmlDiv
      HtmlDiv myDiv = e.As&lt;HtmlDiv&gt;(); 

      // Now invoke a javascript function on my page directly.
      Actions.InvokeScript("myJsFunction('param')");

      // Wait for a color "computed" style to become red
      myDiv.Wait.ForStyles(true, "color=red");

      // Invoke OnFocus event
      myDiv.InvokeEvent(ScriptEventType.OnFocus);

      // Wait for the div to be invisible.
      myDiv.Wait.ForVisibleNot();

      // Move the mouse over the div
      myDiv.MouseHover();

      //Write assertion code here.
}
</pre>
<p>This is probably one of the cooler features of WebAii. What this code is doing is pulling an element with an id of &#8220;~foo&#8221; as soon as it exists. Then after the item exists this code is invoking a javascript function and actually waiting for the javascript to change data on your page. </p>
<p><strong>Asp.NET Testing:</strong></p>
<pre name="code" class="brush:c-sharp">
[TestMethod] //Define your test method (VS Test)
public void AspNetTesting()
{
      // Set the local server to be Asp.Net local server (aka cassini)
      Manager.Settings.LocalWebServer = LocalWebServerType.AspNetDevelopmentServer;
      Manager.Settings.WebAppPhysicalPath = @"C:\myAspNetApp\Test";

      // Launch a new browser
      Manager.LaunchNewBrowser();

      // Navigate to a page in your app.
      ActiveBrowser.NavigateTo("/main.aspx");

      // Get the grid using partial id.
      Element grid = Find.ById("~dataGrid1");

      //Write assertion code here.
}
</pre>
<p>As you can see testing asp.NET applications is as easy as setting up the local web server and web application physical path. The rest as usual, launch the web browser via the Manager, get/set your elements and then run your assertions.</p>
<p>So I should probably get back to writing my tests at work but there is a lot more goodness in WebAii and I encourage you to take a look at it when you get a chance and the best place to start is the documentation: <a href="http://www.artoftest.com/Resources/WebAii/Documentation/topicsindex.aspx">Web Aii Docs</a></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewblogs.com/blog/aspnet-view-testing-mvc/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
