<?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>blog.boro2g.co.uk</title>
	<atom:link href="http://blog.boro2g.co.uk/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.boro2g.co.uk</link>
	<description>Some ideas about ASP.Net &#38; Sitecore</description>
	<lastBuildDate>Thu, 03 May 2012 22:14:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Navigate quickly around the Sitecore Content Editor</title>
		<link>http://blog.boro2g.co.uk/navigate-quickly-around-the-sitecore-content-editor/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=navigate-quickly-around-the-sitecore-content-editor</link>
		<comments>http://blog.boro2g.co.uk/navigate-quickly-around-the-sitecore-content-editor/#comments</comments>
		<pubDate>Thu, 03 May 2012 19:41:26 +0000</pubDate>
		<dc:creator>boro</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://blog.boro2g.co.uk/?p=214</guid>
		<description><![CDATA[During the lifecycle of a Sitecore project, the content editor will be used by several types of user. Here are some tips on how to navigate quickly around the Sitecore Content Editor. As a developer, a lot of these techniques have been discovered trying to save time during the development phase of a project. That&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>During the lifecycle of a Sitecore project, the content editor will be used by several types of user. Here are some tips on how to navigate quickly around the Sitecore Content Editor. As a developer, a lot of these techniques have been discovered trying to save time during the development phase of a project. That&#8217;s not to say they don&#8217;t apply for anyone!</p>
<ol>
<li>Every item in the Sitecore tree has a unique guid &#8211; this is seen in the &#8216;Quick Info&#8217; bar.<a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/quick-info.jpg"><img class="alignnone size-medium wp-image-224" title="quick info" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/quick-info-300x95.jpg" alt="" width="300" height="95" /></a> If you know an items guid, use this to your advantage! You can either search at the top of the content tree <a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/search.jpg"><img class="alignnone size-medium wp-image-226" title="search" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/search-300x65.jpg" alt="" width="300" height="65" /></a> or alternatively the search box in the taskbar<a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/taskbar.jpg"><img class="alignnone size-medium wp-image-228" title="taskbar" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/taskbar-300x58.jpg" alt="" width="300" height="58" /></a>. Both options will jump you to the item if it exists.</li>
<li>Raw values is useful for tracking down related items. If you have a multilist / treelist etc then toggling raw values will show the guid&#8217;s of all the selected items. <a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/raw-values.jpg"><img class="alignnone size-medium wp-image-225" title="raw values" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/raw-values-300x29.jpg" alt="" width="300" height="29" /></a>Plug this into step 1 and you can very quickly jump to the related items. You can toggle &#8216;raw values&#8217; from the &#8216;View&#8217; section of the ribbon.</li>
<li>The &#8216;Links&#8217; flyout in the navigation panel gives you the relationship between items &#8211; here you can see all the items &#8216;referring to&#8217; or &#8216;referred by&#8217; the current item. A good example of this is seeing all the items which are of a certain template type.<a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/links.jpg"><img class="alignnone size-medium wp-image-222" title="links" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/links-300x105.jpg" alt="" width="300" height="105" /></a></li>
<li>Single clicking the items path / guid / template path / template guid selects the whole value. This might seem like a minor point but saves clicks when navigating the content editor.<a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/quick-info-highlight.jpg"><img class="alignnone size-medium wp-image-223" title="quick info highlight" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/quick-info-highlight-300x97.jpg" alt="" width="300" height="97" /></a></li>
<li>Shortcuts &#8211; the content editor is packed with them &#8211; highlighting items in the content editor often shows the keyboard shortcut <a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/shortcut.jpg"><img class="alignnone size-full wp-image-227" title="shortcut" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/shortcut.jpg" alt="" width="110" height="75" /></a>. A lot of them are listed at <a href="http://www.sitecore.net/Community/Technical-Blogs/Sitecore-Australia-Blog/Posts/2010/06/Top-100-List-of-Sitecore.aspx" target="_blank">http://www.sitecore.net/Community/Technical-Blogs/Sitecore-Australia-Blog/Posts/2010/06/Top-100-List-of-Sitecore.aspx</a></li>
<li>&#8216;Go to template&#8217; available in the developer section of the ribbon. This jumps you directly to an items template. <a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/goto.jpg"><img class="alignnone size-full wp-image-220" title="goto" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/goto.jpg" alt="" width="88" height="73" /></a></li>
<li>The &#8216;inheritance&#8217; tab of a template. Here you can see all the templates that make up the item in question &#8211; clicking any takes you to that field section / field. <a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/inheritance.jpg"><img class="alignnone size-medium wp-image-221" title="inheritance" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/05/inheritance-300x257.jpg" alt="" width="300" height="257" /></a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.boro2g.co.uk/navigate-quickly-around-the-sitecore-content-editor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically set the language of the content editor</title>
		<link>http://blog.boro2g.co.uk/automatically-set-the-language-of-the-content-editor/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automatically-set-the-language-of-the-content-editor</link>
		<comments>http://blog.boro2g.co.uk/automatically-set-the-language-of-the-content-editor/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 11:40:52 +0000</pubDate>
		<dc:creator>boro</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://blog.boro2g.co.uk/?p=200</guid>
		<description><![CDATA[In a recent build we had a request from the client to automatically set the language of the content editor based on where in the tree they were viewing. The rules for selecting the language were quite simple: - sitecore &#8211; Content &#8212; English site &#8211; field with value for default language set to be [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent build we had a request from the client to automatically set the language of the content editor based on where in the tree they were viewing. The rules for selecting the language were quite simple:</p>
<p><em>- sitecore<br />
&#8211; Content<br />
&#8212; English site &#8211; field with value for default language set to be &#8216;en&#8217;<br />
&#8212; French site &#8211; field with value for default language set to be &#8216;fr-fr&#8217;</em></p>
<p>If the user was making changes within the English site, they wanted the Content Editor to default to &#8216;en&#8217;. If they were editing within the French site, they wanted the Content Editor to default to &#8216;fr-fr&#8217;.</p>
<p>With the help of support, the following solution was suggested:</p>
<ol>
<li>Create your own class inherited from <strong>Sitecore.Shell.Applications.ContentManager.ContentEditorForm</strong></li>
<li>Add a new method:
<pre class="brush: csharp;">
public void ChangeLanguage(string id)
{
    Error.AssertString(id, &quot;id&quot;, false);
    if (ShortID.IsShortID(id))
    {
        id = ShortID.Decode(id);
    }

    //get the selected item
    Item item = Sitecore.Configuration.Factory.GetDatabase(Context.ContentDatabase.ToString()).GetItem(id);

    if (item != null)
    {
        //get the current site root
        Item currentSiteRoot = item.Axes.GetAncestors().FirstOrDefault(a =&gt; a.TemplateID == new ID(new Guid(....)));

        if (currentSiteRoot != null)
        {
            //if the current language doesnt match the expected language, set the language
            Language siteLanguage = Language.Parse(currentSiteRoot.Fields[&quot;....&quot;].Value);

            if (ContentEditorDataContext.Language != siteLanguage)
            {
                ContentEditorDataContext.Language = siteLanguage;
            }
        }
    }
}
</pre>
</li>
<li>Edit <strong>\sitecore\shell\Applications\Content Manager\Default.aspx</strong>, changing the sc:CodeBeside reference to point to your new class:
<pre class="brush: xml;">
&lt;sc:CodeBeside runat=&quot;server&quot; Type=&quot;YourNamespase.YourClass,YourAssembly&quot; /&gt;
</pre>
<p><em>Note, you need to keep the CodeBeside reference on one line as per the out the box version (the other controls are eg DataContext, RegisterKey etc)</em>
</li>
<li>Edit <strong>\sitecore\shell\Applications\Content Manager\Content editor.js</strong>, adding a call to your new method. This needs to happen in the <strong>onTreeNodeClick</strong> method after <strong>LoadItem</strong>.
<pre class="brush: xml;">
scContentEditor.prototype.onTreeNodeClick = function (sender, id) {
    ...
    scForm.postRequest(&quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;LoadItem(\&quot;&quot; + id + &quot;\&quot;)&quot;);
    //new call to ChangeLanguage
    scForm.postRequest(&quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;ChangeLanguage(\&quot;&quot; + id + &quot;\&quot;)&quot;);
    ...
}
</pre>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.boro2g.co.uk/automatically-set-the-language-of-the-content-editor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moq &#8211; the basics</title>
		<link>http://blog.boro2g.co.uk/moq-the-basics/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=moq-the-basics</link>
		<comments>http://blog.boro2g.co.uk/moq-the-basics/#comments</comments>
		<pubDate>Wed, 04 Apr 2012 20:37:38 +0000</pubDate>
		<dc:creator>boro</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Test Driven Development]]></category>

		<guid isPermaLink="false">http://blog.boro2g.co.uk/?p=185</guid>
		<description><![CDATA[During a recent XP programming course we made use of the Moq&#8217;ing framework. I&#8217;d not used this before so tried to come up with some example moq basic tests. There are several tutorials on the internet which offer up the basics so do hunt around. Hopefully the following provides some simple examples for people to [...]]]></description>
			<content:encoded><![CDATA[<p>During a recent XP programming course we made use of the Moq&#8217;ing framework. I&#8217;d not used this before so tried to come up with some example moq basic tests. There are several tutorials on the internet which offer up the basics so do hunt around. Hopefully the following provides some simple examples for people to get started with.</p>
<p>The following code relies on the following assemblies:</p>
<ul>
<li>nunit.framework &#8211; available from <a title="http://www.nunit.org/" href="http://www.nunit.org/" target="_blank">http://www.nunit.org/</a></li>
<li>moq &#8211; available from <a title="http://code.google.com/p/moq/" href="http://code.google.com/p/moq/" target="_blank">http://code.google.com/p/moq/</a></li>
</ul>
<p>The real crux of TDD is that you program your functionality to interfaces &#8211; here we have a simple interface and dto:</p>
<pre class="brush: csharp;">public interface IMyInterface
{
    int IntMethod(int value);

    int HarderIntMethod(int value, int anotherValue);

    MyObject MyObjectMethod(int value);
}

public class MyObject
{
    public virtual string MyVirtualProperty { get; set; }
    public string MyProperty { get; set; }
}</pre>
<p><em>Note the importance of the virtual property in MyObject will be highlighted in the tests</em>. In the following examples not all the tests pass &#8211; this is intentional! Failing tests are included to demonstrate specific features of Moq. Apologies for the long dump of test code &#8211; the idea is really to copy it into a test class and let NUnit do the work.</p>
<pre class="brush: csharp;">[TestFixture]
public class MyTests
{
    [Test]
    [TestCase(1, TestName = "1")]
    public void A_TestMockBehaviourDefault(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;();

        int result = myInterface.Object.IntMethod(value);

        //we havent setup mock for value = 1
        Assert.AreEqual(value, result);

        myInterface.Verify();
    }

    [Test]
    [TestCase(1, TestName = "1")]
    public void B_TestMockBehaviourStrict(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        int result = myInterface.Object.IntMethod(value);

        //now in strict mode
        //again, we havent setup mock for value = 1
        Assert.AreEqual(value, result);

        myInterface.Verify();
    }

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    public void C_TestMockBehaviourStrictWithSpecificValue(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        myInterface.Setup(a =&gt; a.IntMethod(1)).Returns(1);

        int result = myInterface.Object.IntMethod(value);

        //we have setup the mock for value = 1 but not value = 2
        Assert.AreEqual(value, result);

        myInterface.Verify();
    }       

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    public void D_TestMockBehaviourStrictWithTypedValue(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        myInterface.Setup(a =&gt; a.IntMethod(It.IsAny&lt;int&gt;())).Returns((int a) =&gt; a);

        int result = myInterface.Object.IntMethod(value);

        //any int will pass
        Assert.AreEqual(value, result);

        myInterface.Verify();
    }

    private int _count = 0;

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    public void E_TestMockBehaviourStrictWithTypedValueAndCallback(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);            

        myInterface.Setup(a =&gt; a.IntMethod(It.IsAny&lt;int&gt;())).Returns((int a) =&gt; a).Callback(() =&gt; _count++);

        int result = myInterface.Object.IntMethod(value);

        //we can log callbacks before or after the Returns call
        Console.WriteLine(String.Format("Called E_TestMockBehaviourStrictWithTypedValueAndCallback {0} times", _count));

        Assert.AreEqual(value, result);

        myInterface.Verify();
    }

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    public void E1_TestMockBehaviourStrictWithTypedValueAndCallbackBefore(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        //callbacks can happen before and after the Returns call
        myInterface.Setup(a =&gt; a.IntMethod(It.IsAny&lt;int&gt;())).Callback(() =&gt; Console.WriteLine("before")).Returns((int a) =&gt; a).Callback(() =&gt; Console.WriteLine("after"));

        int result = myInterface.Object.IntMethod(value);

        Assert.AreEqual(value, result);

        myInterface.Verify();
    }

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    [ExpectedException(typeof(Exception))]
    public void F_TestMockBehaviourStrictWithException(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        //this can throw specific exceptions if we want
        //catching at a test level is a bit loose since other code could exception - see F1 for alternative
        myInterface.Setup(a =&gt; a.IntMethod(It.IsAny&lt;int&gt;())).Throws&lt;Exception&gt;();

        int result = myInterface.Object.IntMethod(value);

        myInterface.Verify();
    }

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    public void F1_TestMockBehaviourStrictWithException(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        //this can throw specific exceptions if we want
        myInterface.Setup(a =&gt; a.IntMethod(It.IsAny&lt;int&gt;())).Throws&lt;Exception&gt;();

        //here we can catch specific exceptions
        Assert.Throws&lt;Exception&gt;(() =&gt; myInterface.Object.IntMethod(value));

        myInterface.Verify();
    }

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    public void G_TestMockBehaviourStrictVerify(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        myInterface.Setup(a =&gt; a.IntMethod(It.IsAny&lt;int&gt;())).Returns((int a) =&gt; a).Verifiable();
        myInterface.Setup(a =&gt; a.HarderIntMethod(It.IsAny&lt;int&gt;(), (It.IsAny&lt;int&gt;()))).Returns((int a, int b) =&gt; a).Verifiable();

        int result = myInterface.Object.IntMethod(value);

        //we havent called HarderIntMethod
        myInterface.Verify();
    }

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    public void H_TestMockBehaviourStrictVerifySuccess(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        myInterface.Setup(a =&gt; a.IntMethod(It.IsAny&lt;int&gt;())).Returns((int a) =&gt; a).Verifiable();
        myInterface.Setup(a =&gt; a.HarderIntMethod(It.IsAny&lt;int&gt;(), It.IsAny&lt;int&gt;())).Returns((int a, int b) =&gt; a).Verifiable();

        int result = myInterface.Object.IntMethod(value);

        int anotherResult = myInterface.Object.HarderIntMethod(value, value);

        myInterface.Verify();
    }

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    public void I_TestMockBehaviourStrictWithTypedValueAndLogicOnInput(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        //setup can perform logic based on input to determine return value(s)
        myInterface.Setup(a =&gt; a.IntMethod(It.Is&lt;int&gt;(b =&gt; b % 2 == 0))).Returns((int a) =&gt; a);
        myInterface.Setup(a =&gt; a.IntMethod(It.Is&lt;int&gt;(b =&gt; b % 2 != 0))).Returns((int a) =&gt; -a);

        int result = myInterface.Object.IntMethod(value);

        Assert.AreEqual(value, result);

        myInterface.Verify();
    }

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    [TestCase(4, TestName = "4")]
    public void J_TestMockBehaviourStrictWithTypedValueAndRangeLogicOnInput(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        //rather than specific logic, instead we can make use of Ranges
        myInterface.Setup(a =&gt; a.IntMethod(It.IsInRange&lt;int&gt;(0,3, Range.Inclusive))).Returns((int a) =&gt; a);

        int result = myInterface.Object.IntMethod(value);

        Assert.AreEqual(value, result);

        //we haven't setup a return value for 4
        myInterface.Verify();
    }

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    public void K_TestMockBehaviourStrictWithProperties(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        //we can manipulate objects being returned
        myInterface.Setup(a =&gt; a.MyObjectMethod(value)).Returns((int a) =&gt; new MyObject() { MyProperty = a.ToString() });

        MyObject result = myInterface.Object.MyObjectMethod(value);

        Assert.AreEqual(value.ToString(), result.MyProperty);

        myInterface.Verify();
    }

    [Test]
    public void L_TestMockBehaviourStrictWithPropertiesVerifyGet()
    {
        Mock&lt;MyObject&gt; myObject = new Mock&lt;MyObject&gt;(MockBehavior.Strict);

        //this is where you need virtual properties
        myObject.Setup(a =&gt; a.MyProperty).Returns("blah");

        myObject.Verify();

        myObject.VerifyGet(a =&gt; a.MyProperty);
    }

    [Test]
    public void L1_TestMockBehaviourStrictWithPropertiesVerifyGet()
    {
        Mock&lt;MyObject&gt; myObject = new Mock&lt;MyObject&gt;(MockBehavior.Strict);

        myObject.Setup(a =&gt; a.MyVirtualProperty).Returns("blah");

        myObject.Verify();

        //we have never accessed MyVirtualProperty hence the VerifyGet fails
        myObject.VerifyGet(a =&gt; a.MyVirtualProperty);
    }

    [Test]
    public void L2_TestMockBehaviourStrictWithPropertiesVerifyGet()
    {
        Mock&lt;MyObject&gt; myObject = new Mock&lt;MyObject&gt;(MockBehavior.Strict);

        myObject.Setup(a =&gt; a.MyVirtualProperty).Returns("blah");

        Assert.IsNotEmpty(myObject.Object.MyVirtualProperty);

        myObject.Verify();

        //we have accessed both properties
        myObject.VerifyGet(a =&gt; a.MyVirtualProperty);
    }

    [Test]
    public void L3_TestMockBehaviourStrictWithPropertiesSetupProperty()
    {
        Mock&lt;MyObject&gt; myObject = new Mock&lt;MyObject&gt;(MockBehavior.Strict);

        //rather than setup and then adding Returns method, SetupProperty achieves the same thing
        myObject.SetupProperty(a =&gt; a.MyVirtualProperty, "blah");

        Assert.IsNotEmpty(myObject.Object.MyVirtualProperty);

        myObject.Verify();

        myObject.VerifyGet(a =&gt; a.MyVirtualProperty);
    }

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    public void M_TestMockBehaviourStrictWithTypedValueAndDetailedCallback(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        //Callback and Returns can both deal with multiple parameters via Generics or parameters.
        // M1 shows the opposite of each
        myInterface.Setup(a =&gt; a.HarderIntMethod(It.IsAny&lt;int&gt;(), It.IsAny&lt;int&gt;()))
            .Returns((int a, int b) =&gt; a)
            .Callback&lt;int, int&gt;((a, b) =&gt; Console.WriteLine("A is " + a + " B is " + b));

        int result = myInterface.Object.HarderIntMethod(value, value + 1);

        Assert.AreEqual(value, result);

        myInterface.Verify();
    }

    [Test]
    [TestCase(1, TestName = "1")]
    [TestCase(2, TestName = "2")]
    public void M1_TestMockBehaviourStrictWithTypedValueAndDetailedCallbackAlternativeSyntax(int value)
    {
        Mock&lt;IMyInterface&gt; myInterface = new Mock&lt;IMyInterface&gt;(MockBehavior.Strict);

        //demonstrates the opposite of M in terms of the syntax required into Callback and Returns
        myInterface.Setup(a =&gt; a.HarderIntMethod(It.IsAny&lt;int&gt;(), It.IsAny&lt;int&gt;()))
            .Returns&lt;int , int&gt;((a, b) =&gt; a)
            .Callback((int a, int b) =&gt; Console.WriteLine("A is " + a + " B is " + b));

        int result = myInterface.Object.HarderIntMethod(value, value + 1);

        Assert.AreEqual(value, result);

        myInterface.Verify();
    }
}</pre>
<p>Here is the expected results when evaluated in NUnit:</p>
<p><a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/04/nunit.jpg"><img class="alignnone size-medium wp-image-193" title="nunit" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/04/nunit-300x230.jpg" alt="" width="300" height="230" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.boro2g.co.uk/moq-the-basics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>$name in your Sitecore content</title>
		<link>http://blog.boro2g.co.uk/name-in-your-sitecore-content/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=name-in-your-sitecore-content</link>
		<comments>http://blog.boro2g.co.uk/name-in-your-sitecore-content/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 12:05:33 +0000</pubDate>
		<dc:creator>boro</dc:creator>
				<category><![CDATA[Sitecore]]></category>
		<category><![CDATA[$name]]></category>
		<category><![CDATA[sitecore]]></category>

		<guid isPermaLink="false">http://blog.boro2g.co.uk/?p=166</guid>
		<description><![CDATA[One issue that seems to regularly occur in Sitecore builds is pages showing $name in the content. Its the sort of problem that seems to creep into projects the further through you get. Why does it happen? When you setup Sitecore templates they are typically built up from several other templates eg: A content page [...]]]></description>
			<content:encoded><![CDATA[<p>One issue that seems to regularly occur in Sitecore builds is pages showing $name in the content. Its the sort of problem that seems to creep into projects the further through you get.</p>
<p><strong>Why does it happen?</strong></p>
<p>When you setup Sitecore templates they are typically built up from several other templates eg:</p>
<ul>
<li>A content page is comprised from:</li>
<ul>
<li><em>Page Title</em> field section</li>
<li><em>Meta Data</em> field section</li>
<li>etc</li>
</ul>
</ul>
<p>Down the line you decide you want to add <em>&#8216;Page Content &#8211; (Header and Body fields)&#8217;</em> to all pages so you setup a new Field Section template along with corresponding fields and <em>__standard values</em>. So that new pages automatically push the item name to the Header field, you set the <em>__standard values</em> to contain $name.</p>
<p>All this gets published and you then come to check the front end of the site &#8211; pages created before adding the Page Content field section now have the new header and body fields but the header field shows $name <img src='http://blog.boro2g.co.uk/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>The reason being these fields are inheriting their value from <em>__standard values</em> &#8211; variables such as $name are processed when items are created. See <a title="http://adeneys.wordpress.com/2009/12/29/custom-tokens-and-nvelocity-for-item-creation/" href="http://adeneys.wordpress.com/2009/12/29/custom-tokens-and-nvelocity-for-item-creation/" target="_blank">http://adeneys.wordpress.com/2009/12/29/custom-tokens-and-nvelocity-for-item-creation/</a> for info on how to create custom replacement tokens. There is also more information on <a title="http://learnsitecore.cmsuniverse.net/en/Developers/Articles/2010/08/Standard-values-in-sitecore.aspx" href="http://learnsitecore.cmsuniverse.net/en/Developers/Articles/2010/08/Standard-values-in-sitecore.aspx" target="_blank">http://learnsitecore.cmsuniverse.net/en/Developers/Articles/2010/08/Standard-values-in-sitecore.aspx</a></p>
<p><strong>How to solve the problem?</strong></p>
<p>When items are created they are processed by a set of pipelines. An example of this is <em>expandInitialFieldValue </em>pipeline<em>.</em> Out the box, this makes use of  the <em>MasterVariablesReplacer. </em></p>
<p>You now have a couple options, either you can call the <em>MasterVariablesReplacer</em> for the problematic items or you could manually script the same functionality. The following code demonstrates the manual approach:</p>
<pre class="brush: xml;">&lt;%@ Page Language="C#" AutoEventWireup="true" %&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

&lt;%@ Import Namespace="Sitecore.Data.Items" %&gt;
&lt;%@ Import Namespace="Sitecore.Data.Fields" %&gt;
&lt;%@ Import Namespace="Sitecore.Data" %&gt;

&lt;script runat="server"&gt;    

    public void FixNames_Click(object sender, EventArgs e)
    {
        //note, this doesn't error check the root guid is valid item
        Item root = Database.GetDatabase("master").GetItem(new ID(new Guid(RootIdTextBox.Text)));
        int fixes = 0;

        using (new Sitecore.SecurityModel.SecurityDisabler())
        {
            fixes = RecurseAndFix(root);
        }

        ResultsLiteral.Text = String.Format("&lt;hr /&gt;Fixed {0} cases of '$name'", fixes);
    }

    private int RecurseAndFix(Item root)
    {
        int fixes = 0;

        if (root.Template != null)
        {
            foreach (TemplateFieldItem field in root.Template.Fields)
            {
                Field existingField = root.Fields[field.ID];

                if (existingField != null)
                {
                    bool fixMe = false;

                    if (existingField.Value.Equals("$name"))
                    {
                        fixMe = true;
                    }

                    if (existingField.ContainsStandardValue &amp;&amp; existingField.GetStandardValue().Equals("$name"))
                    {
                        fixMe = true;
                    }

                    if (fixMe)
                    {
                        using (new EditContext(root))
                        {
                            existingField.Value = root.Name;
                            fixes++;
                        }
                    }
                }
                else
                {
                    if (root.Template.StandardValues[field.ID].Equals("$name"))
                    {
                        using (new EditContext(root))
                        {
                            root[field.ID] = root.Name;
                            fixes++;
                        }
                    }
                }
            }
        }

        foreach (Item child in root.Children)
        {
            fixes += RecurseAndFix(child);
        }

        return fixes;
    }

&lt;/script&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
&lt;head id="Head1" runat="server"&gt;
    &lt;title&gt;'$name' Fixer &lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;form id="form1" runat="server"&gt;
        &lt;p&gt;'$name' Fixer &lt;/p&gt;
        &lt;p&gt;
            Running the code on this page searches through all the content in the tree and replaces
            any '$name' values with the item's name.
        &lt;/p&gt;
        &lt;h2&gt;Note: Be careful, only run on content nodes and children and not templates!&lt;/h2&gt;
        &lt;hr /&gt;
        &lt;div&gt;
            Root id: &lt;asp:TextBox runat="server" ID="RootIdTextBox" Width="600"&gt;&lt;/asp:TextBox&gt;
            &lt;asp:Button runat="server" OnClick="FixNames_Click" Text="Fix '$name'" /&gt;
        &lt;/div&gt;
        &lt;asp:Literal runat="server" ID="ResultsLiteral" /&gt;
    &lt;/form&gt;
&lt;/body&gt;</pre>
<p>Its worth noting this can introduce some interesting challenges if Language Fallback is used on your site. The script above works fine for content items on a single language site. If you need similar functionality when language fallback is in place it may actually be meaningful to set $name = &#8221; for non-primary languages. This will ensure the fallback will occur correctly, rather than finding $name and thinking it is valid content.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.boro2g.co.uk/name-in-your-sitecore-content/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How do Sitecore commands work in the cms?</title>
		<link>http://blog.boro2g.co.uk/how-do-sitecore-commands-work-in-the-cms/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=how-do-sitecore-commands-work-in-the-cms</link>
		<comments>http://blog.boro2g.co.uk/how-do-sitecore-commands-work-in-the-cms/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 22:17:36 +0000</pubDate>
		<dc:creator>boro</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://blog.boro2g.co.uk/?p=159</guid>
		<description><![CDATA[Under the hood the Sitecore api offers huge amounts of functionality. When you are using the cms environment, chances are you are triggering this functionality via sitecore commands. Most buttons in the cms are tied into these commands so how do you pair up specific buttons to specific code? There is an excellent Firefox plugin [...]]]></description>
			<content:encoded><![CDATA[<p>Under the hood the Sitecore api offers huge amounts of functionality. When you are using the cms environment, chances are you are triggering this functionality via sitecore commands.</p>
<p>Most buttons in the cms are tied into these commands so how do you pair up specific buttons to specific code?</p>
<p>There is an excellent Firefox plugin &#8211; Firebug, which is essential if you do a lot of web development. If you haven&#8217;t ever used this, download it now!</p>
<p>Once installed, run through the following steps:</p>
<ol>
<li>Fire-up your cms environment inFirefox (once firebug is installed)</li>
<li>Activate firebug and select &#8216;inspect element&#8217; &#8211; then click the button you are interested in</li>
<li>Check the firebug window for the JavaScript attached to the button click &#8211; this should be wrapped in a sitecore form post JavaScript method eg <em>javascript:return scForm.postEvent(this,event,&#8217;item:setdisplayname&#8217;)</em></li>
<li>Open /app_config/commands.config and search for the command name. Examples of this are: <em>item:setdisplayname</em>,<em> item:publish</em></li>
<li>Find the assembly referenced in the commands file and fire up your favourite decompiler eg reflector or ilspy and search for eg <em>&lt;command name=&#8221;item:setdisplayname&#8221; type=&#8221;<strong>Sitecore.Shell.Framework.Commands.SetDisplayName,Sitecore.Kernel</strong>&#8221; /&gt;</em></li>
</ol>
<p>You should now have a route into the source code for each button in the cms!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.boro2g.co.uk/how-do-sitecore-commands-work-in-the-cms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sitecore packages</title>
		<link>http://blog.boro2g.co.uk/sitecore-packages/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sitecore-packages</link>
		<comments>http://blog.boro2g.co.uk/sitecore-packages/#comments</comments>
		<pubDate>Tue, 14 Feb 2012 14:46:20 +0000</pubDate>
		<dc:creator>boro</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://blog.boro2g.co.uk/?p=154</guid>
		<description><![CDATA[If you have ever developed with Sitecore, chances are you will have deployed content via Sitecore Packages. A sitecore package is essentially a zip file containing the xml to be stored in the sitecore databases along with any files you choose to deploy. Some upgrades make use of *.update files &#8211; this is out the [...]]]></description>
			<content:encoded><![CDATA[<p>If you have ever developed with Sitecore, chances are you will have deployed content via Sitecore Packages.</p>
<p>A sitecore package is essentially a zip file containing the xml to be stored in the sitecore databases along with any files you choose to deploy. Some upgrades make use of *.update files &#8211; this is out the scope of this post.</p>
<p>When you install content from packages, items should have the same guid. If conflicts are found during an install you are presented with several options. <em>One word of caution &#8211; if you choose overwrite, its pretty easy to blow away large chunks of the tree if you package only contains a few items.</em></p>
<p>If you want to see what is in a package you have a few options:</p>
<ol>
<li>Drill into the zip file with your favourite zip program &#8211; content items are nested by database and then path</li>
<li>Load the package into the Sitecore Package Designer (I wish I knew about this one sooner!!!!!)</li>
</ol>
<p>For the second option, there is a hidden button (why this is hidden I dont know!) in the package designer:</p>
<p><a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/02/package-designer.jpg"><img class="alignnone size-full wp-image-155" title="package designer" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/02/package-designer.jpg" alt="" width="191" height="159" /></a></p>
<p>When you click &#8216;From Existing&#8217; you are shown the contents of your data -&gt; packages folder. If you have been sent the package, copy it to this folder.</p>
<p>Once the package is selected you should see items in the package designer as if you had created the package yourself. From here you can then save the xml definition as per normal.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.boro2g.co.uk/sitecore-packages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add item anywhere in the tree without setting any Sitecore insert options</title>
		<link>http://blog.boro2g.co.uk/add-item-anywhere-in-the-tree-without-setting-any-sitecore-insert-options/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=add-item-anywhere-in-the-tree-without-setting-any-sitecore-insert-options</link>
		<comments>http://blog.boro2g.co.uk/add-item-anywhere-in-the-tree-without-setting-any-sitecore-insert-options/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 11:06:16 +0000</pubDate>
		<dc:creator>boro</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://ec2-50-19-225-169.compute-1.amazonaws.com/wordpress/?p=147</guid>
		<description><![CDATA[Consider the following scenario: you setup a new Sitecore template (or branch) which you want to add anywhere in the tree without setting any sitecore insert options The reason you may want to do this is you have several templates in place throughout the tree, if the insert options can&#8217;t be inherited then you would [...]]]></description>
			<content:encoded><![CDATA[<p>Consider the following scenario: <em>you setup a new Sitecore template (or branch) which you want to add anywhere in the tree without setting any sitecore insert options</em></p>
<p>The reason you may want to do this is you have several templates in place throughout the tree, if the insert options can&#8217;t be inherited then you would need to update a lot of standard values!</p>
<p>If you dont use the rule engine for this (see <a title="Insert options with rule engine" href="http://www.newguid.net/Sitecore/2011/04/sitecore-rules-engine-how-to-create-an-insert-option-rule/" target="_blank">this post</a>) you can still achieve the same solution.</p>
<p>In the following example, we want the user to be able to add a Generic Form anywhere under the home node of the site.</p>
<pre class="brush: csharp;">using System;
using System.Linq;
using ###.DataSource.Cms;
using Sitecore.Data;
using Sitecore.Pipelines.GetMasters;

namespace ###.Domain.Cms.Specialization.Processors.GetMasters
{
    /// &lt;summary&gt;
    /// Allow content editor to add a generic form anywhere under the home node
    /// &lt;/summary&gt;
    public class GetGenericForm
    {
        public void Process(GetMastersArgs args)
        {
            if (args.Item.ID.Guid == ItemKeys.Home || args.Item.Axes.GetAncestors().Any(a =&gt; a.ID.Guid == ItemKeys.Home))
            {
                args.Masters.Add(Sitecore.Context.ContentDatabase.GetItem(new ID(TemplateKeys.GenericForm)));
            }
        }
    }
}</pre>
<p>Which then needs patching into the uiGetMasters pipeline (/App_Config/Include):</p>
<pre class="brush: xml;">&lt;configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"&gt;
    &lt;sitecore&gt;
    &lt;processors&gt;
      &lt;uiGetMasters&gt;
        &lt;processor
          patch:after="processor[@type='Sitecore.Pipelines.GetMasters.RunRules, Sitecore.Kernel']"
          type="###.Domain.Cms.Specialization.Processors.GetMasters.GetGenericForm, ###.Domain.Cms" /&gt;
      &lt;/uiGetMasters&gt;
    &lt;/processors&gt;
    &lt;/sitecore&gt;
&lt;/configuration&gt;</pre>
<hr />
<p>After the talk at the Bristol Sitecore User Group yesterday, Raul demonstrated the rule engine for this kind of thing &#8211; the exact same problem can be solved without any code <img src='http://blog.boro2g.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You need to set yourself up a rule eg:</p>
<p><a href="http://blog.boro2g.co.uk/wp-content/uploads/2012/02/rule.jpg"><img class="  wp-image-152" title="rule engine" src="http://blog.boro2g.co.uk/wp-content/uploads/2012/02/rule-300x152.jpg" alt="" width="300" height="152" /></a></p>
<p>Note, one step remains &#8211; you need to select the root item.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.boro2g.co.uk/add-item-anywhere-in-the-tree-without-setting-any-sitecore-insert-options/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>API techniques &#8211; accessing items in the sitecore tree</title>
		<link>http://blog.boro2g.co.uk/api-techniques-accessing-items-in-the-sitecore-tree/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=api-techniques-accessing-items-in-the-sitecore-tree</link>
		<comments>http://blog.boro2g.co.uk/api-techniques-accessing-items-in-the-sitecore-tree/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 11:00:29 +0000</pubDate>
		<dc:creator>boro</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://ec2-50-19-225-169.compute-1.amazonaws.com/wordpress/?p=137</guid>
		<description><![CDATA[Sitecore offers various methods for accessing items in the sitecore tree. The following shows some examples: //access item by specific id Item itemByGuid = Sitecore.Context.Database.GetItem(new ID(&#34;{5071E33C-C56D-4D8F-9BBB-88DADA911DA5}&#34;)); //access item by sitecore path Item itemByPath = Sitecore.Context.Database.GetItem(&#34;/sitecore/Content/home/news/article&#34;); //access item by specific id in specific language Item itemByGuidInLanguage = Sitecore.Context.Database.GetItem(new ID(&#34;{5071E33C-C56D-4D8F-9BBB-88DADA911DA5}&#34;), LanguageManager.GetLanguage(&#34;fr-fr&#34;)); //access item by sitecore path in [...]]]></description>
			<content:encoded><![CDATA[<p>Sitecore offers various methods for accessing items in the sitecore tree. The following shows some examples:</p>
<pre class="brush: csharp;">
//access item by specific id
Item itemByGuid = Sitecore.Context.Database.GetItem(new ID(&quot;{5071E33C-C56D-4D8F-9BBB-88DADA911DA5}&quot;));

//access item by sitecore path
Item itemByPath = Sitecore.Context.Database.GetItem(&quot;/sitecore/Content/home/news/article&quot;);

//access item by specific id in specific language
Item itemByGuidInLanguage = Sitecore.Context.Database.GetItem(new ID(&quot;{5071E33C-C56D-4D8F-9BBB-88DADA911DA5}&quot;), LanguageManager.GetLanguage(&quot;fr-fr&quot;));

//access item by sitecore path in specific language
Item itemByPathInLanguage = Sitecore.Context.Database.GetItem(new ID(&quot;/sitecore/Content/home/news/article&quot;), LanguageManager.GetLanguage(&quot;fr-fr&quot;));
</pre>
<p>Typically we will store key item guids and key template guids in static classes so they can be used throughout the code.</p>
<p>From experience it is rare to use path to access items since an items path can change over time &#8211; essentially it is content rather than something fixed. An items guid should never change even when it is packaged up and distributed to multiple environments.</p>
<p>Its worth noting that once you have accessed an item, it may be it is null. Another scenario is that it doesnt have any versions &#8211; this can be caused by an item being published when it isnt in a final workflow state.<br />
These are easy things to check:</p>
<pre class="brush: csharp;">
//check the item actually exists
if (itemByGuid != null &amp;&amp; itemByGuid.Versions.Count &gt; 0)
{

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.boro2g.co.uk/api-techniques-accessing-items-in-the-sitecore-tree/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sitecore custom sublayout cache key</title>
		<link>http://blog.boro2g.co.uk/sitecore-custom-sublayout-cache-key/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sitecore-custom-sublayout-cache-key</link>
		<comments>http://blog.boro2g.co.uk/sitecore-custom-sublayout-cache-key/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 14:11:41 +0000</pubDate>
		<dc:creator>boro</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://blog.boro2g.co.uk/?p=123</guid>
		<description><![CDATA[Out the box, sitecore offers several options for caching the output of sublayouts. Some of the options you have for this are things like &#8216;vary by querystring&#8217; and &#8216;vary by data&#8217;. This post will demonstrate how to setup custom sublayout cache keys. Behind the scenes Sitecore builds up a cache key by appending together information [...]]]></description>
			<content:encoded><![CDATA[<p>Out the box, sitecore offers several options for caching the output of sublayouts. Some of the options you have for this are things like &#8216;vary by querystring&#8217; and &#8216;vary by data&#8217;. This post will demonstrate how to setup custom sublayout cache keys.</p>
<p>Behind the scenes Sitecore builds up a cache key by appending together information from the current request based on the parameters selected in the caching options. The result of this being the cache key is longer, the more permutations you select.</p>
<p>For typical builds, the out the box options cover all scenarios however what do you do if you need to customise this?</p>
<p>In a recent project we exploited * (or wildcard) items so we could accomodate data fed from an external api. This would map known url patterns to one node in the tree, allowing the presentation components on the page to be set in sitecore but the data in the body content be fed from and external system. The mvc routing dll solves the same problem in a similar fashion.</p>
<p>With the default cache options we ran into the issue that the cache key for each wildcard page would always be the same since the &#8216;vary by data&#8217; option used the items id, rather than the dynamic url we were assigning. Essentially every page would share the cache key for the * node.</p>
<p><strong>Solution</strong><br />
There are only two steps needed for this implementation:</p>
<ol>
<li>Create custom implementation of a sublayout</li>
<li>Create custom sublayout factory</li>
</ol>
<p><strong>Custom sublayout</strong></p>
<pre class="brush: csharp;">using System;
using System.Web;
using Sitecore.Web.UI.WebControls;

namespace ###.Presentation.Cms.UI
{
    public class StarItemSublayout : Sublayout
    {
        /// &lt;summary&gt;
        /// Setup custom cache key which includes Rawurl, hence allowing caching for * item sublayouts
        /// &lt;/summary&gt;
        public override string GetCacheKey()
        {
            if (!String.IsNullOrEmpty(base.GetCacheKey()))
            {
                return String.Concat(base.GetCacheKey(), HttpContext.Current.Request.RawUrl).ToLower();
            }

            return String.Empty;
        }
    }
}</pre>
<p>To use this on the front end, you would then embed in the markup using:</p>
<pre class="brush: csharp;">&lt;tc:StarItemSublayout runat="server" Path="~/###/Sublayouts/Common/Header.ascx" Cacheable="false" /&gt;</pre>
<p>If you want sublayouts instantiated from Sitecore to make use of your new type, you need to update the sublayout renderingControl in the config:</p>
<pre class="brush: xml;">&lt;renderingControls&gt;
  ...
  &lt;control template="sublayout" type="###.Presentation.Cms.UI.StarItemRenderingType, ###.Presentation.Cms" propertyMap="Path=path" /&gt;
  ...
&lt;/renderingControls&gt;</pre>
<p>And finally the new rendering type:</p>
<pre class="brush: csharp;">using System;
using System.Collections.Specialized;
using System.Web.UI;
using ###.Domain.Cms.Specialization.MvcRouting.Extensions;
using Sitecore;
using Sitecore.Diagnostics;
using Sitecore.Reflection;
using Sitecore.Web.UI;
using Sitecore.Web.UI.WebControls;

namespace ###.Presentation.Cms.UI
{
    /// &lt;summary&gt;
    /// Custom rendering type which allows creation of StarItemSublayout
    /// &lt;/summary&gt;
    public class StarItemRenderingType : SublayoutRenderingType
    {
        public override Control GetControl(NameValueCollection parameters, bool assert)
        {
            Sublayout sublayout = new Sublayout();

            ///Check if we are on a wildcard (or mvc routed) item
            if (Sitecore.Context.Item.Name == "*" || !String.IsNullOrEmpty(MvcRouteUtility.MatchedRoute()))
            {
                ///Create custom sublayout which has more detailed cachekey
                sublayout = new StarItemSublayout();
            }

            foreach (string str in parameters.Keys)
            {
                string str2 = parameters[str];
                ReflectionUtil.SetProperty(sublayout, str, str2);
            }
            return sublayout;
        }
    }
}</pre>
<p>In the example above the new sublayout is used for wildcard items as well as items which match an MVCRoute &#8211; this is some new functionality currently being developed by Steven Pope @ Sitecore UK.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.boro2g.co.uk/sitecore-custom-sublayout-cache-key/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Sitecore and RegisterClientScriptInclude / RegisterClientScriptBlock / RegisterClientScriptResource</title>
		<link>http://blog.boro2g.co.uk/sitecore-and-registerclientscriptinclude-block-resource/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=sitecore-and-registerclientscriptinclude-block-resource</link>
		<comments>http://blog.boro2g.co.uk/sitecore-and-registerclientscriptinclude-block-resource/#comments</comments>
		<pubDate>Fri, 26 Aug 2011 16:29:48 +0000</pubDate>
		<dc:creator>boro</dc:creator>
				<category><![CDATA[Sitecore]]></category>

		<guid isPermaLink="false">http://blog.boro2g.co.uk/?p=112</guid>
		<description><![CDATA[One of the common issues when using Sitecore HTML Caching is how to execute dynamic scripts based on code behind actions when the control front end is being cached. The solution listed below defines the theory behind the approach rather than the concrete implementations. Consider the following scenario: You need to display the date to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the common issues when using Sitecore HTML Caching is how to execute dynamic scripts based on code behind actions when the control front end is being cached.</p>
<p>The solution listed below defines the theory behind the approach rather than the concrete implementations.</p>
<p>Consider the following scenario:<br />
<em>You need to display the date to the user using javascript. To solve the issue, you decide to make use of either RegisterClientScriptBlock or RegisterStartupScript and register some javascript to write out alert(&#8216;DateTime.Now&#8217;) [psuedo code].</em></p>
<p>This works fine during development since you are building your project a lot and the full use of caching isnt implemented. Down the line, you tune up / turn on caches and the date is only shown the first load after the caches are emptied <img src='http://blog.boro2g.co.uk/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Do not fear, there is a solution to the issue and that is to make use of Sitecore Html Cache. Rather than calling asp.net RegisterClientScriptInclude(Block, Resource), setup your own methods (for the demo, these are exposed off SScriptManager):</p>
<pre class="brush: csharp;">
SScriptManager.RegisterClientScriptInclude(mediaUrl);
</pre>
<p>In your master page, add another control (for the demo, known as SScriptManager). </p>
<p>When you register the script includes / blocks, store this information in the html cache remembering to build the cache key from current item, current language and script key.</p>
<p>During the Render/PreRender phase of the page lifecycle, the SScriptManager can then iterate through all keys in html cache and if the keys match the current page, relay on the script calls to the page.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.boro2g.co.uk/sitecore-and-registerclientscriptinclude-block-resource/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

