<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Davepoint</title>
	<atom:link href="http://blog.ceredir.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ceredir.com</link>
	<description></description>
	<lastBuildDate>Tue, 21 Sep 2010 14:19:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Concurrent Sessions in MVC2</title>
		<link>http://blog.ceredir.com/index.php/2010/09/21/concurrent-sessions-in-mvc2/</link>
		<comments>http://blog.ceredir.com/index.php/2010/09/21/concurrent-sessions-in-mvc2/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 14:19:41 +0000</pubDate>
		<dc:creator>David Bending</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://blog.ceredir.com/?p=138</guid>
		<description><![CDATA[There’s lots of rules that control how many concurrent connections you can have in an ASP.net MVC2 application.
Firstly the browser itself limits the number of connections it will make to the same domain.  The limit used to be 2 (as per the HTTP specification).  Some browsers increase this limit, but older browsers like IE6 will [...]]]></description>
			<content:encoded><![CDATA[<p>There’s lots of rules that control how many concurrent connections you can have in an ASP.net MVC2 application.</p>
<p>Firstly the browser itself limits the number of connections it will make to the same domain.  The limit used to be 2 (as per the HTTP specification).  Some browsers increase this limit, but older browsers like IE6 will still stick to it.</p>
<p>Secondly you have the number of threads available in IIS to content with.  <a href="http://blogs.msdn.com/b/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx">Thomas Masquardt’s Blog</a> gives a very detailed explanation of this.</p>
<p>Finally MVC itself has some limitations. Basically you can only have a single request using a read-write session at any given time.  This means that if you have a controller serving up images, and you don’t take any steps to avoid the problem, you will only ever serve up one image at a time.  <a href="http://weblogs.asp.net/imranbaloch/archive/2010/07/10/concurrent-requests-in-asp-net-mvc.aspx">Imran Baloch’s Blog</a> gives a lot more information about this and shows how to create session-less actions to avoid the issue.  For me the solution is quite simple.  By placing the following code in Global.asax.cs:</p>
<pre class="brush: csharp; ruler: true;">protected void Application_BeginRequest()
{
    if((Request.Url.AbsoluteUri.ToUpperInvariant().Contains("REFRESHPRICES")
        &amp;&amp; Request.Cookies["ASP.NET_SessionId"] != null))
    {
        Context.SetSessionStateBehavior(SessionStateBehavior.ReadOnly);
    }
}</pre>
<p>I can make the session for my action read-only, and sidestep the limit.</p>
<h3>Warning</h3>
<p>Just marking the session sate as read-only doesn’t prevent you from trying to modify the session.  It’s up to you to maintain thread-safety if you decide to lie to the framework.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.ceredir.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.ceredir.com/index.php/2010/09/21/concurrent-sessions-in-mvc2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MVC2 Cross Field Validation</title>
		<link>http://blog.ceredir.com/index.php/2010/08/10/mvc2-cross-field-validation/</link>
		<comments>http://blog.ceredir.com/index.php/2010/08/10/mvc2-cross-field-validation/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 08:07:43 +0000</pubDate>
		<dc:creator>David Bending</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://blog.ceredir.com/index.php/2010/08/10/mvc2-cross-field-validation/</guid>
		<description><![CDATA[Introduction to Validation
Nearly all web applications require some form of validation. Validation performs two main purposes: helping the user to enter correct values on a web page, and protecting the application from invalid or malicious input.
Validation can take place client-side within the browser, or server-side when the page is posted to the server. ASP.NET MVC2 [...]]]></description>
			<content:encoded><![CDATA[<h3>Introduction to Validation</h3>
<p>Nearly all web applications require some form of validation. Validation performs two main purposes: helping the user to enter correct values on a web page, and protecting the application from invalid or malicious input.</p>
<p>Validation can take place client-side within the browser, or server-side when the page is posted to the server. ASP.NET MVC2 comes with a flexible framework for applying validation using data annotations on the view model. Scott Gu has written an excellent tutorial on basic MVC validation here: <a href="http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx">http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx</a>.</p>
<h3>Limitations of Built-in MVC Validation</h3>
<p>The built-in validation works well for standard scenarios, but there are a few common scenarios it can’t cope with. One of the main issues is that validation can only be done on a model property in isolation. Often we will want to validate a property based on the current value of some other property: for instance we may want our <em>confirm password</em> field value to be the same as the <em>password</em> box.</p>
<p>In this article we will extend the MVC validation framework to provide support for cross-field validation. We’ll do this in part by creating custom validation attributes as described in Phil Haack’s article (<a href="http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx">http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx</a>) but we’ll also need to extend the validator framework to allow us to validate across fields.</p>
<h3>Extending the Framework to Support Cross-Field Validation</h3>
<p>To create a custom validation attribute we usually derive from ValidationAttribute and override the IsValid method, however IsValid only gets passed the value of the property to validate and we are going to need to see the value of other fields in the model. To accommodate this we’ll create an interface ICrossFieldValidationAttribute that has an IsValid method with access to the entire view model (note these code snippets only show significant lines – download the example solution to get the whole files):</p>
<pre class="brush: csharp; ruler: true;">public interface ICrossFieldValidationAttribute
{
    bool IsValid(ControllerContext controllerContext, object model, ModelMetadata modelMetadata);
}</pre>
<p>Next we build a base class for cross-field validators. This base class uses the extended IsValid defined above, rather than the narrower method used in the framework’s DataAnnotationsModelValidator class.</p>
<pre class="brush: csharp; ruler: true;">public abstract class CrossFieldValidator&lt;TAttribute&gt; : DataAnnotationsModelValidator&lt;TAttribute&gt;
        where TAttribute : ValidationAttribute, ICrossFieldValidationAttribute
{
    public override IEnumerable&lt;ModelValidationResult&gt; Validate(object container)
    {
        var attribute = Attribute as ICrossFieldValidationAttribute;

        if (!attribute.IsValid(ControllerContext, container, Metadata))
        {
            yield return new ModelValidationResult {Message = ErrorMessage};
        }
    }
}</pre>
<h3>Building the Validation</h3>
<p>Now that we have a cross-field validation framework in place, we can build our new attribute.</p>
<pre class="brush: csharp; ruler: true;">[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)]
public class EqualToPropertyAttribute : ValidationAttribute, ICrossFieldValidationAttribute
{
    public string OtherProperty { get; set; }

    public bool IsValid(ControllerContext controllerContext, object model, ModelMetadata modelMetadata)
    {
        var propertyInfo = model.GetType().GetProperty(OtherProperty);
        var otherValue = propertyInfo.GetGetMethod().Invoke(model, null);

        if (modelMetadata.Model == null) modelMetadata.Model = string.Empty;
        if (otherValue == null) otherValue = string.Empty;

        return modelMetadata.Model.ToString() == otherValue.ToString();
    }
}</pre>
<p>And apply it to the view model:</p>
<pre class="brush: csharp; ruler: true;">public class Account
{
    public string Password { get; set; }

    [EqualToProperty(OtherProperty = "Password")]
    public string ConfirmPassword { get; set; }
}</pre>
<p>We also need to create a validator class to emit the correct client-side rules, and to invoke the IsValid method.</p>
<pre class="brush: csharp; ruler: true;">public class EqualToPropertyValidator : CrossFieldValidator&lt;EqualToPropertyAttribute&gt;
{
    public override IEnumerable&lt;ModelClientValidationRule&gt; GetClientValidationRules()
    {
        var rule = new ModelClientValidationRule
        {
            ValidationType = "equaltoproperty",
            ErrorMessage = Attribute.FormatErrorMessage(Metadata.PropertyName),
        };

        rule.ValidationParameters.Add("otherProperty", Attribute.OtherProperty);

        return new[] { rule };
    }
}</pre>
<p>Finally we need to create a JavaScript function to evaluate the rule client-side:</p>
<pre class="brush: js; ruler: true;">jQuery.validator.addMethod("equaltoproperty", function (value, element, params) {
    if (this.optional(element)) {
        return true;
    }

    var otherPropertyControl = $("#" + params.otherProperty);
    if (otherPropertyControl == null) {
        return false;
    }

    var otherPropertyValue = otherPropertyControl[0].value;
    return otherPropertyValue == value;
});

function testConditionEqual(element, params) {
    var otherPropertyControl = $("#" + params.otherProperty);
    if (otherPropertyControl == null) {
        return false;
    }

    var otherPropertyValue;
    if (otherPropertyControl[0].type == "checkbox") {
        otherPropertyValue = (otherPropertyControl[0].checked) ? "True" : "False";
    } else {
        otherPropertyValue = otherPropertyControl[0].value;
    }

    return otherPropertyValue == params.comparand;
}</pre>
<p>And the final step is to register our new attribute with MVC. We do this in Global.asax Application_Start method like this:</p>
<pre class="brush: csharp; ruler: true;">DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(EqualToPropertyAttribute),
                                                      typeof(EqualToPropertyValidator));</pre>
<pre class="brush: csharp; ruler: true;"> </pre>
<h2 class="brush: csharp; ruler: true;">Example</h2>
<p class="brush: csharp; ruler: true;">The example code is here <a href="http://blog.ceredir.com/wp-content/uploads/2010/08/CrossFieldValidation1.zip">CrossFieldValidation</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.ceredir.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.ceredir.com/index.php/2010/08/10/mvc2-cross-field-validation/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Exception in WCF Service (HRESULT: 0&#215;80131045)</title>
		<link>http://blog.ceredir.com/index.php/2010/08/02/exception-in-wcf-service-hresult-0x80131045/</link>
		<comments>http://blog.ceredir.com/index.php/2010/08/02/exception-in-wcf-service-hresult-0x80131045/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 13:30:05 +0000</pubDate>
		<dc:creator>David Bending</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://blog.ceredir.com/?p=122</guid>
		<description><![CDATA[I couldn&#8217;t understand why I could call my WCF service from WcfTestClient, but when I hit it with integration tests built using the unit test framework I got this message:
Test method Lookup.IntegrationTests.HttpLabelTests.GetLabel threw exception:
System.ServiceModel.ProtocolException: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If [...]]]></description>
			<content:encoded><![CDATA[<p>I couldn&#8217;t understand why I could call my WCF service from WcfTestClient, but when I hit it with integration tests built using the unit test framework I got this message:</p>
<pre>Test method Lookup.IntegrationTests.HttpLabelTests.GetLabel threw exception:
System.ServiceModel.ProtocolException: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.Common' or one of its dependencies. Strong name signature could not be verified. &amp;nbsp;The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)&lt;/title&gt;
        &lt;style&gt;
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;}
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Lucida Console";font-size: .9em}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandabl'. ---&gt; System.Net.WebException: The remote server returned an error: (500) Internal Server Error.</pre>
<p>The answer is CodeCoverage.  By default Visual Studio 2010 tries to measure coverage for every assembly in the service bin.  To avoid the problem turn this off, and add coverage for each assembly you are interested in individually.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.ceredir.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.ceredir.com/index.php/2010/08/02/exception-in-wcf-service-hresult-0x80131045/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Removing types from Unity in unit tests</title>
		<link>http://blog.ceredir.com/index.php/2010/04/27/removing-types-from-unity-in-unit-tests/</link>
		<comments>http://blog.ceredir.com/index.php/2010/04/27/removing-types-from-unity-in-unit-tests/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 07:14:34 +0000</pubDate>
		<dc:creator>David Bending</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[Unity]]></category>

		<guid isPermaLink="false">http://blog.ceredir.com/?p=105</guid>
		<description><![CDATA[Calling teardown on the UnityContainer doesn’t remove a registration from Unity.  Here’s how to unit test code that resolves a type configured by RegisterInstance rather than configuration.  IoC is a thin wrapper around the UnityContainer.

        private ControllerContext _controllerContext;
        private ModelMetadata _modelMetadata;
        private Proposer _proposer;
        private ILookup _lookup;
        private LifetimeManager _lifetimeManager;

        [TestInitialize]
        public void SetupTest()
        {
            [...]]]></description>
			<content:encoded><![CDATA[<p>Calling teardown on the UnityContainer doesn’t remove a registration from Unity.  Here’s how to unit test code that resolves a type configured by RegisterInstance rather than configuration.  IoC is a thin wrapper around the UnityContainer.</p>
<pre class="brush: c-sharp">
        private ControllerContext _controllerContext;
        private ModelMetadata _modelMetadata;
        private Proposer _proposer;
        private ILookup _lookup;
        private LifetimeManager _lifetimeManager;

        [TestInitialize]
        public void SetupTest()
        {
            _controllerContext = new ControllerContext();
            _modelMetadata =
                ModelMetadataProviders.Current.GetMetadataForType(() =&gt; _proposer.AcceptedTerms, typeof (bool));
            _proposer = new Proposer();
            _lifetimeManager = new ContainerControlledLifetimeManager();
            _lookup = MockRepository.GenerateStrictMock&lt;ILookup&gt;();
            IoC.UnityContainer.RegisterInstance(typeof(ILookup), _lookup, _lifetimeManager);
        }
</pre>
<pre class="brush: c-sharp">        [TestCleanup]
        public void VerifyExpectations()
        {
            _lifetimeManager.RemoveValue();
            _lookup.VerifyAllExpectations();
         }       </pre>
<pre class="brush: c-sharp">        [TestMethod]<br />
        public void ErrorMessageIsCorrectlyGenerated()<br />
        {<br />
            var target = new NotDefaultIfAttribute("test/notDefaultIf")<br />
            {<br />
                OtherProperty = "Surname"<br />
            };<br />
            _lookup.Expect(l =&gt; l.GetLabel("test/notDefaultIf")).Return("Blah blah {0} blah");<br />
            Assert.AreEqual("Blah blah AcceptedTerms blah", target.FormatErrorMessage("AcceptedTerms"));<br />
        }</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.ceredir.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.ceredir.com/index.php/2010/04/27/removing-types-from-unity-in-unit-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Brown M&amp;M&#8217;s and Coding Standards</title>
		<link>http://blog.ceredir.com/index.php/2010/03/02/brown-mms-and-coding-standards/</link>
		<comments>http://blog.ceredir.com/index.php/2010/03/02/brown-mms-and-coding-standards/#comments</comments>
		<pubDate>Tue, 02 Mar 2010 08:34:33 +0000</pubDate>
		<dc:creator>David Bending</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://blog.ceredir.com/?p=100</guid>
		<description><![CDATA[I&#39;ve been doing more work on running coding dojos and as part of that I&#39;ve been thinking about compliance to published coding standards and what the purpose of those standards are.&#160; Some of the rules have a very clear purpose: doing it in a certain way is just plain better.&#160; Other rules have a more [...]]]></description>
			<content:encoded><![CDATA[<p>I&#39;ve been doing more work on running coding dojos and as part of that I&#39;ve been thinking about compliance to published coding standards and what the purpose of those standards are.&nbsp; Some of the rules have a very clear purpose: doing it in a certain way is just plain better.&nbsp; Other rules have a more subtle intentI think: essentially they are brown M&amp;M&#39;s.&nbsp;</p>
<p>Let me explain: Van Halen arranged notoriety for having a rider than insisted on having all brown M&amp;M&#39;s removed on pain of forfeiture of the show.&nbsp; Most people put this down to rock star arrogance, but actually the reason for this clause is a lot more interesting.&nbsp; This is from David Lee Roth&#39;s autobiography:</p>
<blockquote>
<p>Van Halen was the first band to take huge productions into tertiary, third-level markets. We&#39;d pull up with nine eighteen-wheeler trucks, full of gear, where the standard was three trucks, max. And there were many, many technical errors &mdash; whether it was the girders couldn&#39;t support the weight, or the flooring would sink in, or the doors weren&#39;t big enough to move the gear through. The contract rider read like a version of the Chinese Yellow Pages because there was so much equipment, and so many human beings to make it function. So just as a little test, in the technical aspect of the rider, it would say <nobr>&quot;Article 148:</nobr> There will be fifteen amperage voltage sockets at twenty-foot spaces, evenly, providing nineteen <nobr>amperes . . .&quot;</nobr> This kind of thing. And article <nobr>number 126,</nobr> in the middle of nowhere, was: &quot;There will be no brown M&amp;M&#39;s in the backstage area, upon pain of forfeiture of the show, with full compensation.&quot; </p>
<p>		So, when I would walk backstage, if I saw a brown M&amp;M in that <nobr>bowl . . .</nobr> well, line-check the entire production. Guaranteed you&#39;re going to arrive at a technical error. They didn&#39;t read the contract. Guaranteed you&#39;d run into a problem. Sometimes it would threaten to just destroy the whole show. Something like, literally, life-threatening.</p>
</blockquote>
<p>So maybe that&#39;s what some of the style rules in coding standards are.&nbsp; Brown M&amp;M&#39;s.&nbsp; A way to see if whoever wrote the code was paying attention and thinking about what they are doing.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.ceredir.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.ceredir.com/index.php/2010/03/02/brown-mms-and-coding-standards/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Agile Restaurant</title>
		<link>http://blog.ceredir.com/index.php/2010/02/18/the-agile-restaurant/</link>
		<comments>http://blog.ceredir.com/index.php/2010/02/18/the-agile-restaurant/#comments</comments>
		<pubDate>Thu, 18 Feb 2010 21:09:40 +0000</pubDate>
		<dc:creator>David Bending</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[training]]></category>

		<guid isPermaLink="false">http://blog.ceredir.com/index.php/2010/02/18/the-agile-restaurant/</guid>
		<description><![CDATA[I&#39;ve been doing Agile training again, and after yesterday&#39;s course I started thinking of a better way to explain what process means in an Agile world and how it differs from either an ISO-style paperfest or anarchy. &#160;This is the analogy I came up with.
Think about dining in a decent restaurant. &#160;There&#39;s a certain number [...]]]></description>
			<content:encoded><![CDATA[<p>I&#39;ve been doing Agile training again, and after yesterday&#39;s course I started thinking of a better way to explain what process means in an Agile world and how it differs from either an ISO-style paperfest or anarchy. &nbsp;This is the analogy I came up with.</p>
<p>Think about dining in a decent restaurant. &nbsp;There&#39;s a certain number of interactions you expect to &nbsp;happen &#8211; you&#39;re going to be greeted and seated, you expect to &nbsp;be offered an aperitif or water, you&#39;ll expect to see the menu and the wine list, and your going to expect your water, wine and dinner to be served. &nbsp;If any of these steps are missed you&#39;re likely to feel annoyed, but also if you are asked every 5 minutes if you&#39;d like to see the wine list, that&#39;s going to be annoying too.</p>
<p>There&#39;s a few ways round this. &nbsp;In some places each waiter looks after a number of tables and only deals with those. &nbsp;This means they always know the state of each table and are unlikely to repeat tasks. &nbsp;The problem is this is quite inefficient. If we get a large party in and the rest of the room is quiet we&#39;d like all our available waiters to help. &nbsp;We also have specialists (like the sommelier) who is going to have to serve the whole room. We might also have junior staff (the guy who brings the water) who isn&#39;t yet ready to deal with more complex tasks.</p>
<p>The traditional prescriptive methodology approach would be to introduce some kind of table checklist. We&#39;d have a set of boxes and tick off the tasks: has the water been offered? Have they seen the menu? and so on. &nbsp;The maitre d&#39; could then manage these table cards and allocate them to staff. &nbsp;He can also &#39;report&#39; on the status of the room to the owner by looking at the cards. &nbsp;Sounds good? &nbsp;Well it does offer a fairly strong guarantee that we will perform each table task exactly once, but we have introduced a major organisational task that&#39;s going to keep one of our seniors busy all night. &nbsp;We&#39;ve also prevented the team from being able to be proactive &#8211; if they spot a table where things don&#39;t seem to be happening they can&#39;t pitch in and help without getting approval from the supervisor. I think that&#39;s why this isn&#39;t how decent restaurants do it.</p>
<p>In reality, restaurants create a lightweight protocol to let each other know what&#39;s going on without the diner necessarily even knowing. &nbsp;When aperitifs or water is offered they will place a bottle coaster on the table. &nbsp;Each table might be set with generic wine glasses that are never used. &nbsp;Once the wine is ordered (but before it arrives which might take some time) they will be removed completely if no wine is required or replaced replaced with specific white or red wine glasses. &nbsp;The details will vary, but the principle is the same.</p>
<p>Any member of staff can see at a glance what state the table is in and deal with it accordingly. &nbsp;There&#39;s a system, but it doesn&#39;t need a prescriptive process with a command and control structure. &nbsp;The team can be proactive and deal with problems having confidence that they understand the situation and what is required &#8211; what does or doesn&#39;t need to be done. &nbsp;That&#39;s the kind of system we want a self-empowered agile team working in. &nbsp;We can&#39;t report by looking at cards, but we can look around the room and know exactly how will each table is doing which is what we really want to know, and we also still have a guarantee that we won&#39;t duplicate tasks.</p>
<p>This is the kind of process we are looking to create for the self-empowered Agile team.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.ceredir.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.ceredir.com/index.php/2010/02/18/the-agile-restaurant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maintenance plans in SQL Server 2008 failing on Windows Server 2008 R2</title>
		<link>http://blog.ceredir.com/index.php/2010/02/16/maintenance-plans-in-sql-server-2008-failing-on-windows-server-2008-r2/</link>
		<comments>http://blog.ceredir.com/index.php/2010/02/16/maintenance-plans-in-sql-server-2008-failing-on-windows-server-2008-r2/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 19:50:00 +0000</pubDate>
		<dc:creator>David Bending</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[dcom]]></category>
		<category><![CDATA[sql server 2008]]></category>
		<category><![CDATA[windows server]]></category>

		<guid isPermaLink="false">http://blog.ceredir.com/?p=96</guid>
		<description><![CDATA[I was having problems getting maintenance plans running. &#160;I could see an error being logged by DCOM, but &#160;when I went into component services to modify launch permissions everything was greyed out. &#160;The solution is obvious, and can be found in the link below:
61738644-F196-11D0-9953-00C04FD919C1 Launch Permissions &#8211; Event 10016 on Windows Server 2008 R2 (SharePoint [...]]]></description>
			<content:encoded><![CDATA[<p>I was having problems getting maintenance plans running. &nbsp;I could see an error being logged by DCOM, but &nbsp;when I went into component services to modify launch permissions everything was greyed out. &nbsp;The solution is obvious, and can be found in the link below:</p>
<p><a href="http://www.sharepointassist.com/2010/02/04/61738644-f196-11d0-9953-00c04fd919c1-launch-permissions-event-10016-on-windows-server-2008-r2-sharepoint-2007-sharepoint-2010/">61738644-F196-11D0-9953-00C04FD919C1 Launch Permissions &ndash; Event 10016 on Windows Server 2008 R2 (SharePoint 2007 &amp; SharePoint 2010) | Ulysses Ludwig&#39;s SharePoint blog</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.ceredir.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.ceredir.com/index.php/2010/02/16/maintenance-plans-in-sql-server-2008-failing-on-windows-server-2008-r2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quotations</title>
		<link>http://blog.ceredir.com/index.php/2010/02/04/quotations/</link>
		<comments>http://blog.ceredir.com/index.php/2010/02/04/quotations/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 10:30:24 +0000</pubDate>
		<dc:creator>David Bending</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://blog.ceredir.com/?p=93</guid>
		<description><![CDATA[I just came across a good thread on Linked In&#160;of people&#39;s favourite Agile related quotations.&#160; Here&#39;s my pick of the bunch:
&#160;
The best is the enemy of the good.
&#160;
Attributed on LinkedIn to Sir John Harvey-Jones, but it&#39;s actually Voltaire: &#34;Le mieux est l&#39;ennemi du bien.&#34;

Stop Starting, Start Finishing!
		- Sterling Mortensen 


If you want to build a [...]]]></description>
			<content:encoded><![CDATA[<p>I just came across a good thread on <a href="http://www.linkedin.com/answers/technology/software-development/TCH_SFT/626574-5629727">Linked In</a>&nbsp;of people&#39;s favourite Agile related quotations.&nbsp; Here&#39;s my pick of the bunch:</p>
<p>&nbsp;</p>
<blockquote><p>The best is the enemy of the good.</p></blockquote>
<p>&nbsp;</p>
<p>Attributed on LinkedIn to Sir John Harvey-Jones, but it&#39;s actually Voltaire: &quot;Le mieux est l&#39;ennemi du bien.&quot;</p>
<blockquote>
<p>Stop Starting, Start Finishing!<br />
		- Sterling Mortensen </p>
</blockquote>
<blockquote>
<p>If you want to build a ship, don&#39;t drum up the people to gather wood, divide the work and give orders. Instead, teach them to yearn for the vast and endless sea.<br />
		- Antoine De Saint-Exupery</p>
</blockquote>
<blockquote>
<p>In preparing for battle I have always found that plans are useless, but planning is indispensable.<br />
		- Dwight D. Eisenhower</p>
</blockquote>
<blockquote>
<p>
		It is a bad plan that admits of no modification.<br />
		- Publilius Syrus</p>
</blockquote>
<blockquote>
<p>Story tests verify &quot;Building the right thing&quot; vs. unit test that verify &quot;Building the thing right&quot;.</p>
</blockquote>
<blockquote>
<p>Man who says &lsquo;it cannot be done&rsquo; should not interrupt the man doing it.<br />
		- old Chinese proverb</p>
</blockquote>
<blockquote>
<p>It is not the strongest of the species that survives, nor the most intelligent, but the one most responsive to change.<br />
		-&nbsp;Charles Darwin</p>
</blockquote>
<blockquote>
<p>Here is Edward Bear, coming downstairs now, bump, bump, bump, on the back of his head. It is, as far as he knows, the only way of coming downstairs, but sometimes he feels that there really is another way, if only he could stop bumping for a moment and think of it. And then he feels that perhaps there isn&#39;t.<br />
		- A. A. Milne&nbsp;</p>
</blockquote>
<blockquote>
<p>The biggest problem with communication is the illusion it has occurred.<br />
		- Michael James </p>
</blockquote>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.ceredir.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.ceredir.com/index.php/2010/02/04/quotations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Effective Software Development &#8211; How to Compare Elephant Herds</title>
		<link>http://blog.ceredir.com/index.php/2010/02/03/effective-software-development-how-to-compare-elephant-herds/</link>
		<comments>http://blog.ceredir.com/index.php/2010/02/03/effective-software-development-how-to-compare-elephant-herds/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 08:52:30 +0000</pubDate>
		<dc:creator>David Bending</dc:creator>
				<category><![CDATA[Agile]]></category>

		<guid isPermaLink="false">http://blog.ceredir.com/?p=91</guid>
		<description><![CDATA[It&#8217;s funny because it&#8217;s true&#8230;
effective software development.
]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s funny because it&#8217;s true&#8230;</p>
<p><a href='http://dnicolet1.tripod.com/agile/index.blog?entry_id=1987139'>effective software development</a>.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.ceredir.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.ceredir.com/index.php/2010/02/03/effective-software-development-how-to-compare-elephant-herds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pex &#8211; Some Early Thoughts</title>
		<link>http://blog.ceredir.com/index.php/2010/02/02/pex-some-early-thoughts/</link>
		<comments>http://blog.ceredir.com/index.php/2010/02/02/pex-some-early-thoughts/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 09:57:41 +0000</pubDate>
		<dc:creator>David Bending</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[pex]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://blog.ceredir.com/?p=81</guid>
		<description><![CDATA[I&#39;ve been looking recently at Pex, Microsoft&#39;s automated white box testing software. There&#39;s basically&#160;4 parts to Pex:

A framework for writing parameterised unit tests.
An explorer, for finding boundary conditions in code.
Suggestions of preconditions that should be added to methods.
Moles &#8211; a way of stubbing even static properties and methods (such as DateTime.Now).

Parameterised Unit Tests (PUT)
When manually [...]]]></description>
			<content:encoded><![CDATA[<p>I&#39;ve been looking recently at <a href="http://research.microsoft.com/en-us/projects/Pex/">Pex</a>, Microsoft&#39;s automated white box testing software. There&#39;s basically&nbsp;4 parts to Pex:</p>
<ol>
<li>A framework for writing parameterised unit tests.</li>
<li>An explorer, for finding boundary conditions in code.</li>
<li>Suggestions of preconditions that should be added to methods.</li>
<li>Moles &#8211; a way of stubbing even static properties and methods (such as DateTime.Now).</li>
</ol>
<h2>Parameterised Unit Tests (PUT)</h2>
<p>When manually writing unit tests, we often end up with blocks of tests that are essentially the same in concept, but with different input/output combinations.&nbsp; For example, an addition routine might have tests for different combination of negative and positive numbers.&nbsp; Pex creates its tests a <em>parameterized</em> tests.&nbsp; There is a template test, and underneath that an instance of each test value.</p>
<p>The templates are placed in a source file and look like normal unit tests.&nbsp; The parameterised versions are stored underneath in a .g.cs file.&nbsp; These files are not intended to be edited and are created automatically by the Pex explorer.</p>
<p>You can also write your own PUTs.&nbsp; More on this later&#8230;</p>
<h2>The Explorer</h2>
<p>The &#39;white box&#39; part of Pex refers to the explorer.&nbsp; This essentially looks at all the possible paths through a piece of code and generates a test for each. Let&#39;s look at this piece of code:</p>
<pre class="brush: c-sharp">public int Add(int x, int y)
{
    return x + y;
}</pre>
<p>If we run Pex on this, we get the following test:</p>
<pre class="brush: c-sharp">[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
public void Add01()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Add(s0, 0, 0);
    Assert.AreEqual&lt;int&gt;(0, i);
    Assert.IsNotNull((object)s0);
}</pre>
<p>Actually there&#39;s a bit more to it &#8211; but this shows the basic details.&nbsp; As we can see, it&#39;s a fairly dull test.&nbsp; in particular Pex hasn&#39;t added any code to see if the result of the operation has overflowed. On the other hand let&#39;s see what it does if there&#39;s a bit more going on in the method:</p>
<pre class="brush: c-sharp">public int Fibonacci(int n)
{
    if (n &lt; 0)
    {
        throw new ArgumentOutOfRangeException(&quot;n&quot;);
    }

    if (n == 0)
    {
        return 0;
    }

    if (n == 1)
    {
        return 1;
    }

    return Fibonacci(n - 2) + Fibonacci(n - 1);
}</pre>
<p>This is an (admiteddly rubbish) implementation of Fibonacci. It&#39;s more interesting that Add because there&#39;s more paths through it. This time when we run Pex we get:</p>
<pre class="brush: c-sharp">[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
public void Fibonacci01()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Fibonacci(s0, 0);
    Assert.AreEqual&lt;int&gt;(0, i);
    Assert.IsNotNull((object)s0);
}

[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
public void Fibonacci02()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Fibonacci(s0, 1);
    Assert.AreEqual&lt;int&gt;(1, i);
    Assert.IsNotNull((object)s0);
}

[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
public void Fibonacci03()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Fibonacci(s0, 2);
    Assert.AreEqual&lt;int&gt;(1, i);
    Assert.IsNotNull((object)s0);
}

[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
public void Fibonacci04()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Fibonacci(s0, int.MinValue);
}

[TestMethod]
[PexGeneratedBy(typeof(CalculatorTest))]
public void Fibonacci05()
{
    int i;
    Calculator s0 = new Calculator();
    i = this.Fibonacci(s0, 14);
    Assert.AreEqual&lt;int&gt;(377, i);
    Assert.IsNotNull((object)s0);
}&nbsp;</pre>
<p>So Pex has created a test case for each path through the program.</p>
<h2>Suggestions</h2>
<p>When passing reference types to a method, Pex will realise that the value could be null.&nbsp; For all such methods it will suggest the a pre-condition is added.&nbsp; There&#39;s also a button that will get Pex to automatically insert the pre-condition into the code for you.&nbsp; This saves a bit of time, but isn&#39;t a huge win.&nbsp; That said Pex does understand code contracts so there may be bigger wins to be had here.</p>
<h2>Moles</h2>
<p>Pex also contains a mocking framework called Moles.&nbsp; Unlike most mocking frameworks, Moles do their work at runtime level (like Isolator) and consequently you can use them to mock static properties.&nbsp; Consider this code:</p>
<pre class="brush: c-sharp">public void Y2kBug()
{
    if (DateTime.Now == new DateTime(1999, 12, 31))
    {
        throw new InvalidProgramException(&quot;Arrgghhh!!!!&quot;);
    }
}&nbsp;</pre>
<p>We&#39;d like to unit test this, and we don&#39;t want to have to change the system clock to do so.&nbsp; Unfortunately, DateTime.Now is static so the likes of Rhino Mocks and MoQ can&#39;t help.&nbsp; With Pex Moles we can do the following:</p>
<pre class="brush: c-sharp">[TestMethod]
[ExpectedException(typeof(InvalidProgramException))]
[HostType(&quot;Moles&quot;)]
public void Y2kBugTest()
{
    MDateTime.NowGet = () =&gt; new DateTime(1999, 12, 31);

    Y2k target = new Y2k();
    target.Y2kBug();
} </pre>
<p>We have generated Moles for mscorlib (by choosing Add New Item -&gt; Pex Moles) in Visual Studio.&nbsp; This creates a mole for each mscorlib type in the Moles namespace with the M prefix.&nbsp; We then tell the mole to return the value we ant in the unit test (note that we supply a delegate not a value, and that properties are a Put and a Get mole).&nbsp; By specifying the <code>HostType </code>attribute for our test, we cause the unit test runner to route the code trhough a mole supplying the value we want.</p>
<p>See Nikolai Tellman&#39;s video for more on this at: <a href="http://channel9.msdn.com/posts/Peli/Moles-Replace-any-NET-method-with-a-delegate/">http://channel9.msdn.com/posts/Peli/Moles-Replace-any-NET-method-with-a-delegate/</a>.</p>
<p>
	&nbsp;</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://blog.ceredir.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://blog.ceredir.com/index.php/2010/02/02/pex-some-early-thoughts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

