<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-9059110702732375767</id><updated>2012-03-07T14:08:29.763-08:00</updated><category term='MVC'/><category term='introduction'/><category term='client'/><category term='Dependency Injection'/><category term='Moq'/><category term='DB4O'/><category term='Object-Oriented Database'/><category term='service'/><category term='ASP.NET MVC 3'/><category term='Programming'/><category term='ASP.NET'/><category term='C#'/><category term='console'/><category term='Extreme'/><category term='Development'/><category term='Introduction to WCF'/><category term='ruby on rails'/><category term='TDD'/><category term='Agile'/><category term='ecommerce'/><category term='Scrum'/><category term='Software'/><category term='Sprint'/><category term='shop'/><category term='GitHub Git install upload configure'/><category term='model'/><title type='text'>Daniel Glyde</title><subtitle type='html'>Thoughts, ideas and comments on technical and managerial solutions</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://danielglyde.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://danielglyde.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Daniel Glyde</name><uri>http://www.blogger.com/profile/07266718495570206021</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>7</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-9059110702732375767.post-7386514124753381405</id><published>2011-07-12T14:29:00.000-07:00</published><updated>2011-07-12T14:49:57.720-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Dependency Injection'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET MVC 3'/><category scheme='http://www.blogger.com/atom/ns#' term='TDD'/><category scheme='http://www.blogger.com/atom/ns#' term='Moq'/><title type='text'>TDD with ASP.NET MVC 3, Moq and Dependency Injection</title><content type='html'>&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;Introduction&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Purpose&lt;/span&gt;&lt;br /&gt;The purpose of this article is to explain what TDD is and give an example in terms of the process.&lt;br /&gt;&lt;br /&gt;So what does TDD stand for, well according to Wikipedia it is Test Driven Development but having read around the subject looking at blogs from Brad Wilson it should really be Test Driven Design, or as his want &lt;a href="http://bradwilson.typepad.com/blog/2009/04/its-not-tdd-its-design-by-example.html"&gt;Design By Example&lt;/a&gt; but this doesn't fit in the acronym. &amp;nbsp;I'll stick with Test Driven Design.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Approach&lt;/span&gt;&lt;br /&gt;Instead  of writing the controller and repository first instead I will create  the test and use Visual Studio 2010 to automatically generate the  classes, methods and properties as dictated by the test.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Patterns&lt;/span&gt;&lt;br /&gt;So what about patterns? &amp;nbsp;Well in this example I will use the Dependency Injection, &amp;nbsp;Repository, Mock Object Design and MVC patterns.&lt;br /&gt;&lt;br /&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Project&lt;/span&gt;&lt;/div&gt;&lt;div&gt;A simple repository call that returns a list of blog entries with URLs built from the title field.&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Toolset&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;To use Moq for the Mock Object Framework&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Version: 4.0.10827&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Mock objects are faked objects that imitate the activities of real objects in a controlled manner.&lt;/div&gt;&lt;div&gt;To mock an interface to the data access component while testing the business logic. &amp;nbsp;This avoids writing code until you are ready to do so.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Moq takes advantage of recent VB.NET and C# language features such as lambdas and generics. When creating mock objects with Moq, you use lambda expressions to represent the methods and properties that you want to mock.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;Download instructions&lt;/i&gt;&lt;/div&gt;Download Moq from: http://code.google.com/p/moq/downloads/list&lt;br /&gt;Ensure you unblock the zip file once you have downloaded it.&lt;br /&gt;For this example I am using .NET 4 so I will need to use the Moq DLL from:&lt;br /&gt;\Moq.4.0.10827.Final\Moq.4.0.10827\NET40&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div&gt;&lt;div&gt;&lt;b&gt;NUnit&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Version: 2.5.10.11092&lt;/div&gt;&lt;div&gt;NUnit is a unit testing framework for .NET. &amp;nbsp;The units of code are tested to ascertain if they are fit for use.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;i&gt;Download instructions&lt;/i&gt;&lt;/div&gt;Download NUnit from here: http://www.nunit.org/index.php?p=download&lt;br /&gt;Use the .msi file.&lt;br /&gt;Install with Typical and use the defaults.&lt;br /&gt;Follow the installation guide here:&lt;br /&gt;http://www.nunit.org/index.php?p=installation&amp;amp;r=2.5.10&lt;br /&gt;C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit.exe.config&lt;br /&gt;&lt;a href="http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/"&gt;To add NUnit to Visual Studio tools menu in VS 2010&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In Visual Studio have the test project highlighted before running NUnit from the Tool menu.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;div&gt;&lt;b&gt;MVC for the Web Application Framework&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;Version: ASP.NET MVC &amp;nbsp;3.&lt;/div&gt;&lt;div&gt;The Model View Controller is a software architecture software pattern.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;Coding&lt;/span&gt;&lt;br /&gt;Ok, let's get our hands dirty. &lt;br /&gt;&lt;br /&gt;Firstly I know that I want to use MVC for this project so we kick off with an empty MVC framework.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Create the MVC project &lt;/span&gt;&lt;br /&gt;In Visual Studio 2010: New Project... &lt;br /&gt;&lt;br /&gt;ASP.NET MVC 3 Web Application &lt;br /&gt;&lt;br /&gt;TDDBlog &lt;br /&gt;&lt;br /&gt;Empty &lt;br /&gt;&lt;br /&gt;View engine: Razor&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Create the test project &lt;/span&gt;&lt;br /&gt;Create a new  Class Library Project called TDDBlog.Tests &lt;br /&gt;&lt;br /&gt;Right Click and Add a reference to TDDBlog from the Projects tab &lt;br /&gt;&lt;br /&gt;Right click and Add a reference to nunit.framework from the .NET &lt;br /&gt;&lt;br /&gt;Create a new folder structure \Library &lt;br /&gt;&lt;br /&gt;Copy the Moq.dll to \Library\Moq &lt;br /&gt;&lt;br /&gt;Right click and Add a reference to Moq.dll &lt;br /&gt;&lt;br /&gt;Delete Class1.cs&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Create a test for the controller &lt;/span&gt;&lt;br /&gt;So we know that we are dealing with a Blog so I will want a BlogController.  But before I go ahead and start building that up I will create the test first. &lt;br /&gt;&lt;br /&gt;So in the TDDBlog.Tests &lt;br /&gt;&lt;br /&gt;Create a new folder structure \Controllers &lt;br /&gt;&lt;br /&gt;Add a new class: BlogControllerTest and make it public, as we are using NUnit we want to tell NUnit that the class we are using is testable, this requires us to reference the NUnit framework in our code and add the TestFixture attribute to the class:&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;using NUnit.Framework;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;namespace TDDBlog.Tests.Controllers&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; [TestFixture]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class BlogControllerTest&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;Let's check to see if it builds. &lt;br /&gt;&lt;br /&gt;Ok, hopefully you had some joy there.  So I want to return a list of blog entries and check the format of the URL. &lt;br /&gt;&lt;br /&gt;As we are using MVC the test is a call on the Index Action: &lt;br /&gt;&lt;br /&gt;Index returns a list of blog entries with correct Urls&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;[Test]&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;public void IndexReturnsAListOfBlogEntriesWithCorrectUrls()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;You will notice the [Test] attribute on the method, this as you may have guessed tells NUnit that this is a test.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Hook up with NUnit &lt;/span&gt;&lt;br /&gt;Now we have our empty test lets run it in NUnit. &lt;br /&gt;&lt;br /&gt;Now we have NUnit set up in the Tools menu we can run it from there.  Ensure you highlight the TDDBlog.Tests project. &lt;br /&gt;&lt;br /&gt;If it does not load with the correct DLL, simply: File &amp;gt; Open Project and select the TDDBlog.Tests.dll. &lt;br /&gt;&lt;br /&gt;Click Run to execute the test. &lt;br /&gt;&lt;br /&gt;We will see a green light, this is the default behaviour; if no test content is present then the is nothing to fail.&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Start building the test and let the compiler guide you &lt;/span&gt;&lt;br /&gt;So our blog will have BlogEntry class objects, to set this up we will Mock a list of these. &lt;br /&gt;&lt;br /&gt;A Mock defines the results from calls it does not set the content on objects.  I like Moq as it uses Lambda expressions. &lt;br /&gt;&lt;br /&gt;Create a Mock for BlogEntry:&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt; line-height: 115%;"&gt;var mockBlogEntry1 = new Mock&lt;blogentry&gt;(&amp;lt;BlogEntry&amp;gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/blogentry&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;Add a reference to Moq in your code:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt; line-height: 115%;"&gt;using Moq;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;Build the project, it will fail with:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNormal"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt; line-height: 115%;"&gt;The type or namespace name 'BlogEntry' could not be found (are you missing a using directive or an assembly reference?)&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;So no surprise, we need to create this class.&lt;br /&gt;&lt;br /&gt;Left click on BlogEntry in the test method.  If you have reSharper installed you will get a red light bulb appear on the left allowing you to create a new class called BlogEntry Visual Studio 2010 has the same functionality.  Hover over BlogEntry and a icon with a tool tip of, 'Options to help bind the selected item' appears; extend this and click on 'Generate new type...'. &lt;br /&gt;&lt;br /&gt;This will allow you to specify the location and access:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;ul&gt;&lt;li&gt;Access: public&lt;/li&gt;&lt;li&gt;Kind: class&lt;/li&gt;&lt;li&gt;Location: TDDBlog&lt;/li&gt;&lt;li&gt;Create new file: Models\BlogEntry.cs&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;It will also add the reference to the file. &lt;br /&gt;&lt;br /&gt;Next we want to set some fields on the new class again this do this from the test.&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;const int id1 = 1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;const string title1 = "My first blog Entry";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;const string content1 = "I love blogging, it is so cool";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;mockBlogEntry1.SetupGet(x =&amp;gt; x.Id).Returns(id1);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;mockBlogEntry1.SetupGet(x =&amp;gt; x.Title).Returns(title1);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;mockBlogEntry1.SetupGet(x =&amp;gt; x.Content).Returns(content1);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New';"&gt;&lt;span class="Apple-style-span" style="font-size: 11px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;So we know that this won't compile and from what we have learnt we can get our test to do some work for us.  Click on Id, hover and 'Generate property stub for 'ID' in 'TDDBlog.Models.BlogEntry'.&amp;nbsp; &lt;br /&gt;&lt;br /&gt;So your BlogEntry class should look like:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;namespace TDDBlog.Models&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class BlogEntry&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Id Id { get; set; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Title Title { get; set; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Content Content { get; set; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;Modify the class to use the correct types and add virtual (this is required for Moq):&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;namespace TDDBlog.Models&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class BlogEntry&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public virtual int Id { get; set; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public virtual string Title { get; set; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public virtual string Content { get; set; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;Create a couple of other BlogEntries.&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 11px;"&gt;const int id2 = 2;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;const string title2 = "I'm still in to this";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;const string content2 = "I'm still enjoying my blogging";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;var mockBlogEntry2 = new Mock&lt;blogentry&gt;(&lt;/blogentry&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt; line-height: 115%;"&gt;&amp;lt;BlogEntry&amp;gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;blogentry&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/blogentry&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;mockBlogEntry2.SetupGet(x =&amp;gt; x.Id).Returns(id2);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;mockBlogEntry2.SetupGet(x =&amp;gt; x.Title).Returns(title2);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;mockBlogEntry2.SetupGet(x =&amp;gt; x.Content).Returns(content2);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;const int id3 = 3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;const string title3 = "OK!";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;const string content3 = "Ok, I'm done!";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;var mockBlogEntry3 = new Mock&lt;blogentry&gt;(&lt;/blogentry&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt; line-height: 115%;"&gt;&amp;lt;BlogEntry&amp;gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;blogentry&gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/blogentry&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;mockBlogEntry3.SetupGet(x =&amp;gt; x.Id).Returns(id3);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;mockBlogEntry3.SetupGet(x =&amp;gt; x.Title).Returns(title3);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;mockBlogEntry3.SetupGet(x =&amp;gt; x.Content).Returns(content3);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;SetupGet is used for Properties on a Class. &lt;br /&gt;&lt;br /&gt;The next thing to do is to work out how we are going to store this, notice I say how not where.  Let's say we are going to use a repository pattern. Mock an IBlogsRepository (again don't create it first).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;var blogRepository = new Mock&lt;iblogsrepository&gt;(&amp;lt;IBlogsRepository&amp;gt;);&lt;o:p&gt;&lt;/o:p&gt;&lt;/iblogsrepository&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;Follow the same process as before: &lt;br /&gt;&lt;ul&gt;&lt;li&gt;Access: public&amp;nbsp;&lt;/li&gt;&lt;li&gt;Kind: interface&amp;nbsp;&lt;/li&gt;&lt;li&gt;Project: TDDBlog&amp;nbsp;&lt;/li&gt;&lt;li&gt;Create new file: Models\IBlogsRepository&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;Ok, so we now have a new interface, lets Mock a call on it:&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;blogRepository&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Setup(p =&amp;gt; p.GetAllBlogEntries())&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; .Returns(new List&lt;blogentry&gt;&amp;lt;BlogEntry&amp;gt; { newBlogEntry.Object });&lt;/blogentry&gt;&lt;/span&gt;&lt;span style="font-family: 'Courier New';"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span class="Apple-style-span" style="font-family: 'Courier New';"&gt;&lt;span class="Apple-style-span" style="font-size: 11px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;You will need to add a reference to Systems.Collections.Generic. &lt;br /&gt;&lt;br /&gt;Setup works in the same way as SetupGet but is for method calls not Properties on a Class. &lt;br /&gt;&lt;br /&gt;Add the interface method for GetAllBlogEntries by clicking on the method and generating from the test: 'Generate method stub for 'GetAllBlogEntries' for 'TDDBlog.Models.IBlogsRepository' &lt;br /&gt;&lt;br /&gt;The interface will look like:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;namespace TDDBlog.Models&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public interface IBlogsRepository&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; object GetAllBlogEntries();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;Add the correct return type:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;namespace TDDBlog.Models&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public interface IBlogsRepository&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IEnumerable&lt;blogentry&gt;&amp;lt;BlogEntry&amp;gt; GetAllBlogEntries();&lt;o:p&gt;&lt;/o:p&gt;&lt;/blogentry&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;So that is our repository set up and Mocked, and the objects inside it Mocked.&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Test the Controller                                                                          &lt;/span&gt;&lt;br /&gt;We will inject the controller with the repository. &lt;br /&gt;&lt;br /&gt;In the test we will initialise the controller - we will start with the test code before getting the test code to create the Controller:&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt; line-height: 115%;"&gt;BlogController blogController = new BlogController((IBlogsRepository)blogRepository.Object);&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;You know the steps by now: &lt;br /&gt;&lt;ul&gt;&lt;li&gt;Access: public&amp;nbsp;&lt;/li&gt;&lt;li&gt;Kind: class&amp;nbsp;&lt;/li&gt;&lt;li&gt;Project: TDDBlog&amp;nbsp;&lt;/li&gt;&lt;li&gt;Create new file: Controllers\BlogController.cs&amp;nbsp;&lt;/li&gt;&lt;/ul&gt;Next we need to create the constructor. &lt;br /&gt;&lt;br /&gt;Again click and hover on the BlogController, and 'Generate constructor stub in 'TDDBlog.Controllers.BlogController'. &lt;br /&gt;&lt;br /&gt;This generates:&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;namespace TDDBlog.Controllers&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class BlogController&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private Models.IBlogsRepository iBlogsRepository;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public BlogController(Models.IBlogsRepository iBlogsRepository)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // TODO: Complete member initialization&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; this.iBlogsRepository = iBlogsRepository;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;Inherit the BlogController from Controller and add a reference to System.Web.Mvc. &lt;br /&gt;&lt;br /&gt;Next we need to call the controller method to get the result.  We are going to assume that the Index call is going to be used:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;ViewResult viewResult = blogController.Index() as ViewResult;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;We need to ensure out test project knows what a ViewResult is, add System.Web.Mvc to the TDDBlog.Tests project. &lt;br /&gt;&lt;br /&gt;Then get Visual Studio 2010 add the reference to the file by hover etc... &lt;br /&gt;&lt;br /&gt;Create the Index method in the Controller by the usual method as described above. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;public ViewResult Index()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new NotImplementedException();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Start testing &lt;/span&gt;&lt;br /&gt;We want to get the URL for each blog entry but this will not be in the repository.&amp;nbsp; &lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;List&amp;lt;BlogEntry&amp;gt;&lt;blogentry&gt; blogEntries = (System.Collections.Generic.List&lt;blogentry&gt;)viewResult.ViewData.Model;&lt;o:p&gt;&lt;/o:p&gt;&lt;/blogentry&gt;&lt;/blogentry&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;BlogEntry blogEntry1 = blogEntries[0];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(id1, blogEntry1.Id);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(title1, blogEntry1.Title);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;const string url1 = "my-first-blog-entry";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(url1, blogEntry1.Url);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(content1, blogEntry1.Content);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;BlogEntry blogEntry2 = blogEntries[1];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(id2, blogEntry2.Id);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(title2, blogEntry2.Title);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;const string url2 = "I'm still in to this";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(url2, blogEntry2.Url);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(content2, blogEntry2.Content);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;BlogEntry blogEntry3 = blogEntries[2];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(id3, blogEntry3.Id);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(title3, blogEntry3.Title);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;const string url3 = "ok";&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(url3, blogEntry3.Url);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;Assert.AreEqual(content3, blogEntry3.Content);&lt;/span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;The Url property does not exist at this point in the BlogEntry, so add the property stub from the test, set the correct type:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;public string Url { get; set; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;Notice this is not set to virtual as it is not going to be Mocked or used by the repository. &lt;br /&gt;&lt;br /&gt;Right, that is the test code complete, so what happens when we run our test?&lt;/div&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;/span&gt;  &lt;span class="Apple-style-span" style="font-size: large;"&gt;Expected failure&lt;/span&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&amp;nbsp;&lt;/span&gt;&lt;br /&gt;So we are seeing red!  Let's look at the output window: &lt;br /&gt;&lt;br /&gt;TDDBlog.Tests.Controllers.BlogControllerTest.IndexReturnsAListOfBlogEntriesWithCorrectUrls: &lt;br /&gt;&lt;br /&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;TDDBlog.Tests.Controllers.BlogControllerTest.IndexReturnsAListOfBlogEntriesWithCorrectUrls:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt; line-height: 115%;"&gt;System.NotImplementedException : The method or operation is not implemented.&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Not a big shock as we have not implemented the Index method on the controller yet. &lt;br /&gt;&lt;br /&gt;Let's do this now:&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;public ViewResult Index()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return View(iBlogsRepository.GetAllBlogEntries());&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;span style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 115%;"&gt;Ok, run again.&amp;nbsp; Hmm red again what now:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;span style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 115%;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 115%;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;TDDBlog.Tests.Controllers.BlogControllerTest.IndexReturnsAListOfBlogEntriesWithCorrectUrls:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 115%;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp; Expected: "my-first-blog-entry"&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 115%;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp; But was:&amp;nbsp; null&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing" style="font-family: Calibri, sans-serif; font-size: 11pt; line-height: 115%;"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;Ok, that makes sense, we have not changed the controller to set the Url, this is a good test as before we were just returning what we put in the Mock framework. &lt;br /&gt;&lt;br /&gt;So we need to change the controller:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div class="MsoNoSpacing"&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;public ViewResult Index()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; IEnumerable&lt;blogentry&gt;&amp;lt;BlogEntry&amp;gt; blogEntries = iBlogsRepository.GetAllBlogEntries();&lt;o:p&gt;&lt;/o:p&gt;&lt;/blogentry&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (BlogEntry blogEntry in blogEntries)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;blogEntry.Url = blogEntry.Title.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Replace("'", string.Empty).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Replace("!", string.Empty).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Replace(" ", "-").&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ToLower();&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return View(blogEntries);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;}&lt;b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="MsoNoSpacing"&gt;&lt;span style="font-family: 'Courier New'; font-size: 8pt;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;The test now passes; woo and indeed hoo!&lt;br /&gt;&lt;br /&gt;&lt;span class="Apple-style-span" style="font-size: x-large;"&gt;Summary &lt;/span&gt;&lt;br /&gt;So, we created an MVC project designed by our tests.  We only implemented what was required so there was no redundant code which is something that can happen when just cracking out the code. &lt;br /&gt;&lt;br /&gt;As I used Moq, I did not have to configure or populate a database or some other repository. &lt;br /&gt;&lt;br /&gt;By using Dependency Injection the code would be easily extendable to inject a repository to the Controller using a dependency injector like Ninject. &lt;br /&gt;&lt;br /&gt;One gotcha that you may have come across is that if the BlogEntry Url property is set to virtual then the value will not be set in the controller. &lt;br /&gt;&lt;br /&gt;I have uploaded the&amp;nbsp;&lt;a href="https://github.com/danielglyde/TDD-with-ASP.NET-MVC-3--Moq-and-Dependency-Injection"&gt;source code for TDD with ASP.NET MVC 3, Moq and Dependency Injection on githib&lt;/a&gt;, take a look and fork it.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9059110702732375767-7386514124753381405?l=danielglyde.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danielglyde.blogspot.com/feeds/7386514124753381405/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://danielglyde.blogspot.com/2011/07/tdd-with-aspnet-mvc-3-moq-and.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/7386514124753381405'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/7386514124753381405'/><link rel='alternate' type='text/html' href='http://danielglyde.blogspot.com/2011/07/tdd-with-aspnet-mvc-3-moq-and.html' title='TDD with ASP.NET MVC 3, Moq and Dependency Injection'/><author><name>Daniel Glyde</name><uri>http://www.blogger.com/profile/07266718495570206021</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total><georss:featurename>Southampton, UK</georss:featurename><georss:point>50.90496599999999 -1.4032339999999976</georss:point><georss:box>50.86263049999999 -1.4817019999999976 50.94730149999999 -1.3247659999999977</georss:box></entry><entry><id>tag:blogger.com,1999:blog-9059110702732375767.post-6786991320890362889</id><published>2011-03-05T13:39:00.000-08:00</published><updated>2011-03-05T14:15:05.887-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='service'/><category scheme='http://www.blogger.com/atom/ns#' term='Introduction to WCF'/><category scheme='http://www.blogger.com/atom/ns#' term='model'/><category scheme='http://www.blogger.com/atom/ns#' term='console'/><category scheme='http://www.blogger.com/atom/ns#' term='client'/><title type='text'>Introduction to WCF</title><content type='html'>This blog shows how to create a Visual Studio 2010 C# console application that hosts a Windows Communication Foundation (WCF) service exposing string manipulation methods.&lt;br /&gt;&lt;br /&gt;The purpose of WCF is to simplify the communication of distributed applications on Windows. Because WCF uses RESTful communication and implements SOAP it can therefore operate with multiple platforms.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Creating the service&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In Visual Studio 2010:&lt;br /&gt;File &gt; New &gt; Console Application &gt; Name: Service&lt;br /&gt;&lt;br /&gt;Open the project’s properties and change the namespace to: Glyde.ServiceModel.Examples&lt;br /&gt;Change the Program.cs namespace to use the Glyde.ServiceModel.Examples namespace.&lt;br /&gt;&lt;br /&gt;Add System.ServiceModel.dll to the project.&lt;br /&gt;Create a new public interface: IStringManipulator.cs, this will expose methods to add two strings together, replace part of a string and remove a substring.&lt;br /&gt;&lt;br /&gt;Add a reference to System.ServiceModel in the interface.&lt;br /&gt;&lt;br /&gt;Add a service contract to the interface:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;[ServiceContract(Namespace = &lt;/span&gt;&lt;a href="http://glyde.servicemodel.examples/"&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;http://Glyde.ServiceModel.Examples&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;)]&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And add [OperationContract] to the exposed methods:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;[&lt;span style="color:#66cccc;"&gt;OperationContract&lt;/span&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;string&lt;/span&gt; Add(&lt;span style="color:#330099;"&gt;string&lt;/span&gt; s1, &lt;span style="color:#330099;"&gt;string&lt;/span&gt; s2);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;[&lt;span style="color:#66cccc;"&gt;OperationContract&lt;/span&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;string&lt;/span&gt; Delete(&lt;span style="color:#330099;"&gt;string&lt;/span&gt; s1, &lt;span style="color:#330099;"&gt;string&lt;/span&gt; s2);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;[&lt;span style="color:#66cccc;"&gt;OperationContract&lt;/span&gt;]&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;string&lt;/span&gt; Replace(&lt;span style="color:#330099;"&gt;string&lt;/span&gt; s1, &lt;span style="color:#330099;"&gt;string&lt;/span&gt; s2, &lt;span style="color:#330099;"&gt;string&lt;/span&gt; s3);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Next we create a WCF service contract.&lt;br /&gt;&lt;br /&gt;Create a StringManipulatorService class to implement the interface methods.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;public&lt;/span&gt; &lt;span style="color:#330099;"&gt;string&lt;/span&gt; Add(&lt;span style="color:#330099;"&gt;string&lt;/span&gt; s1, &lt;span style="color:#330099;"&gt;string&lt;/span&gt; s2) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;return&lt;/span&gt; s1 + s2; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;public string&lt;/span&gt; Delete(&lt;span style="color:#330099;"&gt;string&lt;/span&gt; s1, &lt;span style="color:#330099;"&gt;string&lt;/span&gt; s2) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;return&lt;/span&gt; s1.Replace(s2, &lt;span style="color:#330099;"&gt;string&lt;/span&gt;.Empty); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;}&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;public string&lt;/span&gt; Replace(&lt;span style="color:#330099;"&gt;string&lt;/span&gt; s1, &lt;span style="color:#330099;"&gt;string&lt;/span&gt; s2, &lt;span style="color:#330099;"&gt;string&lt;/span&gt; s3) &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;{ &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;return&lt;/span&gt; s1.Replace(s2, s3); &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;In the Program.cs create a URI object to serve as the base address – this will be used by the client to call the service:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#66cccc;"&gt;Uri&lt;/span&gt; baseAddress = &lt;span style="color:#330099;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;Uri&lt;/span&gt;("&lt;/span&gt;&lt;a href="http://localhost:8000/GlydeServiceModelExamples/Service"&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;http://localhost:8000/GlydeServiceModelExamples/Service&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create a service host for the StringManipulatorService&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#66cccc;"&gt;ServiceHost&lt;/span&gt; selfHost = &lt;span style="color:#330099;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;ServiceHost&lt;/span&gt;(&lt;span style="color:#330099;"&gt;typeof&lt;/span&gt;(&lt;span style="color:#66cccc;"&gt;StringManipulatorService&lt;/span&gt;), baseAddress);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:Courier New;font-size:85%;"&gt;&lt;/span&gt;&lt;br /&gt;Add a service end point&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;selfHost.AddServiceEndpoint(&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;typeof&lt;/span&gt;(&lt;span style="color:#66cccc;"&gt;IStringManipulator&lt;/span&gt;), &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;WSHttpBinding&lt;/span&gt;(),&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;"StringManipulatorService");&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Enable the metadata exchange, for HTTP:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#66cccc;"&gt;ServiceMetadataBehavior&lt;/span&gt; smb = &lt;span style="color:#330099;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;ServiceMetadataBehavior&lt;/span&gt;(); smb.HttpGetEnabled = true; &lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;selfHost.Description.Behaviors.Add(smb);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Start the service&lt;br /&gt;&lt;span style="font-size:85%;"&gt;&lt;span style="font-family:courier new;"&gt;selfHost.Open();&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;Add a&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;Console&lt;/span&gt;.ReadLine();&lt;/span&gt;&lt;br /&gt;…to keep the service running.&lt;br /&gt;Call close to stop the service from running:&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;selfHost.Close();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Create a WCF client&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Create a console application called Client, implement this in a separate application so the service and client can be run from a separate debug solutions – this will help your understanding and allow you to debug both.&lt;br /&gt;&lt;br /&gt;Add System.ServiceModel.dll to the project and add the reference to Program.cs&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;How to use the service utility to create the client proxy&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Switch back to the service solution and start the console application by F5&lt;br /&gt;&lt;br /&gt;Start the Visual Studio command promptNavigate to the client projectRun the ServiceModel&lt;br /&gt;&lt;br /&gt;Metadata Utility Tool to create the client code and configuration file (generated proxy):&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config &lt;/span&gt;&lt;a href="http://localhost:8000/GlydeServiceModelExamples/Service"&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;http://localhost:8000/GlydeServiceModelExamples/Service&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This will generate the files in the client project folder:&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;generatedProxy&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;app.config&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;Add these to the client project by using ‘Add existing item’.&lt;br /&gt;&lt;br /&gt;Remember, if you modify or add new methods in the service, the client proxy will have to be recreated.&lt;br /&gt;&lt;br /&gt;The app.config specifies the location of the service, the binding and contract interface.&lt;br /&gt;Call the service via the proxy&lt;br /&gt;&lt;br /&gt;Create an endpoint address and a WCF instance client in the Program.cs.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#66cccc;"&gt;StringManipulatorClient&lt;/span&gt; client = &lt;span style="color:#330099;"&gt;new&lt;/span&gt; &lt;span style="color:#66cccc;"&gt;StringManipulatorClient&lt;/span&gt;();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;By adding the app.config and generatedProxy.cs the StringManipulatorClient is automatically available in the project.&lt;br /&gt;&lt;br /&gt;Don’t forget to add System.ServiceModel to the project and add a reference in the Program.cs file.&lt;br /&gt;&lt;br /&gt;Make a call to the client:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;string&lt;/span&gt; value1 = "Hello Hannah, ";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;string&lt;/span&gt; value2 = "how are you today";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;string&lt;/span&gt; result = client.Add(value1, value2);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;Console&lt;/span&gt;.WriteLine("Add({0},{1}) = {2}", value1, value2, result);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;value1 = result;&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;value2 = "Hannah";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;string&lt;/span&gt; value3 = "Emma";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;result = client.Replace(value1, value2, value3);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;Console&lt;/span&gt;.WriteLine("Replace({0},{1}) = {2}", value1, value2, result);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;value1 = result;value2 = ", how are you today";&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;result = client.Delete(value1, value2);&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;&lt;span style="color:#330099;"&gt;Console&lt;/span&gt;.WriteLine("Delete({0},{1}) = {2}", value1, value2, result);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Close the client after use:&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;font-size:85%;"&gt;client.Close();&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So that’s it, I hope I have wept your appetite to learn more about WCF – As ever I have uploaded my source to GitHub click here to get the source from &lt;a href="https://github.com/danielglyde/WCFStringManipulator"&gt;my introduction to WCF&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9059110702732375767-6786991320890362889?l=danielglyde.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danielglyde.blogspot.com/feeds/6786991320890362889/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://danielglyde.blogspot.com/2011/03/introduction-to-wcf.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/6786991320890362889'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/6786991320890362889'/><link rel='alternate' type='text/html' href='http://danielglyde.blogspot.com/2011/03/introduction-to-wcf.html' title='Introduction to WCF'/><author><name>Daniel Glyde</name><uri>http://www.blogger.com/profile/07266718495570206021</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9059110702732375767.post-7619199540843051434</id><published>2011-03-01T10:30:00.000-08:00</published><updated>2011-03-01T11:56:52.388-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Programming'/><category scheme='http://www.blogger.com/atom/ns#' term='Development'/><category scheme='http://www.blogger.com/atom/ns#' term='Sprint'/><category scheme='http://www.blogger.com/atom/ns#' term='Extreme'/><category scheme='http://www.blogger.com/atom/ns#' term='Software'/><category scheme='http://www.blogger.com/atom/ns#' term='Scrum'/><category scheme='http://www.blogger.com/atom/ns#' term='Agile'/><title type='text'>Agile Software Development</title><content type='html'>&lt;span style="font-size:180%;"&gt;What does it mean to be Agile?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There are a number of strategies and working practices available for Agile software development, I have included the process that works for me; this is based on my real life experiences working with stakeholders (more about these in a moment), developers and testers.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Scrum&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;What is Scrum?  During a project the customers can change their minds about what they want and need (also called churn) these challenges cannot be addressed in a planned manner.  Scrum uses a pragmatic approach, in most instances these problems cannot be fully understood therefore a focus on capitalising on the team's ability to delivery quickly and respond to emerging requirements.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Daily Scrum&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A stand up meeting called a Daily Scrum takes place at precisely the same time every day - 10 am is a good time as the team members have had the time to know what they are doing by this point.  If your team is distributed then use a video conferencing tool (e.g. Skype).&lt;br /&gt;&lt;br /&gt;There are three roles in a Daily Scrum:&lt;br /&gt;&lt;br /&gt;On the officials in the 2007 Tech-Texas game in Austin:&lt;br /&gt;&lt;br /&gt;"It's a little like breakfast; you eat ham and eggs. As coaches and players, we're like the ham. You see, the chicken's involved but the pig's committed. We're like the pig, they're like the chicken. They're involved, but everything we have rides on this."&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Pigs&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The developers and testers play the part of Pigs, they have no longer than one minute to describe what they did since the last Daily Scrum, what they are doing today and what blockers they think they may have to do today's tasks.&lt;br /&gt;&lt;br /&gt;If anyone has an questions or comments they should take place outside of the Daily Scrum.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Chickens&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The stakeholders (customers) play the role of chickens - they can listen but not speak.  If they have any questions they should go through the Scrum Master outside of the Daily Scrum meeting.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Scrum Master&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;The senior member of the software team usual a Team Leader will take the role of Scrum Master, they ensure the Daily Scrum starts on time and that everyone takes turns to speak.  The Scrum Master can also be a Pig.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Sprint&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Sprints are a part of the Scrum methodology.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Sprint planning meeting&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A sprint cycle lasts for two weeks.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Select the work to be done&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;User Stories&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;The Scrum Master meets with all the Stakeholders in a single meeting to gather the user stories.&lt;br /&gt;&lt;br /&gt;In order to process the user stories quickly cards should be used to write a short sentence that describes the functionality in the form:&lt;br /&gt;&lt;br /&gt;As a [role] I want [requirement]  so that [business need].&lt;br /&gt;&lt;br /&gt;The Stakeholder writes the card and passes it back to the Scrum Master, only one card is completed at a time after being discussed with the other Stakeholders.&lt;br /&gt;&lt;br /&gt;The number of User Stories gathered in the Sprint Planning Meeting will vary depending on the size of the team for a small team of four developers, ten User Stories would be a fair number.&lt;br /&gt;&lt;br /&gt;Each User Story will have a number of scenarios written on the back; these will form the tests.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Story Points and Planning Poker&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;After the User Stories are gathered the Software Developers and Testers go through each User Story and assign it a number of Story Points.&lt;br /&gt;&lt;br /&gt;The highest number is the most complex and time consuming, the lowest is the simplest and shortest: 0,1,2,3,5,8,13,20,100.  100 alerts you to the fact that you have an Epic Story which should be split in to multiple stories.&lt;br /&gt;&lt;br /&gt;A game of Planner Poker should be played, this can be done with Planning Poker cards or if your team are distributed - this can be done over an IM - The Scrum Master asks everyone to get their numbers ready and all hit Enter at the same time.&lt;br /&gt;&lt;br /&gt;The Scrum Master records the Story Points against each User Story, no more than 5 minutes should be spent on each User Story.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Prioritisation&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;The User Stories with Story Points should be reported to the Stakeholders in person, they then order the cards by relative priority.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Tasks and durations&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;The Scrum Master asks each of the Developers if they have any holiday booked for the next two weeks, this is subtracted from the number of hours in the Sprint.&lt;br /&gt;&lt;br /&gt;A Sprint is always two weeks long, due to outside forces, answering emails, meetings, urgent issues (real life) I allow for six hours per day on a Sprint.  So if a Developer is in then they are available for sixty hours for the two weeks.  I recommend using Pair Programming so this will be the hours shared between your developers (i.e. sixty hours for two Developers).&lt;br /&gt;&lt;br /&gt;Get the Developers and Testers together, take each User Story ordered by highest priority first, split in to Tasks i.e. Analysis, Design,  Database schema changes, Development, Testing, Deployment.  Speak directly to the individuals most likely to implement  the User Story (Developers and Testers should work on a single User Story rather than a single Task), ask them to say how long they think the Tasks will take.  The other Developers and Testers can verify this.&lt;br /&gt;&lt;br /&gt;Create a table in a spreadsheet with sixty at the top and subtract the hours for each User Story from the Developers available hours, eventually this will get to less than zero, all User Stories in positive numbers will be what the team can commit to.&lt;br /&gt;&lt;br /&gt;The Scrum Master meets with the Stakeholders and provides them with the list of User Stories that can be committed to in the two week Sprint.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Story board&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;A Story board is created for each Sprint, User Stories have a state during the Sprint:&lt;br /&gt;&lt;br /&gt;Backlog &gt; In progress &gt; Code ready for review &gt; Code reviewed &gt; QA Ready &gt; [QA Passed][QA Failed] &gt; Deployed&lt;br /&gt;&lt;br /&gt;There is another state called Waste, this is used for any duplicate or erroneous User Stories.&lt;br /&gt;&lt;br /&gt;The Developers are encouraged to move their User Story to the next Sprint, this should be viewable by the Stakeholders, web based story boards are available this is useful for distributed teams.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Sprint review meeting&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Once the two week Sprint is completed, the Developers and Testers meet with the Stakeholders to review the work that was completed and not completed.  A demonstration of the completed work is shown to the Stakeholders.  There should be a four hour limit to this meeting.&lt;br /&gt;&lt;br /&gt;Any User Stories not completed in the Sprint go in to the Sprint Backlog.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Velocity&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;The number of Story Points completed in the Sprint gets recorded against the User Story, this becomes the velocity of the team. &lt;br /&gt;&lt;br /&gt;After three Sprints the velocity will start to even out and give the Stakeholders an idea of the amount of work that can be done in a Sprint.&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Charts&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;There are two charts I have found useful, the first is a Daily Burndown Chart, this is where the number of hours the Developers spent on the Sprint each day is recorded against the number of available hours.&lt;br /&gt;&lt;br /&gt;The second is the Release Burndown Chart, this shows the estimated number of Story Points in the Sprint against the actual Story Points completed, this chart can be extended to also include the velocity.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:130%;"&gt;Sprint retrospective&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This meeting is attended by the Developers and Testers, all team members reflect on the past Sprint, make continuous process improvements , what went well and what can be improved, there should be a three hour limit to this meeting.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Extreme Programming (XP)&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;There are a number of XP elements, the one I find most useful is Pair programming.  Software developers sit at a single Development workstation they take it in turns to be at the keyboard - known as the Driver, as a Developer types they describe what they are doing to the Observer.  The Observer reviews the code as it is being typed, therefore code reviews do not need to be done after a task is completed and the quality of the code is far superior than if done on their own. &lt;br /&gt;&lt;br /&gt;One common issue is one of swapping, if this does not feel natural then switching every thirty minutes is a good compromise.  Other benefits include a lack of fatigue, knowledge sharing, a boost in morale, not skipping unit tests.  New Developers can pick up the workings of the team quickly and people are less likely to interrupt a pair of programmers.&lt;br /&gt;&lt;br /&gt;Other distractions can be email, one solution to this is to have a separate PC that individuals can use to read their email.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:180%;"&gt;Summary&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;By employing these Agile Software Development methods my team are able to work in a more efficient way, there is little or no context switching between tasks, the quality of work has improved and the implementation matches the requirements closely.  The Stakeholders feel engaged with the development process and see results more frequently than through the waterfall model.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9059110702732375767-7619199540843051434?l=danielglyde.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danielglyde.blogspot.com/feeds/7619199540843051434/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://danielglyde.blogspot.com/2011/03/agile-software-development.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/7619199540843051434'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/7619199540843051434'/><link rel='alternate' type='text/html' href='http://danielglyde.blogspot.com/2011/03/agile-software-development.html' title='Agile Software Development'/><author><name>Daniel Glyde</name><uri>http://www.blogger.com/profile/07266718495570206021</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9059110702732375767.post-1954223176876307091</id><published>2011-01-16T09:45:00.000-08:00</published><updated>2011-01-23T09:17:29.306-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='introduction'/><category scheme='http://www.blogger.com/atom/ns#' term='ruby on rails'/><category scheme='http://www.blogger.com/atom/ns#' term='ecommerce'/><category scheme='http://www.blogger.com/atom/ns#' term='shop'/><title type='text'>Introduction to Ruby on Rails</title><content type='html'>&lt;span class="Apple-style-span"&gt;&lt;b&gt;Introduction&lt;/b&gt;&lt;/span&gt; &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I am a .NET developer and have been programming ASP.NET in C# for a number of years, I have been hearing some pretty wonderful stuff about Ruby on Rails and wanted to see for myself. This post is about my discovery of this framework from the unknown to creating an ecommerce site from scratch.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Environment&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;IDE: NetBeans IDE 6.8&lt;/div&gt;&lt;div&gt;Ruby Platform: Build-in JRuby 1.4.0&lt;/div&gt;&lt;div&gt;Server: GlassFish v3 Domain&lt;/div&gt;&lt;div&gt;Database: MySQL&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Application&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;The application is simple and one that followers of this blog will recognise. It is a simple eCommerce shop with the data structured in to Products, Categories and Basket.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The purpose is to show how quickly an application in Rails can be created and takes you through the steps to set this up.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Prerequisite&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;You will have loaded in the Ruby and Rails plugin for NetBeans&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Create the Project&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;In the NetBean IDE select File &gt; New Project&lt;/div&gt;&lt;div&gt;Give your project a name e.g. ‘RailsShop’&lt;/div&gt;&lt;div&gt;See the environment section above for other settings.&lt;/div&gt;&lt;div&gt;Unselect ‘Add Rake Targets to Support App Server Development’&lt;/div&gt;&lt;div&gt;Database Configuration: Specify Database Information Directly&lt;/div&gt;&lt;div&gt;&lt;span style="WHITE-SPACE: pre" class="Apple-tab-span"&gt;&lt;/span&gt;Database adapter: mysql (jdbc)&lt;/div&gt;&lt;div&gt;&lt;span style="WHITE-SPACE: pre" class="Apple-tab-span"&gt;&lt;/span&gt;Database name: RailsShop_development (it will also create ‘_test’; ‘_production’&lt;/div&gt;&lt;div&gt;&lt;span style="WHITE-SPACE: pre" class="Apple-tab-span"&gt;&lt;/span&gt;User name: localhost&lt;/div&gt;&lt;div&gt;&lt;span style="WHITE-SPACE: pre" class="Apple-tab-span"&gt;&lt;/span&gt;Password xxxxxx&lt;/div&gt;&lt;div&gt;Install rails: 2.3.4&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Create and set up the database&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Right click on the project in the Project window &gt; Run/Debug Rake Task&gt; db:create &lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Add the tables&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Right click on the project &gt; Generate &lt;/div&gt;&lt;div&gt;Generator: model&lt;/div&gt;&lt;div&gt;Arguments: category name:string&lt;/div&gt;&lt;div&gt;Arguments: product category_id: integer name:string price:decimal url:string&lt;/div&gt;&lt;div&gt;Arguments: basket product_id: count:integer&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Note that the model is created in the Models folder – this does not define the fields in the model, these are specified in the Database migrations folder. The database will not be updated until the database migration has been called.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The convention is to use the foreign key to be the model_id.&lt;/div&gt;&lt;div&gt;Primary key ids are created automatically as are time stamps.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;Define the association between the models&lt;/span&gt;&lt;/div&gt;&lt;div&gt;A basket has products, edit the \models\basket.rb to:&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;class Basket &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt; ActiveRecord::Base&lt;br /&gt; belongs_to :product&lt;br /&gt;end&lt;/pre&gt;and so on with the rest of the models&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;class Category &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt; ActiveRecord::Base&lt;br /&gt; has_many :products&lt;br /&gt;end&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;class Product &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt; ActiveRecord::Base&lt;br /&gt; belongs_to :category&lt;br /&gt; has_many :baskets&lt;br /&gt;end&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Update the database&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Right click on the project &gt; Migrate Database &gt; To Current Version&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you get an error like this: &lt;/div&gt;&lt;div&gt;The driver encountered an error: com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown database 'railsshop_development'&lt;/div&gt;&lt;div&gt;rake aborted!&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The db:create failed silently in which case you will need to create the database manually – I did this in mySQL Workbench – this is a known issue and is discussed in the Knowledge base.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;You should be able to update the database to the current version.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If for any reason you need to reset the database to its empty state run:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Right click on the project &gt; Migrate Database &gt; To Version 0 - Clear&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Adding sample data&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Right click on lib\tasks&lt;/div&gt;&lt;div&gt;Create db_load_dev_data.rake (using Other\Empty file) – these isn’t support for the .rake extension by default.&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;namespace :db_load_dev_data do&lt;br /&gt; desc "This loads the development data."&lt;br /&gt; task :seed =&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; :environment do&lt;br /&gt;   require 'active_record/fixtures'&lt;br /&gt;   Dir.glob(RAILS_ROOT + '/db/fixtures/*.yml').each do file&lt;br /&gt;     base_name = File.basename(file, '.*')&lt;br /&gt;     #say "Loading #{base_name}..."&lt;br /&gt;     Fixtures.create_fixtures('db/fixtures', base_name)&lt;br /&gt;   end&lt;br /&gt; end&lt;br /&gt; desc "This drops the db, builds the db, and seeds the data."&lt;br /&gt; task :reseed =&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; [:environment, 'db:reset', 'db:seed']&lt;br /&gt;end&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;The code reads the yml files and loads the data in the database:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Create a new fixtures folder under the \db\ folder and create a file for each table i.e. products.yml.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Note: in Files view \db\ equates to Database Migrations in the Projects view.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Right click on the project &gt; Run/Debug Rake task… &gt; [refresh tasks] &gt; db_load_dev_data: seed&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It is important to specify the id of using test data – this allows for the foreign keys to be specified otherwise the id will automatically generated.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Here is an example with two products:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Concorde Bikes PDM Team Replica Road Bike:&lt;/div&gt;&lt;div&gt;category_id: 1&lt;/div&gt;&lt;div&gt;name: "Concorde Bikes PDM Team Replica Road Bike"&lt;/div&gt;&lt;div&gt;price: 699.99&lt;/div&gt;&lt;div&gt;url: "concorde-bike-pdm-ind.jpg"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Kestrel Talon Tri 105 2010:&lt;/div&gt;&lt;div&gt;category_id: 1&lt;/div&gt;&lt;div&gt;name: "Kestrel Talon Tri 105 2010"&lt;/div&gt;&lt;div&gt;price: 147.99&lt;/div&gt;&lt;div&gt;url: "kestral-talon-tri-ind.jpg"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To remove the sample data right click on the application &gt; Run/Debug Rake Task… &gt; db_load_dev_data:reseed&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Routes&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;To utilise shorthand like:&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= link_to category.name, category&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Ensure you have entries in the \Configuration\routes.rb:&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;map.resources :category&lt;br /&gt;map.resources :product&lt;br /&gt;map.resources :basket&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;More on this later.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Create the controllers&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;The scaffold generation will create controller methods for CRUD application, as we are displaying the site in read only we will not create with a scaffold.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Note, do not delete the application_controller.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;RailsShop &gt; Generate &gt; controller &gt; Category. Views: index, show&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This creates: &lt;/div&gt;&lt;div&gt;\Controllers\category_controller&lt;/div&gt;&lt;div&gt;\Views\category\index.html.erb&lt;/div&gt;&lt;div&gt;\Views\category\show.html.erb&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Edit the controller index – this is used to display all the categories&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;def index&lt;br /&gt; @categories = Category.all&lt;br /&gt;&lt;br /&gt; respond_to do format&lt;br /&gt;   format.html # index.html.erb&lt;br /&gt;   format.xml  { render :xml =&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; @categories }&lt;br /&gt; end&lt;br /&gt;end&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Show is used when a single category is selected:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;def show&lt;br /&gt; @category = Category.find(params[:id])&lt;br /&gt; respond_to do format&lt;br /&gt;   format.html # show.html.erb&lt;br /&gt;   format.xml  { render :xml =&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; @category }&lt;br /&gt; end&lt;br /&gt;end&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We also need to create a controller for product and basket.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Product views: show&lt;/div&gt;&lt;div&gt;Basket views: index, update, delete, add_to_basket&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Partial Views&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;As we want to show the categories, products and basket summary on the same page we need to use partial views.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In rails the partial views need to be located in the same folder as the containing page.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So for our example the Category show view is set out as:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;\Views\category\_basket_list.html.erb&lt;/div&gt;&lt;div&gt;\Views\category\_category_list.html.erb&lt;/div&gt;&lt;div&gt;\Views\category\_product_list.html.erb&lt;/div&gt;&lt;div&gt;\Views\category\show.html.erb&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;As you can see the convention in rails is to name partial views with an underscore prefix.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;These are included in the show.html.erb as:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= render :&lt;span class="kwrd"&gt;partial&lt;/span&gt;=&amp;gt;&lt;span class="str"&gt;"category_list"&lt;/span&gt;, :locals=&amp;gt;{:categories=&amp;gt;Category.find(:all)} &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= render :&lt;span class="kwrd"&gt;partial&lt;/span&gt;=&amp;gt;&lt;span class="str"&gt;"product_list"&lt;/span&gt;, :locals=&amp;gt;{:products=&amp;gt;@category.products} &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= render :&lt;span class="kwrd"&gt;partial&lt;/span&gt;=&amp;gt;&lt;span class="str"&gt;"basket_list"&lt;/span&gt;, :locals=&amp;gt;{:baskets=&amp;gt;Basket.find(:all)} &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The Category.find(all) does not call the controller but gets the list of categories and sets the partial’s categories variable with the result of the find call.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The product_list is interesting to us, and really sets out as a great example of Rails at work making our lives easier:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The show.html.erb has a variable @category, if we refer back to the model definition, Category ‘has_many :products’ and this along with the fact that the database definition defines that Product has a category_id we can access the list of products from the @category variable and pass it to the partial as a products variable. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Partials can also be accessed if they are not in the same folder – the same partials are included in the \Views\product\show.html.erb like this:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= render :&lt;span class="kwrd"&gt;partial&lt;/span&gt;=&amp;gt;&lt;span class="str"&gt;"category/basket_list"&lt;/span&gt;, :locals=&amp;gt;{:baskets=&amp;gt;Basket.find(:all)} &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Link to&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Rails provides a nice short hand to call controllers from views to call an action the first I touched on earlier:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In the \Views\category\show.html.erb we set the products local variable in the _product_list.html.erb this is then used in a ‘for loop’ like this:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; products.each &lt;span class="kwrd"&gt;do&lt;/span&gt; product &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= link_to product.name, product&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; end &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So the product is the instance of each iteration of the loop, so in the link_to what actually renders is: http://localhost:8080/RailsShop/product/2107859366, this will automatically call the product_controller show action passing the 2107859366 as a parameter id which is accessed like so:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;def show&lt;br /&gt; @product = Product.find(params[:id])&lt;br /&gt; respond_to do format&lt;br /&gt;   format.html # show.html.erb&lt;br /&gt;   format.xml  { render :xml =&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; @product}&lt;br /&gt; end&lt;br /&gt;end&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;In certain cases we need to explicitly identify the controller, action and parameter we are passing, this can be seen when adding a product to the basket:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;\Views\product\show.html.erb&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We have access to the local variable @product the id of which is used as a parameter to the basket which is called:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= link_to &lt;span class="str"&gt;'Add to basket'&lt;/span&gt;, :controller =&amp;gt; &lt;span class="str"&gt;"basket"&lt;/span&gt;, :action =&amp;gt; &lt;span class="str"&gt;"add_to_basket"&lt;/span&gt;, :id =&amp;gt; @product.id&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If we take a look at the ‘add_to_basket’ action:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;def add_to_basket&lt;br /&gt; #how many of this product is in the basket?&lt;br /&gt; @product_id = params[:id]&lt;br /&gt; @basket = Basket.find_by_product_id(@product_id)&lt;br /&gt;&lt;br /&gt; if !@basket.nil?&lt;br /&gt;   @count = @basket.count + 1&lt;br /&gt;   @basket.update_attribute(:count, @count)&lt;br /&gt; else&lt;br /&gt;   @basket = Basket.new&lt;br /&gt;   @basket.product_id = @product_id&lt;br /&gt;   @basket.count = 1&lt;br /&gt;   @basket.save&lt;br /&gt; end&lt;br /&gt;&lt;br /&gt; redirect_to :controller =&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; 'category', :action =&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; 'index'&lt;br /&gt;&lt;br /&gt;end&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;The code above takes the id parameter, uses it to find the basket, if the basket does not exist a new one is created with a single product otherwise the current number of products is obtained, incremented and stored in the data layer using the update_attribute method.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Another call on the basket allows us to remove the product, this is done by:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;def delete&lt;br /&gt; @basket = Basket.find(params[:id])&lt;br /&gt; @basket.destroy&lt;br /&gt; redirect_to :action =&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; 'index'&lt;br /&gt;end&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If we compare the last two controller actions we can see the redirect can be both explicit in describing the controller and implicit in that the index will call the Basket for the Basket delete action.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Submitting data in a form&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;We need to be able to modify the quantity of products in the basket, so how does it plumb together?&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;We call the basket index from an edit button on the _basket_list.html.erb:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= link_to &lt;span class="str"&gt;'Edit basket'&lt;/span&gt;, :controller =&amp;gt; &lt;span class="str"&gt;"basket"&lt;/span&gt;, :action =&amp;gt; &lt;span class="str"&gt;"index"&lt;/span&gt; &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This calls the basket_controller index action:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;def index&lt;br /&gt; @baskets = Basket.all&lt;br /&gt;&lt;br /&gt; respond_to do format&lt;br /&gt;   format.html # index.html.erb&lt;br /&gt;   format.xml  { render :xml =&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; @baskets }&lt;br /&gt; end&lt;br /&gt;end&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;This renders the \Views\basket\index.html.erb&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; @baskets.each &lt;span class="kwrd"&gt;do&lt;/span&gt; basket &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="asp"&gt;  &amp;lt;%&lt;/span&gt; form_for(basket) &lt;span class="kwrd"&gt;do&lt;/span&gt; f &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;    &amp;lt;&lt;/span&gt;&lt;span class="html"&gt;tr&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;    &amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt; &lt;span class="kwrd"&gt;="productname"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= basket.product.name &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;    &amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= basket.product.price &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;    &amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= f.text_field :count, :&lt;span class="kwrd"&gt;class&lt;/span&gt; =&amp;gt; &lt;span class="str"&gt;"qty"&lt;/span&gt; &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;    &amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= basket.product.price * basket.count &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;    &amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= f.hidden_field :id &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="kwrd"&gt;    &amp;lt;&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= f.submit &lt;span class="str"&gt;'Update'&lt;/span&gt;, :&lt;span class="kwrd"&gt;class&lt;/span&gt; =&amp;gt; &lt;span class="str"&gt;"updatebutton"&lt;/span&gt; &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;td&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;Note the hidden id field and form placement within the ‘for loop’, the submit button will call the basket_controller update method, more on the class settings in the style section later:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;def update&lt;br /&gt; @basket = Basket.find(params[:id])&lt;br /&gt; @basket.update_attributes(params[:basket])&lt;br /&gt; redirect_to :action =&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; 'index'&lt;br /&gt;end&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;And then re show the basket with the new line totals.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;Making it look good&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Layout&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;To maintain consistency across the site we need to create a page template. We do this by creating a new erb in \app\views\layouts\ - as ever the naming conversion is important here. We can either create one for the site named ‘application.html.erb’ or for each controller i.e. ‘category.html.erb’ the &lt;%= yield %&gt;is used on the page to donate the location to load the views.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Style&lt;/b&gt;&lt;/div&gt;&lt;div&gt;We set up styling in a CSS file in \public\stylesheets\default.css – this is referred to in the layout page as:&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;&lt;br /&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= stylesheet_link_tag &lt;span class="str"&gt;'default.css'&lt;/span&gt; &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If we want to style the delete link in the basket and add a confirmation question we do the following:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= link_to &lt;span class="str"&gt;'x'&lt;/span&gt;, {:controller =&amp;gt; &lt;span class="str"&gt;"basket"&lt;/span&gt;, :action =&amp;gt; &lt;span class="str"&gt;"delete"&lt;/span&gt;, :id =&amp;gt; basket.id}, :&lt;span class="kwrd"&gt;class&lt;/span&gt; =&amp;gt; &lt;span class="str"&gt;"delete"&lt;/span&gt;, :confirm =&amp;gt; &lt;span class="str"&gt;"Are you sure?"&lt;/span&gt;&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Note the curly parenthesis; without it the class and confirm will be added to the link URL.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Images&lt;/b&gt;&lt;/div&gt;&lt;div&gt;Load images on the page using the image_tag, this automatically looks up images in the \public\images folder in the web application.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= image_tag(@product.url) &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;b&gt;Run the application&lt;/b&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;I want the first page to load with the categories displayed; this is done by adding the following to \Configuration\routes.rb:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;pre class="csharpcode"&gt;map.root :controller =&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; "category"&lt;/pre&gt;&lt;/div&gt;&lt;div&gt;To run the application from NetBeans:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Right click on the Project &gt; Run&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;http://localhost:8080/RailsShop/category/&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span"&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Firstly the structure is all about creating a real world environment the segregation between Development, Test and Production make sense.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;When changes are made to the database it is easy to rollback changes and recreates the tables using the rake tasks.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The fields are not specified in the models only in the database migrations, this allows for encapsulation in code from the data layer.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I like the convention over configuration methodology; this has saved time creating rules for each instance.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So in summary then I like rails, it has a very structured approach to development and database schema changes as you can see things can be developed quickly without code bloat using the DRY methods.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I have uploaded the code to &lt;a href="https://github.com/danielglyde/RailsShop"&gt;GitHub&lt;/a&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9059110702732375767-1954223176876307091?l=danielglyde.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danielglyde.blogspot.com/feeds/1954223176876307091/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://danielglyde.blogspot.com/2011/01/introduction-to-ruby-on-rails.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/1954223176876307091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/1954223176876307091'/><link rel='alternate' type='text/html' href='http://danielglyde.blogspot.com/2011/01/introduction-to-ruby-on-rails.html' title='Introduction to Ruby on Rails'/><author><name>Daniel Glyde</name><uri>http://www.blogger.com/profile/07266718495570206021</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9059110702732375767.post-435305927243767661</id><published>2010-11-14T12:58:00.000-08:00</published><updated>2010-11-16T12:39:19.529-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='MVC'/><category scheme='http://www.blogger.com/atom/ns#' term='DB4O'/><category scheme='http://www.blogger.com/atom/ns#' term='ASP.NET'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><category scheme='http://www.blogger.com/atom/ns#' term='Object-Oriented Database'/><title type='text'>MVC 2.0 with DB4O</title><content type='html'>&lt;div&gt;&lt;strong&gt;Object-Oriented Databases&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;The aim of this blog is to firstly give an introduction of what an object-oriented database is, showing how to install DB4O, any shortcomings and finally to give an example in a C# .NET 4 MVC 2 shopping cart project.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is an Object-Oriented Database?&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;An object-oriented database is a database model (OODBMS), unlike relational database management systems which hold data in relational rows and columns the OODBMS holds information as objects in the same way as object-oriented programming.&lt;br /&gt;&lt;br /&gt;OODBMS is useful when used with object-oriented programming as no translation needs to take place between objects in code and objects in a database, the same objects can be referenced in each.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Why choose OODBMS over RDBMS?&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;OODBMS are faster than RDBMS and can be programmed without making changes to the full system.&lt;br /&gt;&lt;br /&gt;As navigation with OODBMS is done with pointers data access is done very efficiently.&lt;br /&gt;&lt;br /&gt;On the negative, OODBMS are optimised for specific search routes and will tend to be slower for general-purpose queries than relational however direct object references may be maintained to allow for both types of access.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;So what OODBMS should I choose?&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;This depends on the language you are programming in, I’m pro open source and the language I am writing for this example is in .Net I have selected the highly rated db4o: &lt;a href="http://www.db4o.com/about/productinformation/db4o/"&gt;http://www.db4o.com/about/productinformation/db4o/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;This o-o database has libraries for both Java and .NET, for a full list and comparison of OODBMS see this wiki link: &lt;a href="http://en.wikipedia.org/wiki/Comparison_of_object_database_management_systems"&gt;http://en.wikipedia.org/wiki/Comparison_of_object_database_management_systems&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Installation guide of db4o for .NET&lt;br /&gt;&lt;/strong&gt;&lt;br /&gt;Download the production release from the following location: &lt;a href="http://developer.db4o.com/Downloads.aspx"&gt;http://developer.db4o.com/Downloads.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;The following steps are for db4o-7.12-net35.msi&lt;br /&gt;&lt;br /&gt;Setup type: Typical&lt;br /&gt;Accept the default installation location&lt;br /&gt;Go though the defaults and click Finish to complete the installation&lt;br /&gt;&lt;br /&gt;If you have more than one version of Visual Studio installed you get the choice of plugin to install.&lt;br /&gt;&lt;br /&gt;‘To proceed with the installation of the Object Manager Enterprise plugin for VS please choose the appropriate shortcut from your db4objects Start menu’&lt;br /&gt;&lt;br /&gt;The plugin does not work with Microsoft Visual Web Developer – you will need the fully blown version of the Visual Studio.&lt;br /&gt;&lt;br /&gt;The tutorial automatically loads on completion of installation from here code examples can be obtained for processes such as opening databases to CRUD to LINQ and SODA queries.&lt;br /&gt;&lt;br /&gt;The only DLL you need to build against is C:\Program Files\db4o\db4o-7.12\bin\net-3.5\ Db4objects.Db4o.dll.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Issues &lt;/strong&gt;&lt;br /&gt;&lt;em&gt;Cache&lt;br /&gt;&lt;/em&gt;Db40 has its own caching, the default is ‘CachingStorage’, db4o uses a LRU/Q2 caching strategy. &lt;a href="http://developer.db4o.com/Documentation/Reference/db4o-8.0/net35/reference/index_Left.html#CSHID=configuration%2Ffile%2Fstorage%2Fisolated_storage.htmStartTopic=Content%2Fconfiguration%2Ffile%2Fstorage%2Fisolated_storage.htmSkinName=RedVersant"&gt;http://developer.db4o.com/Documentation/Reference/db4o-8.0/net35/reference/index_Left.html#CSHID=configuration%2Ffile%2Fstorage%2Fisolated_storage.htmStartTopic=Content%2Fconfiguration%2Ffile%2Fstorage%2Fisolated_storage.htmSkinName=RedVersant&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Load balancing&lt;br /&gt;&lt;/em&gt;&lt;a href="http://developer.db4o.com/Documentation/Reference/db4o-8.0/net35/reference/index_Left.html#CSHID=configuration%2Ffile%2Fstorage%2Fisolated_storage.htmStartTopic=Content%2Fconfiguration%2Ffile%2Fstorage%2Fisolated_storage.htmSkinName=RedVersant"&gt;http://developer.db4o.com/Documentation/Reference/db4o-8.0/net35/reference/index_Left.html#CSHID=configuration%2Ffile%2Fstorage%2Fisolated_storage.htmStartTopic=Content%2Fconfiguration%2Ffile%2Fstorage%2Fisolated_storage.htmSkinName=RedVersant&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Locking&lt;br /&gt;&lt;/em&gt;&lt;a href="http://www.gamlor.info/wordpress/?p=779"&gt;http://www.gamlor.info/wordpress/?p=779&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;Serialized objects &lt;/em&gt;&lt;br /&gt;As soon as objects are serialized the object-identity is lost, this is typical in web-scenarios or web-services, there are a number of different ids, one of which is “ID-Field On Classes With a ID-Generator”.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;The project&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;I developed this MVC 2.0 project using Visual Studio 2010 Ultimate.&lt;br /&gt;&lt;br /&gt;The source is available on &lt;a href="https://github.com/danielglyde/MvcDB4O"&gt;GitHub&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;It is assumed you have working knowledge of the MVC framework.&lt;br /&gt;&lt;br /&gt;The only DLLs I referenced from my application are:&lt;br /&gt;&lt;br /&gt;Db4objects.Db4o&lt;br /&gt;Db4objects.Db4o.Linq&lt;br /&gt;&lt;br /&gt;The second was included as I used Linq queries on the object database.&lt;br /&gt;&lt;br /&gt;To keep this example simple I have not addressed the issues of load balancing and isolated storage.&lt;br /&gt;&lt;br /&gt;I have created a new class in the Models folder: StoreDB4O&lt;br /&gt;&lt;br /&gt;In the class I define the yap file – this is the file DB4O uses to store the database.&lt;br /&gt;&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;&lt;br /&gt;&lt;div class="csharpcode"&gt;&lt;br /&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;readonly&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; StoreYapFileName = Path.Combine( &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:    &lt;/span&gt;Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:    &lt;/span&gt;&lt;span class="str"&gt;"store.yap"&lt;/span&gt;); &lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;...and obtain it using the following method:&lt;br /&gt;&lt;div class="csharpcode"&gt;&lt;br /&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IObjectContainer GetDB()&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;  &lt;span class="kwrd"&gt;return&lt;/span&gt;Db4oEmbedded.OpenFile(Db4oEmbedded.NewConfiguration(), StoreYapFileName);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;In order to get test data in to the project I have created a method called LoadTestData(), this is called from Application_Start() in Global.asax and removes the content of the database:&lt;br /&gt;&lt;br /&gt;&lt;div class="csharpcode"&gt;&lt;br /&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;File.Delete(StoreYapFileName);&lt;/pre&gt;&lt;br /&gt;&lt;/div&gt;&lt;br /&gt;And stores the sample data in Category and Product objects:&lt;br /&gt;&lt;br /&gt;&lt;div class="csharpcode"&gt;&lt;br /&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;IObjectContainer db = GetDB();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;&lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    Category category = &lt;span class="kwrd"&gt;new&lt;/span&gt; Category { CategoryId = 1, Name = &lt;span class="str"&gt;"Bikes"&lt;/span&gt; };&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    StoreCategory(db, category);&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;…&lt;br /&gt;&lt;br /&gt;&lt;div class="csharpcode"&gt;&lt;br /&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; StoreCategory(IObjectContainer db, Category category)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    db.Store(category);&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;There is nothing special about the objects that are stored in the database.&lt;br /&gt;&lt;div class="csharpcode"&gt;&lt;br /&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MvcDB4O.Models&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;{&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Category&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; CategoryId { get; set; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;In addition to storing data in object I have implemented methods that return data using Linq queries as example of which returns a list of products by category name:&lt;br /&gt;&lt;div class="csharpcode"&gt;&lt;br /&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable&amp;lt;Product&amp;gt; GetProductsByCategoryName(&lt;span class="kwrd"&gt;string&lt;/span&gt; name)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;        {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;            IObjectContainer db = GetDB();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt; &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;            &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;            {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Product&amp;gt;(from Product p &lt;span class="kwrd"&gt;in&lt;/span&gt; db&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;                                          &lt;span class="kwrd"&gt;where&lt;/span&gt; p.Category.Name == name&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;                                          orderby p.Name&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;                                          select p).Distinct(&lt;span class="kwrd"&gt;new&lt;/span&gt; ProductByNameEquality());&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt; &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;            }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;            &lt;span class="kwrd"&gt;finally&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;            {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;                db.Close();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;        }&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;One important thing to mention is to always return a copy of the object from the database otherwise the connection of the database will be required to be open when accessing data from the objects.&lt;br /&gt;&lt;br /&gt;Another gotcha is that when updating existing data, the same object will be required from the database within the same session i.e. In this example, the basket has the count decremented and the basket is then placed back in the object database, if this was done in two separate sessions with the database a second basket will be added to the database and the existing one will also exist.&lt;br /&gt;&lt;br /&gt;&lt;div class="csharpcode"&gt;&lt;br /&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable&amp;lt;Product&amp;gt; GetProductsByCategoryName(&lt;span class="kwrd"&gt;string&lt;/span&gt; name)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;        {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;            IObjectContainer db = GetDB();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt; &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;            &lt;span class="kwrd"&gt;try&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;            {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;Product&amp;gt;(from Product p &lt;span class="kwrd"&gt;in&lt;/span&gt; db&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;                                          &lt;span class="kwrd"&gt;where&lt;/span&gt; p.Category.Name == name&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;                                          orderby p.Name&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;                                          select p).Distinct(&lt;span class="kwrd"&gt;new&lt;/span&gt; ProductByNameEquality());&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt; &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;            }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;            &lt;span class="kwrd"&gt;finally&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;            {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;                db.Close();&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;        }&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The MVC structure here is nothing new, the Home\Index.aspx shows the categories and a link to the StoreController Browse method:&lt;br /&gt;&lt;br /&gt;&lt;div class="csharpcode"&gt;&lt;br /&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;        &amp;lt;% &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (MvcDB4O.Models.Category category &lt;span class="kwrd"&gt;in&lt;/span&gt; Model.Categories)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;           { %&amp;gt;         &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        &amp;lt;li&amp;gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;            &amp;lt;%: Html.ActionLink(category.Name, &lt;span class="str"&gt;"Browse"&lt;/span&gt;, &lt;span class="str"&gt;"Store"&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; { category = category.Name }, &lt;span class="kwrd"&gt;null&lt;/span&gt;)%&amp;gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;        &amp;lt;/li&amp;gt;     &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &amp;lt;% } %&amp;gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt; &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Browse(&lt;span class="kwrd"&gt;string&lt;/span&gt; category)&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        {&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            &lt;span class="rem"&gt;// Retrieve Category and Products from database     &lt;/span&gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;            var storeBrowseViewModel = &lt;span class="kwrd"&gt;new&lt;/span&gt; StoreBrowseViewModel()&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;                { &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  13:  &lt;/span&gt;                    Category = StoreDB4O.GetCategory(category),&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  14:  &lt;/span&gt;                    Products = StoreDB4O.GetProductsByCategoryName(category)&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  15:  &lt;/span&gt;                };&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  16:  &lt;/span&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; View(storeBrowseViewModel);&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  17:  &lt;/span&gt;        }&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;The View Model is populated and used in the Store\Browse.aspx page.&lt;br /&gt;&lt;div class="csharpcode"&gt;&lt;br /&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; StoreBrowseViewModel&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    {&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; Category Category { get; set; }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; IEnumerable&amp;lt;Product&amp;gt; Products { get; set; }&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;    }&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt; &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        &amp;lt;% &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (MvcDB4O.Models.Product product &lt;span class="kwrd"&gt;in&lt;/span&gt; Model.Products)&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;           { %&amp;gt;         &lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        &amp;lt;li&amp;gt;&lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;            &amp;lt;%: Html.ActionLink(product.Name, &lt;span class="str"&gt;"Details"&lt;/span&gt;, &lt;span class="str"&gt;"Store"&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; { id = product.ProductId }, &lt;span class="kwrd"&gt;null&lt;/span&gt;)%&amp;gt;&lt;/pre&gt;&lt;pre class="alt"&gt;&lt;span class="lnum"&gt;  11:  &lt;/span&gt;        &amp;lt;/li&amp;gt;     &lt;/pre&gt;&lt;pre&gt;&lt;span class="lnum"&gt;  12:  &lt;/span&gt;        &amp;lt;% } %&amp;gt;&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;I hope this has served to show how to connect to an object database in particular DB4O using MVC.&lt;br /&gt;&lt;br /&gt;Please ask any questions you may have and I welcome your comments.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9059110702732375767-435305927243767661?l=danielglyde.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danielglyde.blogspot.com/feeds/435305927243767661/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://danielglyde.blogspot.com/2010/11/mvc-20-with-db4o.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/435305927243767661'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/435305927243767661'/><link rel='alternate' type='text/html' href='http://danielglyde.blogspot.com/2010/11/mvc-20-with-db4o.html' title='MVC 2.0 with DB4O'/><author><name>Daniel Glyde</name><uri>http://www.blogger.com/profile/07266718495570206021</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9059110702732375767.post-5247017184797648860</id><published>2010-10-19T13:49:00.000-07:00</published><updated>2010-10-19T14:18:38.094-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='GitHub Git install upload configure'/><title type='text'>How to download, install, configure and upload content to GitHub</title><content type='html'>&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;This post describes how to download, install, configure and upload content to GitHub.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;What is GitHub?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Git is a distributed version control system. GitHub provides a way for sharing content in Git with other people&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;How do I get GitHub?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Sign up for a free account here: &lt;a href="https://github.com/signup/free"&gt;https://github.com/signup/free&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Once you have your account, create a new repository: &lt;a href="http://github.com/repositories/new"&gt;http://github.com/repositories/new&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;After setting up your account you will need to Download and Install Git on your PC.&lt;br /&gt;&lt;br /&gt;msysgit is the Windows version, available here: &lt;a href="http://code.google.com/p/msysgit/downloads/list?can=3"&gt;http://code.google.com/p/msysgit/downloads/list?can=3&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;At the time of writing the latest version is: 1.7.3.1&lt;br /&gt;&lt;br /&gt;Accept the defaults when installing&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;So how do I set it up?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Once Git is installed, run the application Git &gt; Git GUI &gt; Create New Repository &gt; [enter a name] &gt; Create&lt;br /&gt;&lt;br /&gt;This will create a new folder in your Documents and Settings folder with the name of your repository&lt;br /&gt;&lt;br /&gt;Copy or create your new project in the folder.&lt;br /&gt;&lt;br /&gt;In Explorer, right click on the new top level folder &gt; Git add all files now&lt;br /&gt;&lt;br /&gt;Run the command prompt: Git &gt; Git Bash&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;git config --global user.name "Your Name"&lt;br /&gt;git config --global user.email "Your email address"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Next set up a SSH public key on your PC that links you to the repository:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://help.github.com/msysgit-key-setup/"&gt;http://help.github.com/msysgit-key-setup/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Change to the location of the new repository:&lt;br /&gt;cd MvcDB4O&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;git init&lt;/span&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;ssh-keygen –t rsc –C "Your email address"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;You will be prompted for a location for the key, hit enter for the default&lt;br /&gt;Enter a passphrase&lt;br /&gt;&lt;br /&gt;You will be told the location of the ssh public key&lt;br /&gt;&lt;br /&gt;Create an SSH public key from the website: &lt;a href="https://github.com/account"&gt;https://github.com/account&lt;/a&gt; &gt; add another public key&lt;br /&gt;&lt;br /&gt;Give it a title and the key you created in Git Bash&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;So how do I push my files to GitHub?&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;In Git Bash&lt;br /&gt;Change to the directory of the repository&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;git remote add origin git@github.com:your-git-username/repository-name.git &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-family:courier new;"&gt;git push origin master (you will be asked for your passphrase)&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;(ensure the .ssh folder exists in the repository you are uploading)&lt;br /&gt;&lt;br /&gt;Switch to GitHub to view the uploaded files&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Hopefully you have found this information useful - good luck with your Git friends.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9059110702732375767-5247017184797648860?l=danielglyde.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danielglyde.blogspot.com/feeds/5247017184797648860/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://danielglyde.blogspot.com/2010/10/how-to-download-install-configure-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/5247017184797648860'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/5247017184797648860'/><link rel='alternate' type='text/html' href='http://danielglyde.blogspot.com/2010/10/how-to-download-install-configure-and.html' title='How to download, install, configure and upload content to GitHub'/><author><name>Daniel Glyde</name><uri>http://www.blogger.com/profile/07266718495570206021</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-9059110702732375767.post-955513082774202122</id><published>2010-07-30T13:50:00.000-07:00</published><updated>2010-07-31T01:56:08.070-07:00</updated><title type='text'>Welcome</title><content type='html'>Hello, &lt;br /&gt;&lt;br /&gt;I hold the post of Project Technical Lead at Wiggle Limited. &lt;br /&gt;&lt;br /&gt;I will be posting my thoughts, ideas and comments on technical and managerial solutions I come across on a day to day basis.&lt;br /&gt;&lt;br /&gt;Please feel free to make any comments to my posts and I will get back to you as soon as possible.&lt;br /&gt;&lt;br /&gt;Check out my &lt;a href="http://uk.linkedin.com/in/danielglyde"&gt;linkedin&lt;/a&gt; and &lt;a href="http://twitter.com/DanielGlyde"&gt;twitter&lt;/a&gt; accounts or contact me via &lt;a href="mailto:dan@glyde.eu"&gt;email&lt;/a&gt;.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/9059110702732375767-955513082774202122?l=danielglyde.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://danielglyde.blogspot.com/feeds/955513082774202122/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://danielglyde.blogspot.com/2010/07/welcome.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/955513082774202122'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/9059110702732375767/posts/default/955513082774202122'/><link rel='alternate' type='text/html' href='http://danielglyde.blogspot.com/2010/07/welcome.html' title='Welcome'/><author><name>Daniel Glyde</name><uri>http://www.blogger.com/profile/07266718495570206021</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
