<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Dr. Random</title>
    <link>http://www.drrandom.org/</link>
    <description>Random Thoughts for Random People</description>
    <language>en-us</language>
    <copyright>Casey Kramer</copyright>
    <lastBuildDate>Thu, 17 Jun 2010 21:46:05 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>casey.kramer@gmail.com</managingEditor>
    <webMaster>casey.kramer@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=ef0ceef1-8cf4-4a06-b626-2329ba3cff3a</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,ef0ceef1-8cf4-4a06-b626-2329ba3cff3a.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,ef0ceef1-8cf4-4a06-b626-2329ba3cff3a.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=ef0ceef1-8cf4-4a06-b626-2329ba3cff3a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If it walks like a giraffe and talks like a duck then what is it?  Maybe a duhk? 
Who knows, but it certainly is not a duck.  So if that is the case, then you
can probably guess what the Duhking library is all about…or maybe you can’t. 
In terms of programming, <a href="http://en.wikipedia.org/wiki/Duck_Typing" target="_blank">Duck
Typing</a> refers to the ability of some languages to allow you to treat an object
of one type as an object of a different type, provided the methods/properties needed
exist on both objects.  Statically typed languages are usually not very good
at this sort of loosey-goosey type inference, which is why this behavior is typically
restricted to languages with less stringent rules on typing.
</p>
        <p>
The <a href="http://duhking.codeplex.com/" target="_blank">Duhking library</a> is
an attempt to provide a very limited view of Duck Typing to .Net 3.5 applications. 
It allows you to graft an interface type onto an object that has matching properties
and/or methods but does not actually implement that type.  Why would you do that? 
Well, there were a couple of use-cases that drove the development of this library. 
One is a case where you want to wrap an API that you have no control over in an interface
so that you can test your consuming code.  This is common for things like HttpContext
or SmtpClient where you want to utilize the functionality of those libraries in your
code which you work so hard to make testable.  A standard approach to doing this
is to create an interface which defines the methods you need, and then create a “wrapper”
class that implements the interface, but then calls through to the real, un-testable
class to do the work.  So my thought was this:  “Since we’re just calling
through to matching method signatures in a class that already exists, why not abstract
the whole thing so I don’t need all of these crazy <em>Wrapper</em> classes everywhere?”.
</p>
        <p>
The other use-case came up when dealing with anonymous types.  We all know that
you can create basic data objects as an anonymous type, and then use them within the
scope they are created.  But what happens if you want to pass an anonymous type
to another method?  Well, you have two choices.  You can either move the
data in your anonymous type to another class/struct and pass <em>that</em>, or you
can resort to some reflection trickery to get the values out of a plain old object. 
It seemed like you should be able to create a new anonymous object as a particular
interface type, and then pass it around as that interface type.
</p>
        <p>
So the Duhking library allows you to do both fairly easily by use of some simple extension
methods on object, and the magic of the Castle project DynamicProxy2 library. 
Now that I’ve told you the secret, surely you can see how things work.  The library
simply creates a proxy of the specified interface, and then intercepts calls to the
interface methods, and in-turn calls the matching methods on the object we are “Duhking”. 
There is some checking going on to ensure that your object is compatible with the
interface you are wanting to Duhk, which involves checking method signatures (this
is surprisingly complicated, considering it is the basis for compiler based interface
implementation verification….but then I may be doing it the hard way), but beyond
that its just passing calls off to the proxy.  But enough idle chit-chat, lets
see a sample.
</p>
        <p>
Okay, so lets take the first use-case where we are wanting a wrapper class for a sealed
framework class so we can test our consumers.  Let’s go with the SmtpClient as
an example because it is fairly common to want to send emails for various reasons.
</p>
        <p>
First off we need out wrapper interface:<br /></p>
        <pre class="brush: csharp" name="code">public interface ISmtpClient
{
    string Host { get; set; }<br />
int Port { get; set; }<br /><br />
void Send(string from, string recipients, string subject, string body); } </pre>
        <p>
You could add in additional properties or methods, but this is enough to get you going. 
So now you can use this interface in place of the standard SmtpClient in the framework,
and write your tests against it without major pain.  So the next step is to Duhk
the real SmtpClient so it implements your interface when your ready to do the “real”
work.
</p>
        <pre class="brush: csharp" name="code">// Some code here getting ready to call your class that needs the client
var myClass = new ClassNeedingSmtpClient(new SmtpClient().AsType&lt;ISmtpClient&gt;());
// and now you do something with it
</pre>
        <p>
Pretty cool huh?  You can also check to see if the given concrete type can be
Duhked by using the CanBe extension method 
</p>
        <pre class="brush: csharp" name="code">// Some code here getting ready to call your class that needs the client
var realClient = new SmtpClient();
if(realClient.CanBe&lt;ISmtpClient&gt;())
    var myClass = new ClassNeedingSmtpClient(realClient.AsType&lt;ISmtpClient&gt;());
// and do something else if it doesn't work
</pre>
        <p>
So now lets look at the other usage scenario, wrapping anonymous types in an iterface
so you can pass them around.  The first thing we need is an interface to hold
the data
</p>
        <pre class="brush: csharp" name="code">public interface INamedSomething
{
    string Name { get; }
    int Id { get; }
    string SomethingElse { get; }
}
</pre>
        <p>
Note here that we are only specifying getters. That is because the properties of anonymous
types are read-only, and right now the duhking code doesn't differentiate anonymous
types from other types (more on that later). Ok, so with this we can now create an
anonymous type and return it as an INamedSomething
</p>
        <pre class="brush: csharp" name="code">public INamedSomething MethodThatReturnsSomething()
{
    // Some work goes here
    return new { Name = "Sam", Id = 1234, SomethingElse = "Hah!", SomethingElseNotInTheInterface = "Foo" }.AsType&lt;INamedSomething&gt;();
}
</pre>
        <p>
And this works fine. Notice I threw an extra property in there to show you that when
we are checking for matching signatures we're only checking the methods/properties
in the interface we're trying to Duhk. You can have as many additional properties
or methods as you want in your concrete type, doesn't matter. 
</p>
        <p>
Now, as for that whole read-only thing.  Right now the code that checks compatability
between your class and the target interface is ensuring that each method in the target
interface has a matching method in the class.  This includes the compiler-generated
methods for getting and setting properties.  That means that if your using an
anonymous type as your class, you will never be able to Duhk it to an interface that
has setters on it’s properties.  While <em>technically</em> correct there is
something about this behavior that bugs me…it just doesn’t seem flexible enough. 
So most likely what I am going to do is add some special handling for anonymous types
that will allow the target interface to have both getters an setters.  This will
in effect provide a way to stub out an interface implementation, and use the anonymous
type to set the initial values of the interface.  This does change a bit the
purpose of what I’m trying to do with this library, and gives it the added ability
to stub out interfaces, so I’ve held off on doing this.  I think, though, that
adding this functionality will actually increase the utility of the library, so it’s
probably worth doing. 
</p>
        <p>
Right, so now that you have all of the grueling details, <a href="http://duhking.codeplex.com/" target="_blank">go
get it</a>, and let me know what you think. <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=ef0ceef1-8cf4-4a06-b626-2329ba3cff3a" /></p>
      </body>
      <title>Announcing the Duhking Library for .Net 3.5</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,ef0ceef1-8cf4-4a06-b626-2329ba3cff3a.aspx</guid>
      <link>http://www.drrandom.org/2010/06/17/AnnouncingTheDuhkingLibraryForNet35.aspx</link>
      <pubDate>Thu, 17 Jun 2010 21:46:05 GMT</pubDate>
      <description>&lt;p&gt;
If it walks like a giraffe and talks like a duck then what is it?&amp;nbsp; Maybe a duhk?&amp;nbsp;
Who knows, but it certainly is not a duck.&amp;nbsp; So if that is the case, then you
can probably guess what the Duhking library is all about…or maybe you can’t.&amp;nbsp;
In terms of programming, &lt;a href="http://en.wikipedia.org/wiki/Duck_Typing" target="_blank"&gt;Duck
Typing&lt;/a&gt; refers to the ability of some languages to allow you to treat an object
of one type as an object of a different type, provided the methods/properties needed
exist on both objects.&amp;nbsp; Statically typed languages are usually not very good
at this sort of loosey-goosey type inference, which is why this behavior is typically
restricted to languages with less stringent rules on typing.
&lt;/p&gt;
&lt;p&gt;
The &lt;a href="http://duhking.codeplex.com/" target="_blank"&gt;Duhking library&lt;/a&gt; is
an attempt to provide a very limited view of Duck Typing to .Net 3.5 applications.&amp;nbsp;
It allows you to graft an interface type onto an object that has matching properties
and/or methods but does not actually implement that type.&amp;nbsp; Why would you do that?&amp;nbsp;
Well, there were a couple of use-cases that drove the development of this library.&amp;nbsp;
One is a case where you want to wrap an API that you have no control over in an interface
so that you can test your consuming code.&amp;nbsp; This is common for things like HttpContext
or SmtpClient where you want to utilize the functionality of those libraries in your
code which you work so hard to make testable.&amp;nbsp; A standard approach to doing this
is to create an interface which defines the methods you need, and then create a “wrapper”
class that implements the interface, but then calls through to the real, un-testable
class to do the work.&amp;nbsp; So my thought was this:&amp;nbsp; “Since we’re just calling
through to matching method signatures in a class that already exists, why not abstract
the whole thing so I don’t need all of these crazy &lt;em&gt;Wrapper&lt;/em&gt; classes everywhere?”.
&lt;/p&gt;
&lt;p&gt;
The other use-case came up when dealing with anonymous types.&amp;nbsp; We all know that
you can create basic data objects as an anonymous type, and then use them within the
scope they are created.&amp;nbsp; But what happens if you want to pass an anonymous type
to another method?&amp;nbsp; Well, you have two choices.&amp;nbsp; You can either move the
data in your anonymous type to another class/struct and pass &lt;em&gt;that&lt;/em&gt;, or you
can resort to some reflection trickery to get the values out of a plain old object.&amp;nbsp;
It seemed like you should be able to create a new anonymous object as a particular
interface type, and then pass it around as that interface type.
&lt;/p&gt;
&lt;p&gt;
So the Duhking library allows you to do both fairly easily by use of some simple extension
methods on object, and the magic of the Castle project DynamicProxy2 library.&amp;nbsp;
Now that I’ve told you the secret, surely you can see how things work.&amp;nbsp; The library
simply creates a proxy of the specified interface, and then intercepts calls to the
interface methods, and in-turn calls the matching methods on the object we are “Duhking”.&amp;nbsp;
There is some checking going on to ensure that your object is compatible with the
interface you are wanting to Duhk, which involves checking method signatures (this
is surprisingly complicated, considering it is the basis for compiler based interface
implementation verification….but then I may be doing it the hard way), but beyond
that its just passing calls off to the proxy.&amp;nbsp; But enough idle chit-chat, lets
see a sample.
&lt;/p&gt;
&lt;p&gt;
Okay, so lets take the first use-case where we are wanting a wrapper class for a sealed
framework class so we can test our consumers.&amp;nbsp; Let’s go with the SmtpClient as
an example because it is fairly common to want to send emails for various reasons.
&lt;/p&gt;
&lt;p&gt;
First off we need out wrapper interface:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="brush: csharp" name="code"&gt;public interface ISmtpClient
{
    string Host { get; set; }&lt;br&gt;
int Port { get; set; }&lt;br&gt;
&lt;br&gt;
void Send(string from, string recipients, string subject, string body); } &lt;/pre&gt;
&lt;p&gt;
You could add in additional properties or methods, but this is enough to get you going.&amp;nbsp;
So now you can use this interface in place of the standard SmtpClient in the framework,
and write your tests against it without major pain.&amp;nbsp; So the next step is to Duhk
the real SmtpClient so it implements your interface when your ready to do the “real”
work.
&lt;/p&gt;
&lt;pre class="brush: csharp" name="code"&gt;// Some code here getting ready to call your class that needs the client
var myClass = new ClassNeedingSmtpClient(new SmtpClient().AsType&amp;lt;ISmtpClient&amp;gt;());
// and now you do something with it
&lt;/pre&gt;
&lt;p&gt;
Pretty cool huh?&amp;nbsp; You can also check to see if the given concrete type can be
Duhked by using the CanBe extension method 
&lt;/p&gt;
&lt;pre class="brush: csharp" name="code"&gt;// Some code here getting ready to call your class that needs the client
var realClient = new SmtpClient();
if(realClient.CanBe&amp;lt;ISmtpClient&amp;gt;())
    var myClass = new ClassNeedingSmtpClient(realClient.AsType&amp;lt;ISmtpClient&amp;gt;());
// and do something else if it doesn't work
&lt;/pre&gt;
&lt;p&gt;
So now lets look at the other usage scenario, wrapping anonymous types in an iterface
so you can pass them around.&amp;nbsp; The first thing we need is an interface to hold
the data
&lt;/p&gt;
&lt;pre class="brush: csharp" name="code"&gt;public interface INamedSomething
{
    string Name { get; }
    int Id { get; }
    string SomethingElse { get; }
}
&lt;/pre&gt;
&lt;p&gt;
Note here that we are only specifying getters. That is because the properties of anonymous
types are read-only, and right now the duhking code doesn't differentiate anonymous
types from other types (more on that later). Ok, so with this we can now create an
anonymous type and return it as an INamedSomething
&lt;/p&gt;
&lt;pre class="brush: csharp" name="code"&gt;public INamedSomething MethodThatReturnsSomething()
{
    // Some work goes here
    return new { Name = "Sam", Id = 1234, SomethingElse = "Hah!", SomethingElseNotInTheInterface = "Foo" }.AsType&amp;lt;INamedSomething&amp;gt;();
}
&lt;/pre&gt;
&lt;p&gt;
And this works fine. Notice I threw an extra property in there to show you that when
we are checking for matching signatures we're only checking the methods/properties
in the interface we're trying to Duhk. You can have as many additional properties
or methods as you want in your concrete type, doesn't matter. 
&lt;p&gt;
Now, as for that whole read-only thing.&amp;nbsp; Right now the code that checks compatability
between your class and the target interface is ensuring that each method in the target
interface has a matching method in the class.&amp;nbsp; This includes the compiler-generated
methods for getting and setting properties.&amp;nbsp; That means that if your using an
anonymous type as your class, you will never be able to Duhk it to an interface that
has setters on it’s properties.&amp;nbsp; While &lt;em&gt;technically&lt;/em&gt; correct there is
something about this behavior that bugs me…it just doesn’t seem flexible enough.&amp;nbsp;
So most likely what I am going to do is add some special handling for anonymous types
that will allow the target interface to have both getters an setters.&amp;nbsp; This will
in effect provide a way to stub out an interface implementation, and use the anonymous
type to set the initial values of the interface.&amp;nbsp; This does change a bit the
purpose of what I’m trying to do with this library, and gives it the added ability
to stub out interfaces, so I’ve held off on doing this.&amp;nbsp; I think, though, that
adding this functionality will actually increase the utility of the library, so it’s
probably worth doing. 
&lt;p&gt;
Right, so now that you have all of the grueling details, &lt;a href="http://duhking.codeplex.com/" target="_blank"&gt;go
get it&lt;/a&gt;, and let me know what you think. &lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=ef0ceef1-8cf4-4a06-b626-2329ba3cff3a" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,ef0ceef1-8cf4-4a06-b626-2329ba3cff3a.aspx</comments>
      <category>.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=49ad68e1-3159-4225-ab35-8c1a345429da</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,49ad68e1-3159-4225-ab35-8c1a345429da.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,49ad68e1-3159-4225-ab35-8c1a345429da.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=49ad68e1-3159-4225-ab35-8c1a345429da</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
On November 27th, a beta release of the 9.3 version of the Developer Express components,
including CodeRush and Refactor Pro! was made available to subscribers.  This
release is pretty significant to me because it contains a major feature that I have
been waiting for <a href="http://www.drrandom.org/2007/07/13/TakingTheCodeRushPlunge.aspx" target="_blank">for
a long time</a>: A Unit Test Runner.  There were some teasers released by <a href="http://community.devexpress.com/blogs/markmiller/">Mark
Miller</a> a while back, which only made me want to get my hands on the tool that
much more.  My initial impressions are that it is very nice.  It is similar
to <a href="http://www.testdriven.net">TestDriven.Net</a> in that it provides context
menu options to run tests at various levels of granularity (single test, file, project,
and solution level) and includes a debug option.  At this point it does not contain
some of the additional coolness that TestDriven gives you like NCover/Team Coverage
and TypeMock integration, but it does have the advantage of being extensible. 
I know it was extensible because Mr. Miller <a href="http://community.devexpress.com/blogs/markmiller/archive/2009/11/16/the-test-runner-you-ve-been-waiting-for.aspx">told
me it was extensible</a> (the title “The Extensible Unit Test Runner You’ve Been Waiting
For” was a clue).  I did not realize how extensible, however, until after I submitted
a <a href="http://www.devexpress.com/issue=B142663">bug report</a> to DevExpress. 
The bug I was reporting (the NUnit TestCase attributes were not recognized), it turns
out, was already brought to the attention of the DX team by way of a <a href="http://community.devexpress.com/forums/p/83453/285881.aspx#285881">forum
post</a>, and they had already planned on correcting it with the next 9.3 release,
but I could have saved myself (and Vito on DevExpress team) some time by taking a
peek at the source samples bundled with the 9.3 release.  Yep, you guessed it,
there with a shared source license were all of the test framework implementation projects. 
So this meant I could whip together my own temporary fix while I was waiting for the
next release.  It seemed like something that other folks might want to know about,
so I thought I would share it here.
</p>
        <p>
The biggest piece of the puzzle is a new TestExecuteTask class for handling the TestCaseAttribute. 
Due to my complete lack of creativity, I called mine TestCaseExecuteTask, and it looks
like this: 
</p>
        <pre class="brush: csharp" name="code">using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.CodeRush.Core.Testing;
using System.Reflection;
using DevExpress.CodeRush.Core;

namespace CR_NUnitTesting
{
    public class TestCaseExecuteTask : TestExecuteTask
    {
        public override TaskExecuteResult CollectTestParameters()
        {
            TaskExecuteResult result = TaskExecuteResult.SkippedTaskResult;
            Attribute testCase = GetMethodAttribute("NUnit.Framework.TestCaseAttribute");
            if (testCase == null)
                return result;
            
            foreach(Attribute testCaseItem in TestMethod.GetCustomAttributes(true))
            {
                if(testCaseItem == null)
                    continue;
                var testCaseType = testCaseItem.GetType();
                if(testCaseType == null || testCaseType.FullName != "NUnit.Framework.TestCaseAttribute")
                    continue;
                PropertyInfo prop = testCaseType.GetProperty("Arguments");
                if(prop == null)
                    continue;
                foreach(MethodInfo getter in prop.GetAccessors())
                {
                    object[] parameters = getter.Invoke(testCaseItem, Type.EmptyTypes) as object[];
                    result.AddParameters(parameters);
                }
            }
        }
    }
}
</pre>
        <p>
This could be cleaned up some, and some of the magic strings extracted to constants,
but overall it is pretty simple. Basically what is going on here is that we are looking
for the TestCase attribute, and extracting the arguments for any attributes we find. 
It just so happens that the TestExecuteTask base class has a CollectTestParameters()
method we can override which allows for this sort of Row testing.  The parameters
we extract get stashed in the execution result, which causes the test runner to execute
the test once for each group of parameters (the result has a list of parameters, which
gets populated with an array of objects for each TestCase attribute), and will correctly
display which cases failed if there is a failure.
</p>
        <p>
There are a couple other small changes that need to happen to get this to work. 
There is an NUnitExtension.cs  class, which is the Plug-In class for the NUnit
support, and it handles wiring everything up for us.  First off we need to initialize
our new TestExecuteTask, and add it to the list of tasks that run for NUnit tests. 
We do that in the InitializePlugin method of the NUnitExtension class: 
</p>
        <pre class="brush: csharp">public override void InitializePlugin()
{
    base.InitializePlugin();
    nUnitProvider.AvailableTasks.Add(new NUnitIgnoreTask());
    nUnitProvider.AvailableTasks.Add(new NUnitSetupTearDownTask());
    nUnitProvider.AvailableTasks.Add(new NUnitExpectedExceptionTask());
    nUnitProvider.AvailableTasks.Add(new NUnitValuesTask());
    nUnitProvider.AvailableTasks.Add(new NUnitRowTestTask());
    nUnitProvider.AvailableTasks.Add(new NUnitTimeoutTask());
    nUnitProvider.AvailableTasks.Add(new NUnitExplicitTask());
    nUnitProvider.AvailableTasks.Add(new NUnitTestCaseTask());
}
</pre>Ours
gets added to the end of the list, so it will be executed. The next step is to get
the plug-in to realize that a method with a TestCase attribute is an executable test
method. That trick happens in the handler for the CheckTestMethod event on the UnitTestProvider.
All we're going to do is add another condition to an if statement like so: <pre class="brush: csharp">void nUnitProvider_CheckTestMethod(object sender, CheckTestMethodEventArgs ea)
{
    IMethodElement method = ea.Method;
    if(//method.Name != null &amp;&amp; method.Name.StartsWith("Test")
       ea.GetAttribute("NUnit.Framework", "Test", method) != null
    || ea.GetAttribute("NUnit.Framework.Extensions", "RowTest", method) != null
    || ea.GetAttribute("NUnit.Framework", "TestCase", method) != null)
    {
        ea.IsTestMethod = true;
        ea.Description = ea.GetAttributeText("NUnit.Framework", "Description", method);
        ea.Category = ea.GetAttributeText("NUnit.Framework", "Category", method);
    }
}
</pre><p>
The only change to the original code was the additional GetAttribute call at the end
of the if statement (the comments were there when I got there, I swear).  Now
the only thing left to do is to compile it and drop it in the plug-ins directory. 
Now when you are looking at a test class, you should be able to run TestCase decorated
test methods without problem.  Well, almost.  There is one thing I was not
able to find a clean way to implement, and that is the Result property of the TestCase
attribute.  This allows you to streamline tests which are doing equals assertions
by having the test method return the actual result, and you specify the expected result
by using the result property.  Unfortunately I could not find a way to hook into
the actual execution of the test in such a way that I could have access to the specific
test properties being used, and the result of the test method execution.  But
considering the DevExpress folks will be fixing this issue, I’m sure when they release
it there will be support for this feature.  After all, this is simply a stop-gap
solution until the next CodeRush release is available, so I’m willing to live with
this slight inconvenience.
</p><p>
Happy Testing!   
</p><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=49ad68e1-3159-4225-ab35-8c1a345429da" /></body>
      <title>More CodeRush Awesomeness</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,49ad68e1-3159-4225-ab35-8c1a345429da.aspx</guid>
      <link>http://www.drrandom.org/2009/12/15/MoreCodeRushAwesomeness.aspx</link>
      <pubDate>Tue, 15 Dec 2009 15:08:44 GMT</pubDate>
      <description>&lt;p&gt;
On November 27th, a beta release of the 9.3 version of the Developer Express components,
including CodeRush and Refactor Pro! was made available to subscribers.&amp;nbsp; This
release is pretty significant to me because it contains a major feature that I have
been waiting for &lt;a href="http://www.drrandom.org/2007/07/13/TakingTheCodeRushPlunge.aspx" target="_blank"&gt;for
a long time&lt;/a&gt;: A Unit Test Runner.&amp;nbsp; There were some teasers released by &lt;a href="http://community.devexpress.com/blogs/markmiller/"&gt;Mark
Miller&lt;/a&gt; a while back, which only made me want to get my hands on the tool that
much more.&amp;nbsp; My initial impressions are that it is very nice.&amp;nbsp; It is similar
to &lt;a href="http://www.testdriven.net"&gt;TestDriven.Net&lt;/a&gt; in that it provides context
menu options to run tests at various levels of granularity (single test, file, project,
and solution level) and includes a debug option.&amp;nbsp; At this point it does not contain
some of the additional coolness that TestDriven gives you like NCover/Team Coverage
and TypeMock integration, but it does have the advantage of being extensible.&amp;nbsp;
I know it was extensible because Mr. Miller &lt;a href="http://community.devexpress.com/blogs/markmiller/archive/2009/11/16/the-test-runner-you-ve-been-waiting-for.aspx"&gt;told
me it was extensible&lt;/a&gt; (the title “The Extensible Unit Test Runner You’ve Been Waiting
For” was a clue).&amp;nbsp; I did not realize how extensible, however, until after I submitted
a &lt;a href="http://www.devexpress.com/issue=B142663"&gt;bug report&lt;/a&gt; to DevExpress.&amp;nbsp;
The bug I was reporting (the NUnit TestCase attributes were not recognized), it turns
out, was already brought to the attention of the DX team by way of a &lt;a href="http://community.devexpress.com/forums/p/83453/285881.aspx#285881"&gt;forum
post&lt;/a&gt;, and they had already planned on correcting it with the next 9.3 release,
but I could have saved myself (and Vito on DevExpress team) some time by taking a
peek at the source samples bundled with the 9.3 release.&amp;nbsp; Yep, you guessed it,
there with a shared source license were all of the test framework implementation projects.&amp;nbsp;
So this meant I could whip together my own temporary fix while I was waiting for the
next release.&amp;nbsp; It seemed like something that other folks might want to know about,
so I thought I would share it here.
&lt;/p&gt;
&lt;p&gt;
The biggest piece of the puzzle is a new TestExecuteTask class for handling the TestCaseAttribute.&amp;nbsp;
Due to my complete lack of creativity, I called mine TestCaseExecuteTask, and it looks
like this: &lt;pre class="brush: csharp" name="code"&gt;using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.CodeRush.Core.Testing;
using System.Reflection;
using DevExpress.CodeRush.Core;

namespace CR_NUnitTesting
{
    public class TestCaseExecuteTask : TestExecuteTask
    {
        public override TaskExecuteResult CollectTestParameters()
        {
            TaskExecuteResult result = TaskExecuteResult.SkippedTaskResult;
            Attribute testCase = GetMethodAttribute("NUnit.Framework.TestCaseAttribute");
            if (testCase == null)
                return result;
            
            foreach(Attribute testCaseItem in TestMethod.GetCustomAttributes(true))
            {
                if(testCaseItem == null)
                    continue;
                var testCaseType = testCaseItem.GetType();
                if(testCaseType == null || testCaseType.FullName != "NUnit.Framework.TestCaseAttribute")
                    continue;
                PropertyInfo prop = testCaseType.GetProperty("Arguments");
                if(prop == null)
                    continue;
                foreach(MethodInfo getter in prop.GetAccessors())
                {
                    object[] parameters = getter.Invoke(testCaseItem, Type.EmptyTypes) as object[];
                    result.AddParameters(parameters);
                }
            }
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;
This could be cleaned up some, and some of the magic strings extracted to constants,
but overall it is pretty simple. Basically what is going on here is that we are looking
for the TestCase attribute, and extracting the arguments for any attributes we find.&amp;nbsp;
It just so happens that the TestExecuteTask base class has a CollectTestParameters()
method we can override which allows for this sort of Row testing.&amp;nbsp; The parameters
we extract get stashed in the execution result, which causes the test runner to execute
the test once for each group of parameters (the result has a list of parameters, which
gets populated with an array of objects for each TestCase attribute), and will correctly
display which cases failed if there is a failure.
&lt;/p&gt;
&lt;p&gt;
There are a couple other small changes that need to happen to get this to work.&amp;nbsp;
There is an NUnitExtension.cs&amp;nbsp; class, which is the Plug-In class for the NUnit
support, and it handles wiring everything up for us.&amp;nbsp; First off we need to initialize
our new TestExecuteTask, and add it to the list of tasks that run for NUnit tests.&amp;nbsp;
We do that in the InitializePlugin method of the NUnitExtension class: &lt;pre class="brush: csharp"&gt;public override void InitializePlugin()
{
    base.InitializePlugin();
    nUnitProvider.AvailableTasks.Add(new NUnitIgnoreTask());
    nUnitProvider.AvailableTasks.Add(new NUnitSetupTearDownTask());
    nUnitProvider.AvailableTasks.Add(new NUnitExpectedExceptionTask());
    nUnitProvider.AvailableTasks.Add(new NUnitValuesTask());
    nUnitProvider.AvailableTasks.Add(new NUnitRowTestTask());
    nUnitProvider.AvailableTasks.Add(new NUnitTimeoutTask());
    nUnitProvider.AvailableTasks.Add(new NUnitExplicitTask());
    nUnitProvider.AvailableTasks.Add(new NUnitTestCaseTask());
}
&lt;/pre&gt;Ours
gets added to the end of the list, so it will be executed. The next step is to get
the plug-in to realize that a method with a TestCase attribute is an executable test
method. That trick happens in the handler for the CheckTestMethod event on the UnitTestProvider.
All we're going to do is add another condition to an if statement like so: &lt;pre class="brush: csharp"&gt;void nUnitProvider_CheckTestMethod(object sender, CheckTestMethodEventArgs ea)
{
    IMethodElement method = ea.Method;
    if(//method.Name != null &amp;amp;&amp;amp; method.Name.StartsWith("Test")
       ea.GetAttribute("NUnit.Framework", "Test", method) != null
    || ea.GetAttribute("NUnit.Framework.Extensions", "RowTest", method) != null
    || ea.GetAttribute("NUnit.Framework", "TestCase", method) != null)
    {
        ea.IsTestMethod = true;
        ea.Description = ea.GetAttributeText("NUnit.Framework", "Description", method);
        ea.Category = ea.GetAttributeText("NUnit.Framework", "Category", method);
    }
}
&lt;/pre&gt;
&lt;p&gt;
The only change to the original code was the additional GetAttribute call at the end
of the if statement (the comments were there when I got there, I swear).&amp;nbsp; Now
the only thing left to do is to compile it and drop it in the plug-ins directory.&amp;nbsp;
Now when you are looking at a test class, you should be able to run TestCase decorated
test methods without problem.&amp;nbsp; Well, almost.&amp;nbsp; There is one thing I was not
able to find a clean way to implement, and that is the Result property of the TestCase
attribute.&amp;nbsp; This allows you to streamline tests which are doing equals assertions
by having the test method return the actual result, and you specify the expected result
by using the result property.&amp;nbsp; Unfortunately I could not find a way to hook into
the actual execution of the test in such a way that I could have access to the specific
test properties being used, and the result of the test method execution.&amp;nbsp; But
considering the DevExpress folks will be fixing this issue, I’m sure when they release
it there will be support for this feature.&amp;nbsp; After all, this is simply a stop-gap
solution until the next CodeRush release is available, so I’m willing to live with
this slight inconvenience.
&lt;/p&gt;
&lt;p&gt;
Happy Testing!&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=49ad68e1-3159-4225-ab35-8c1a345429da" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,49ad68e1-3159-4225-ab35-8c1a345429da.aspx</comments>
      <category>.Net</category>
      <category>C#</category>
      <category>CodeRush</category>
      <category>DxCore</category>
      <category>TDD</category>
      <category>tips</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=ae83bded-50a9-4c93-85da-78a0da965f14</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,ae83bded-50a9-4c93-85da-78a0da965f14.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,ae83bded-50a9-4c93-85da-78a0da965f14.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=ae83bded-50a9-4c93-85da-78a0da965f14</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As of right about now, you should be able to mosey on over to the <a href="http://code.google.com/p/dxcorecommunityplugins/" target="_blank">DxCore
Community Plug-ins page</a>, and grab a copy of <a href="http://code.google.com/p/dxcorecommunityplugins/wiki/CR_MoveFile" target="_blank">CR_MoveFile</a>. 
This is a plug-in I created primarily as a tool to aid in working in a TDD environment,
but which certainly has uses for non-TDD applications.  It does basically what <a href="http://www.drrandom.org/content/binary/WindowsLiveWriter/AnnouncingCR_MoveFileDxCorepluginformovi_8466/CR_MoveFile_ScreenShot_5.png"><img style="border-right-width: 0px; margin: 10px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CR_MoveFile_ScreenShot" border="0" alt="CR_MoveFile_ScreenShot" align="right" src="http://www.drrandom.org/content/binary/WindowsLiveWriter/AnnouncingCR_MoveFileDxCorepluginformovi_8466/CR_MoveFile_ScreenShot_thumb_1.png" width="660" height="439" /></a>the
name suggests, it allows you to move a file from one directory in your solution/project
structure to another, even one in a different project.  I implemented this as
a code provider (since it could change the functionality if you move the file from
one project to another), so it will appear in the Code menu when you have the cursor
somewhere within the beginning blocks of a file (“using” sections, namespace declaration,
or class/interface/struct declarations).  Once selected you are presented with
a popup window which has a tree that represents your current solution structure, with
your current directory highlighted.  You can use the arrow keys to navigate the
directories and choose a new home for your file.
</p>
        <p>
If you move files between projects, the plug-in will create project references for
you, so you don’t need to worry about that.  When the file is moved the file
contents remain unchanged, so all namespaces will be the same as they were originally. 
I did this mostly to keep the plug-in simple, but also because I could see situations
where this would be good, and situations where this would be bad, and it seemed like
this was a bad choice to make for people.  I’ve been using this plug-in on a
day-to-day basis for a while now, and things seem pretty clean, I did run into a small
issue, however, using it within a solution that was under source control.  At
this point you need to make sure the project files effected by the move are checked
out, otherwise the plug-in goes through the motions, but doesn’t actually do anything,
which is quite annoying.  There is also no checking going on to make sure the
language is the same between the source and target project, so if you work on a solution
that contains C# <strong>and</strong> VB.Net projects, you have to be careful not
to move files around to projects that can’t understand what they are (oh, and the
project icons used on the tree view are all the same, so there is no visual indication
of what project contains what type of files).
</p>
        <p>
That’s pretty much it.  Clean, simple, basic.  Used with other existing
CodeRush/Refactor tools like “Move Type To File” and “Move to Namespace”, this provides
for some pretty powerful code re-organization.  Just make sure you run all of
your tests :).
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=ae83bded-50a9-4c93-85da-78a0da965f14" />
      </body>
      <title>Announcing CR_MoveFile: DxCore plug-in for moving files around in a solution</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,ae83bded-50a9-4c93-85da-78a0da965f14.aspx</guid>
      <link>http://www.drrandom.org/2009/12/07/AnnouncingCRMoveFileDxCorePluginForMovingFilesAroundInASolution.aspx</link>
      <pubDate>Mon, 07 Dec 2009 19:17:46 GMT</pubDate>
      <description>&lt;p&gt;
As of right about now, you should be able to mosey on over to the &lt;a href="http://code.google.com/p/dxcorecommunityplugins/" target="_blank"&gt;DxCore
Community Plug-ins page&lt;/a&gt;, and grab a copy of &lt;a href="http://code.google.com/p/dxcorecommunityplugins/wiki/CR_MoveFile" target="_blank"&gt;CR_MoveFile&lt;/a&gt;.&amp;nbsp;
This is a plug-in I created primarily as a tool to aid in working in a TDD environment,
but which certainly has uses for non-TDD applications.&amp;nbsp; It does basically what &lt;a href="http://www.drrandom.org/content/binary/WindowsLiveWriter/AnnouncingCR_MoveFileDxCorepluginformovi_8466/CR_MoveFile_ScreenShot_5.png"&gt;&lt;img style="border-right-width: 0px; margin: 10px 0px 0px 20px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="CR_MoveFile_ScreenShot" border="0" alt="CR_MoveFile_ScreenShot" align="right" src="http://www.drrandom.org/content/binary/WindowsLiveWriter/AnnouncingCR_MoveFileDxCorepluginformovi_8466/CR_MoveFile_ScreenShot_thumb_1.png" width="660" height="439"&gt;&lt;/a&gt;the
name suggests, it allows you to move a file from one directory in your solution/project
structure to another, even one in a different project.&amp;nbsp; I implemented this as
a code provider (since it could change the functionality if you move the file from
one project to another), so it will appear in the Code menu when you have the cursor
somewhere within the beginning blocks of a file (“using” sections, namespace declaration,
or class/interface/struct declarations).&amp;nbsp; Once selected you are presented with
a popup window which has a tree that represents your current solution structure, with
your current directory highlighted.&amp;nbsp; You can use the arrow keys to navigate the
directories and choose a new home for your file.
&lt;/p&gt;
&lt;p&gt;
If you move files between projects, the plug-in will create project references for
you, so you don’t need to worry about that.&amp;nbsp; When the file is moved the file
contents remain unchanged, so all namespaces will be the same as they were originally.&amp;nbsp;
I did this mostly to keep the plug-in simple, but also because I could see situations
where this would be good, and situations where this would be bad, and it seemed like
this was a bad choice to make for people.&amp;nbsp; I’ve been using this plug-in on a
day-to-day basis for a while now, and things seem pretty clean, I did run into a small
issue, however, using it within a solution that was under source control.&amp;nbsp; At
this point you need to make sure the project files effected by the move are checked
out, otherwise the plug-in goes through the motions, but doesn’t actually do anything,
which is quite annoying.&amp;nbsp; There is also no checking going on to make sure the
language is the same between the source and target project, so if you work on a solution
that contains C# &lt;strong&gt;and&lt;/strong&gt; VB.Net projects, you have to be careful not
to move files around to projects that can’t understand what they are (oh, and the
project icons used on the tree view are all the same, so there is no visual indication
of what project contains what type of files).
&lt;/p&gt;
&lt;p&gt;
That’s pretty much it.&amp;nbsp; Clean, simple, basic.&amp;nbsp; Used with other existing
CodeRush/Refactor tools like “Move Type To File” and “Move to Namespace”, this provides
for some pretty powerful code re-organization.&amp;nbsp; Just make sure you run all of
your tests :).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=ae83bded-50a9-4c93-85da-78a0da965f14" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,ae83bded-50a9-4c93-85da-78a0da965f14.aspx</comments>
      <category>.Net</category>
      <category>C#</category>
      <category>CodeRush</category>
      <category>DxCore</category>
      <category>TDD</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=7bb82e3b-a7d0-4fa5-9ac1-0f8e4261ed11</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,7bb82e3b-a7d0-4fa5-9ac1-0f8e4261ed11.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,7bb82e3b-a7d0-4fa5-9ac1-0f8e4261ed11.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=7bb82e3b-a7d0-4fa5-9ac1-0f8e4261ed11</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Anyone who has been around me for more than a few hours while coding, or who pays
any attention to me on <a href="http://www.twitter.com/drrandom">Twitter</a> will
know that I am a huge fan of <a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/">CodeRush
and Refactor Pro!</a> from <a href="http://www.devexpress.com">DevExpress</a>. 
I consider these sorts of tools essential to getting the most out of your development
environment, and I think CodeRush is one of the best tools available for a number
of reasons, not the least of which is it’s extensibility.  CodeRush is built
on top of <a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/DXCore/">DxCore</a>,
which is a freely available library for building Visual Studio plug-ins (incidentally,
DevExpress also have a free version of CodeRush called <a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/">CodeRush
XPress</a>, which is built on the same platform).  DxCore provides any developer
who wants it access to the same tools that the folks at DevExpress have for building
plug-ins and extensions on top of VisualStudio, and several developers (including
yours truly) have <a href="http://code.google.com/p/dxcorecommunityplugins/">done
just that</a>.
</p>
        <p>
One of the more recent additions to the CodeRush arsenal are the CodeIssues. 
As of the v9 release, CodeRush included an extensive collection of these mini code
analyzers which will look at your code in real time and do everything from let you
know when you have undisposed resources, to suggesting alternate language features
you may not even be aware of.  A lot of these are also tied in to the refactoring
and code generation tools that already exist within CodeRush and Refactor Pro! so
that not only do you see that there is an issue or suggestion, but in a lot of cases
you can tell the tool to correct it for you.  Pretty impressive stuff.
</p>
        <p>
So what I would like to do is dig in to how the CodeIssue functionality works within
CodeRush by creating a custom CodeIssue Provider.  Because I’m a TDD guy, one
of the things I’ve been trying to do is build in some tooling around the TDD process
to make it that much easier to write code TDD.  So based on that I’m going to
show you how to implement a CodeRush CodeIssueProvider which will generate a warning
whenever you have created a Unit Test method with no assertions (which would indicate
that you are either dealing with an Integration Test, or your test is not correctly
factored).  <strong>Note:</strong> Since the CodeIssue UI elements are part of
the full CodeRush product, and not CodeRush XPress, this plug-in will note do anything
unless you are running the full version of CodeRush.
</p>
        <p>
Okay, so the first thing to do is to create a new Plug-In project.  This can
either be done from the Visual Studio File –&gt; New Project menu, or by selecting
the New Plug-in option from the DevExpress menu in visual studio (if you are using
CodeRush XPress and you don’t have the DevExpress menu, my man Rory Becker has a solution
for you).  Regardless of which way you go, you will get a “New DxCore Plug-in
Project” window, which will ask you what Language you want to write your plug-in in
(C# or Visual Basic .Net), and what kind of plug-in you want, along with the standard
stuff about what to name the solution and where to store the files.  For our
purposes we’re going to go with C# as the Language, a Standard Plug-in, and we’ll
call it CR_TestShouldAssert (the CR_ is a naming convention used by the CodeRush team
to indicate it’s a CodeRush plug-in, as opposed to a Refactoring or DxCore plug-in).
</p>
        <p>
          <a href="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_2.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_thumb.png" width="745" height="393" />
          </a>
        </p>
        <p>
Net up is the “DxCore Plug-in Project Settings” dialog.  This allows you to give
your plug-in a title, and set some more advanced options which deal with how the plug-in
gets loaded by the DxCore framework.  We’ll just leave everything as-is and move
on to the good stuff.
</p>
        <p>
          <a href="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_4.png">
            <img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_thumb_1.png" width="401" height="255" />
          </a>
        </p>
        <p>
Once your project loads you will be presented with a design surface, this is because
a large number of the components that are available via DXCore can actually be found
in the Visual Studio toolbox, and you can just drag them out onto your plug-in designer
to get started.  The CodeIssueProvider is an exception, though, so we will have
to crack open the designer file to add it to our plug-in.  So open up the PlugIn1.designer.cs
file, and add the following line of code under the “Windows Form Designer Generated
Code” section:
</p>
        <pre class="brush: csharp" name="code">CodeIssueProvider cipTestsShouldAssert;</pre>You'll
need to add a using statement for the DevExpress.CodeRush.Core namespace as well. 
Next we need to instantiate it, so we need to do this in the the InitializeComponents
method.  When you are finished your InitializeComponents method should look like
this:<pre class="brush: csharp" name="code">this.components = new System.ComponentModel.Container();
cipTestsShouldAssert = new CodeIssueProvider(this.components);
((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this)).EndInit();</pre><p>
Now if we switch back over to the designer, we will see our new provider on the design
surface.  At this point we can use the Properties window to configure the provider. 
The things we need to worry about filling out are the Description, DisplayName, and
ProviderName properties.  The Description is the text that will be displayed
in the Code Issue catalog, so it needs to clearly explain what the CodeIssueProvider
is intended to do.  Let’s go with something like: “A Unit Test should have at
least one explicit or implicit assertion.”  As for DisplayName, lets say something
like “Unit Test Method Should Assert”, and make the ProviderName the same.
</p><p>
Ok, so now it’s time to actually do the work of finding a TestMethod that violates
this condition.  So we need to switch over to the Events list for our provider,
and Double-Click in the CheckCodeIssues drop-down so it generates an event handler
for us.  You will now be taken to the code editor and presented with a empty
handler that looks something like:
</p><pre class="brush: csharp" name="code">private void cipTestsShouldAssert_CheckCodeIssues(object sender, CheckCodeIssuesEventArgs ea)
{

}</pre><p>
This looks pretty much like your normal event handler, we’ve got the sender object
(which would be our provider instance, and then we have a custom EventArgs object.
Looking at this event args object, you can see quite a few methods, and a couple of
properties.  The first few methods you see deal with actually adding your code
issue, if it exists, to the list of issues reported by the UI.  You’ve got one
method for each type of CodeIssue (AddDeadCode, AddError, AddHint, AddSmell,AddWarning),
and then one method (AddIssue), which allows you to specify the CodeIssue Type. 
Now this is where things start to get interesting because basically we’re at the point
where the good folks who wrote DxCore have said “All right, go off and find your problem
and report your finding back to me when your done”.  So from here we have to
figure out whether or not there are any test methods without asserts floating around
anywhere.  The good news is that there are a few tools in the CodeRush bag of
tricks that can help us.
</p><p>
Perhaps the best tool for figuring out this sort of thing is the “Expression Lab”
plug-in.  You can open this up by going to the DevExpress menu, opening the Tool
Windows-&gt;Diagnostics-&gt;Expressions Lab.  This shows you in real time what
the AST that CodeRush produces for your code looks like as you move about in a file. 
You can also see all of the properties associated with the various syntax elements,
and view how things are related.  This is a very handy tool to have.  Before
we dig too deep into the Expressions Lab, lets get a start on finding our CodeIssue. 
We know that we are going to be looking at methods here, since we are ultimately searching
for test methods, so the first thing to do is to limit the scope of our search to
just methods.  The CheckCodeIssues event is fired at a file level, so you are
basically handed an entire file to search by the DxCore framework.  We need to
filter that down a bit and only pay attention to the methods contained in the current
file.  To do that we’re going to use the ResolveScope() method of the CheckCodeIssuesEventArgs
object.  Calling the ResolveScope() method gives us a ScopreResolveResult object,
which doesn’t sound very interesting, but this object has a wonderful little method
on it called GetElementEnumerator().  This method will allow you to pass in a
filter expression, and return all of the elements that match that filter expression
as an enumerable collection. So to get to this, lets add the following to the body
of our event handler:
</p><pre class="brush: csharp" name="code">var resolveScope = ea.ResolveScope();
foreach(IMethodElement method in resolveScope.GetElementEnumerator(ea.Scope,new ElementTypeFilter(LanguageElementType.Method)))
{
}</pre><p>
This looks pretty straightforward, but there are a couple of things I want to point
out. First is the ea.Scope property that we are passing in to the GetElementEnumerable()
method. This is the AST object that represents the top of the parse-tree that we are
going to be searching for code issues in. Typically this is a file-level object, but
I don't know that you can count on that always being the case (changing the parse
settings could potentially effect how much of the code is considered invalid at a
time, and so you could get larger or smaller segments of code).  The other interesting
bit is the ElementTypeFilter().  This allows us to filter the list of AST elements
given to us in our enumerable based on their LangueElementType (LanguageElement is
the base class for syntax elements within the DxCore AST structure.  All nodes
have an ElementType property which exposes a LanguageElementType enum value). In our
case we’re only interested in methods, so we’re using LanguageElementType.Method. 
The result is a collection of all of the methods within our Scope.
</p><p>
Now that we have all of our methods, we need to figure out if they are Test methods. 
To do this we’ll have to look for the existence of an Attribute on the method. 
Taking a look at Expressions Lab, we can see that a Method object has an Attributes
collection associated with it. So we should be able to search the list of attributes
for one with a Name property of “Test”.  Using Linq, we can do this pretty easily
like this:
</p><pre class="brush: csharp" name="code">method.Attributes.OfType&lt;IAttributeElement&gt;().Count(a =&gt; a.Name == "Test")</pre>This
will give a a count of the "Test" attributes on our method. We can put this into an
if statement like so:<pre class="brush: csharp">if(method.Attributes.OfType&lt;IAttributeElement&gt;().Count(a =&gt; a.Name == "Test") &gt; 0)
{
}</pre>A
quick note; I'm using the OfType&lt;T&gt;() method to convert the collection returned
by the Attributes Property into an enumerable of IAttributeElements just as an easy
way of enabling Linq expressions against the collection. Since DxCore is written to
work with all versions of VisualStudio, there really isn't any official Linq support.
As a matter of fact, using the expression we did limits the plug-in to only those
people with .Net Framework 3.5 installed on their development machines. I think that
in this day and age, this is a fairly safe assumption, so I'm not that worried about
it. I would like to point out also, that having this expression in place does not
prevent the plug-in from working with Visual Studio 2005, as long as the 3.5 framework
is installed. 
<p></p><p>
Ok, so now we have a list of methods, and we’re filtering them based on whether or
not they are Test methods (defined by the existence of a Test attribute).  The
next thing to do is look for an Assert statement within the text of our method. 
This is another place where the Expressions Lab proves invaluable.  Looking at
Expressions Lab we discover that our Assert statement is in fact an ElementReferenceExpression
and is a child node of our Method object.  With this knowledge in hand we can
use the FindElementByName method on our Method object to look for an Assert reference:
</p><pre class="brush: csharp">var assert = method.FindChildByName("Assert") as IElementReferenceExpression</pre>Now
all we have to do is test whether or not our assert variable is null, and we know
whether or not this method violates our rule. Once we do that test we can add the
appropriate Code Issue Type to the CodeIssues list using our event args. The last
piece of the puzzle then will look something like this:<pre class="brush: csharp">if(assert == null)
{
    ea.AddIssue(CodeIssueType.CodeSmell,(SourceRange)method.NameRanges[0],"A Test Method should have at least one Assert");
}</pre><p>
With this in place we should now be able to run our project and try it out. Using
F5 to debug a DxCore plug-in will launch a new instance of Visual Studio. From there
if you create a new project, or open an existing project, and write a test method
which does not have an Assert, you should see a red squiggle underneath the name of
the method. Hovering over that with your mouse you'll see our Code Issue test presented.
Adding an Assert will make the Code Issue disappear.
</p><p><a href="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_thumb_2.png" width="498" height="136" /></a></p><p>
Well, things are looking good here, we’ve got code that is searching for an issue,
and displaying the appropriate warning if our condition is met.  There is one
other condition we should probably consider, however.  The one case I can think
of when our rule does not apply is when we are expecting the code under test to throw
an exception.  In that case there would be an ExpectedException attribute on
the test class.  To make our users happy we should probably implement this functionality.
</p><p>
The good news is we already know how to accomplish this, since we are using the same
technique to determine if the method we’re looking at is a test method.  All
we need to do is change the test condition in our Count() method so it looks for “ExpectedException”
instead of “Test”.  While we’re at it it seems like a reasonable thing to get
an instance of the attribute and then check it for null, similar to how we’re handling
the assert.  With all of this done the code should look like this:
</p><pre class="brush: csharp">var assert = method.FindChildByName("Assert") as IElementReferenceExpression;
var expectedException = method.Attributes.OfType&lt;IAttributeElement&gt;().FirstOrDefault(a =&gt; a.Name == "ExpectedException");
if (assert == null &amp;&amp; expectedException == null)
{
    ea.AddIssue(CodeIssueType.CodeSmell, (SourceRange)method.NameRanges[0], "A Test Method should have at least one implicit or explicit Assertion");
}</pre>So
now we should be able to run this, and see that the code issue disappears if we have
a test method with either an assert statement, or an expected exception attribute.
Pretty cool. You’ll notice that I also updated our issue message so it reflects the
fact that we are able to handle implicit assertions (in the form of our ExpectedException)
attribute.  For the sake of completeness, here is what our finished CheckCodeIssues
method looks like:<pre class="brush: csharp">private void cipTestShouldAssert_CheckCodeIssues(object sender, CheckCodeIssuesEventArgs ea)
{
    var resolveScope = ea.ResolveScope();
    foreach (IMethodElement method in resolveScope.GetElementEnumerator(ea.Scope, new ElementTypeFilter(LanguageElementType.Method)))
    {
        if (method.Attributes.OfType&lt;IAttributeElement&gt;().Count(a =&gt; a.Name == "Test") &gt; 0)
        {
            var assert = method.FindChildByName("Assert") as IElementReferenceExpression;
            var expectedException = method.Attributes.OfType&lt;IAttributeElement&gt;().FirstOrDefault(a =&gt; a.Name == "ExpectedException");
            if (assert == null &amp;&amp; expectedException == null)
            {
                ea.AddIssue(CodeIssueType.CodeSmell, (SourceRange)method.NameRanges[0], "A Test Method should have at least one implicit or explicit Assertion");
            }
        }
    }
}</pre><p>
And that's it. Granted there are some things here I would like to change before releasing
this into the wild. We are specifically looking for NUnit/MbUnit style test method
declarations for one, and we are also looking only for the short version of the attribute
names, but this should give you a good idea of how things work. 
</p><p>
If you are interested in seeing a more polished final version, you can either download
the <a href="http://www.drrandom.org/downloads/CR_TestShouldAssert.zip">finished source
for this post</a>, or have a look at my <a href="http://code.google.com/p/dxcorecommunityplugins/wiki/CR_CreateTestMethod">CR_CreateTestMethod</a> (admittedly
poorly named) plug-in on the <a href="http://code.google.com/p/dxcorecommunityplugins/">DxCore
Community Plug-In's site</a>.
</p><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=7bb82e3b-a7d0-4fa5-9ac1-0f8e4261ed11" /></body>
      <title>Getting a CodeRush: Inside a CodeRush CodeIssue</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,7bb82e3b-a7d0-4fa5-9ac1-0f8e4261ed11.aspx</guid>
      <link>http://www.drrandom.org/2009/10/07/GettingACodeRushInsideACodeRushCodeIssue.aspx</link>
      <pubDate>Wed, 07 Oct 2009 17:22:35 GMT</pubDate>
      <description>&lt;p&gt;
Anyone who has been around me for more than a few hours while coding, or who pays
any attention to me on &lt;a href="http://www.twitter.com/drrandom"&gt;Twitter&lt;/a&gt; will
know that I am a huge fan of &lt;a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/Coding_Assistance/"&gt;CodeRush
and Refactor Pro!&lt;/a&gt; from &lt;a href="http://www.devexpress.com"&gt;DevExpress&lt;/a&gt;.&amp;nbsp;
I consider these sorts of tools essential to getting the most out of your development
environment, and I think CodeRush is one of the best tools available for a number
of reasons, not the least of which is it’s extensibility.&amp;nbsp; CodeRush is built
on top of &lt;a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/DXCore/"&gt;DxCore&lt;/a&gt;,
which is a freely available library for building Visual Studio plug-ins (incidentally,
DevExpress also have a free version of CodeRush called &lt;a href="http://www.devexpress.com/Products/Visual_Studio_Add-in/CodeRushX/"&gt;CodeRush
XPress&lt;/a&gt;, which is built on the same platform).&amp;nbsp; DxCore provides any developer
who wants it access to the same tools that the folks at DevExpress have for building
plug-ins and extensions on top of VisualStudio, and several developers (including
yours truly) have &lt;a href="http://code.google.com/p/dxcorecommunityplugins/"&gt;done
just that&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
One of the more recent additions to the CodeRush arsenal are the CodeIssues.&amp;nbsp;
As of the v9 release, CodeRush included an extensive collection of these mini code
analyzers which will look at your code in real time and do everything from let you
know when you have undisposed resources, to suggesting alternate language features
you may not even be aware of.&amp;nbsp; A lot of these are also tied in to the refactoring
and code generation tools that already exist within CodeRush and Refactor Pro! so
that not only do you see that there is an issue or suggestion, but in a lot of cases
you can tell the tool to correct it for you.&amp;nbsp; Pretty impressive stuff.
&lt;/p&gt;
&lt;p&gt;
So what I would like to do is dig in to how the CodeIssue functionality works within
CodeRush by creating a custom CodeIssue Provider.&amp;nbsp; Because I’m a TDD guy, one
of the things I’ve been trying to do is build in some tooling around the TDD process
to make it that much easier to write code TDD.&amp;nbsp; So based on that I’m going to
show you how to implement a CodeRush CodeIssueProvider which will generate a warning
whenever you have created a Unit Test method with no assertions (which would indicate
that you are either dealing with an Integration Test, or your test is not correctly
factored).&amp;nbsp; &lt;strong&gt;Note:&lt;/strong&gt; Since the CodeIssue UI elements are part of
the full CodeRush product, and not CodeRush XPress, this plug-in will note do anything
unless you are running the full version of CodeRush.
&lt;/p&gt;
&lt;p&gt;
Okay, so the first thing to do is to create a new Plug-In project.&amp;nbsp; This can
either be done from the Visual Studio File –&amp;gt; New Project menu, or by selecting
the New Plug-in option from the DevExpress menu in visual studio (if you are using
CodeRush XPress and you don’t have the DevExpress menu, my man Rory Becker has a solution
for you).&amp;nbsp; Regardless of which way you go, you will get a “New DxCore Plug-in
Project” window, which will ask you what Language you want to write your plug-in in
(C# or Visual Basic .Net), and what kind of plug-in you want, along with the standard
stuff about what to name the solution and where to store the files.&amp;nbsp; For our
purposes we’re going to go with C# as the Language, a Standard Plug-in, and we’ll
call it CR_TestShouldAssert (the CR_ is a naming convention used by the CodeRush team
to indicate it’s a CodeRush plug-in, as opposed to a Refactoring or DxCore plug-in).
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_thumb.png" width="745" height="393"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Net up is the “DxCore Plug-in Project Settings” dialog.&amp;nbsp; This allows you to give
your plug-in a title, and set some more advanced options which deal with how the plug-in
gets loaded by the DxCore framework.&amp;nbsp; We’ll just leave everything as-is and move
on to the good stuff.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_thumb_1.png" width="401" height="255"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Once your project loads you will be presented with a design surface, this is because
a large number of the components that are available via DXCore can actually be found
in the Visual Studio toolbox, and you can just drag them out onto your plug-in designer
to get started.&amp;nbsp; The CodeIssueProvider is an exception, though, so we will have
to crack open the designer file to add it to our plug-in.&amp;nbsp; So open up the PlugIn1.designer.cs
file, and add the following line of code under the “Windows Form Designer Generated
Code” section:&lt;pre class="brush: csharp" name="code"&gt;CodeIssueProvider cipTestsShouldAssert;&lt;/pre&gt;You'll
need to add a using statement for the DevExpress.CodeRush.Core namespace as well.&amp;nbsp;
Next we need to instantiate it, so we need to do this in the the InitializeComponents
method.&amp;nbsp; When you are finished your InitializeComponents method should look like
this:&lt;pre class="brush: csharp" name="code"&gt;this.components = new System.ComponentModel.Container();
cipTestsShouldAssert = new CodeIssueProvider(this.components);
((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this)).EndInit();&lt;/pre&gt;
&lt;p&gt;
Now if we switch back over to the designer, we will see our new provider on the design
surface.&amp;nbsp; At this point we can use the Properties window to configure the provider.&amp;nbsp;
The things we need to worry about filling out are the Description, DisplayName, and
ProviderName properties.&amp;nbsp; The Description is the text that will be displayed
in the Code Issue catalog, so it needs to clearly explain what the CodeIssueProvider
is intended to do.&amp;nbsp; Let’s go with something like: “A Unit Test should have at
least one explicit or implicit assertion.”&amp;nbsp; As for DisplayName, lets say something
like “Unit Test Method Should Assert”, and make the ProviderName the same.
&lt;/p&gt;
&lt;p&gt;
Ok, so now it’s time to actually do the work of finding a TestMethod that violates
this condition.&amp;nbsp; So we need to switch over to the Events list for our provider,
and Double-Click in the CheckCodeIssues drop-down so it generates an event handler
for us.&amp;nbsp; You will now be taken to the code editor and presented with a empty
handler that looks something like:&lt;pre class="brush: csharp" name="code"&gt;private void cipTestsShouldAssert_CheckCodeIssues(object sender, CheckCodeIssuesEventArgs ea)
{

}&lt;/pre&gt;
&lt;p&gt;
This looks pretty much like your normal event handler, we’ve got the sender object
(which would be our provider instance, and then we have a custom EventArgs object.
Looking at this event args object, you can see quite a few methods, and a couple of
properties.&amp;nbsp; The first few methods you see deal with actually adding your code
issue, if it exists, to the list of issues reported by the UI.&amp;nbsp; You’ve got one
method for each type of CodeIssue (AddDeadCode, AddError, AddHint, AddSmell,AddWarning),
and then one method (AddIssue), which allows you to specify the CodeIssue Type.&amp;nbsp;
Now this is where things start to get interesting because basically we’re at the point
where the good folks who wrote DxCore have said “All right, go off and find your problem
and report your finding back to me when your done”.&amp;nbsp; So from here we have to
figure out whether or not there are any test methods without asserts floating around
anywhere.&amp;nbsp; The good news is that there are a few tools in the CodeRush bag of
tricks that can help us.
&lt;/p&gt;
&lt;p&gt;
Perhaps the best tool for figuring out this sort of thing is the “Expression Lab”
plug-in.&amp;nbsp; You can open this up by going to the DevExpress menu, opening the Tool
Windows-&amp;gt;Diagnostics-&amp;gt;Expressions Lab.&amp;nbsp; This shows you in real time what
the AST that CodeRush produces for your code looks like as you move about in a file.&amp;nbsp;
You can also see all of the properties associated with the various syntax elements,
and view how things are related.&amp;nbsp; This is a very handy tool to have.&amp;nbsp; Before
we dig too deep into the Expressions Lab, lets get a start on finding our CodeIssue.&amp;nbsp;
We know that we are going to be looking at methods here, since we are ultimately searching
for test methods, so the first thing to do is to limit the scope of our search to
just methods.&amp;nbsp; The CheckCodeIssues event is fired at a file level, so you are
basically handed an entire file to search by the DxCore framework.&amp;nbsp; We need to
filter that down a bit and only pay attention to the methods contained in the current
file.&amp;nbsp; To do that we’re going to use the ResolveScope() method of the CheckCodeIssuesEventArgs
object.&amp;nbsp; Calling the ResolveScope() method gives us a ScopreResolveResult object,
which doesn’t sound very interesting, but this object has a wonderful little method
on it called GetElementEnumerator().&amp;nbsp; This method will allow you to pass in a
filter expression, and return all of the elements that match that filter expression
as an enumerable collection. So to get to this, lets add the following to the body
of our event handler:&lt;pre class="brush: csharp" name="code"&gt;var resolveScope = ea.ResolveScope();
foreach(IMethodElement method in resolveScope.GetElementEnumerator(ea.Scope,new ElementTypeFilter(LanguageElementType.Method)))
{
}&lt;/pre&gt;
&lt;p&gt;
This looks pretty straightforward, but there are a couple of things I want to point
out. First is the ea.Scope property that we are passing in to the GetElementEnumerable()
method. This is the AST object that represents the top of the parse-tree that we are
going to be searching for code issues in. Typically this is a file-level object, but
I don't know that you can count on that always being the case (changing the parse
settings could potentially effect how much of the code is considered invalid at a
time, and so you could get larger or smaller segments of code).&amp;nbsp; The other interesting
bit is the ElementTypeFilter().&amp;nbsp; This allows us to filter the list of AST elements
given to us in our enumerable based on their LangueElementType (LanguageElement is
the base class for syntax elements within the DxCore AST structure.&amp;nbsp; All nodes
have an ElementType property which exposes a LanguageElementType enum value). In our
case we’re only interested in methods, so we’re using LanguageElementType.Method.&amp;nbsp;
The result is a collection of all of the methods within our Scope.
&lt;/p&gt;
&lt;p&gt;
Now that we have all of our methods, we need to figure out if they are Test methods.&amp;nbsp;
To do this we’ll have to look for the existence of an Attribute on the method.&amp;nbsp;
Taking a look at Expressions Lab, we can see that a Method object has an Attributes
collection associated with it. So we should be able to search the list of attributes
for one with a Name property of “Test”.&amp;nbsp; Using Linq, we can do this pretty easily
like this:&lt;pre class="brush: csharp" name="code"&gt;method.Attributes.OfType&amp;lt;IAttributeElement&amp;gt;().Count(a =&amp;gt; a.Name == "Test")&lt;/pre&gt;This
will give a a count of the "Test" attributes on our method. We can put this into an
if statement like so:&lt;pre class="brush: csharp"&gt;if(method.Attributes.OfType&amp;lt;IAttributeElement&amp;gt;().Count(a =&amp;gt; a.Name == "Test") &amp;gt; 0)
{
}&lt;/pre&gt;A
quick note; I'm using the OfType&amp;lt;T&amp;gt;() method to convert the collection returned
by the Attributes Property into an enumerable of IAttributeElements just as an easy
way of enabling Linq expressions against the collection. Since DxCore is written to
work with all versions of VisualStudio, there really isn't any official Linq support.
As a matter of fact, using the expression we did limits the plug-in to only those
people with .Net Framework 3.5 installed on their development machines. I think that
in this day and age, this is a fairly safe assumption, so I'm not that worried about
it. I would like to point out also, that having this expression in place does not
prevent the plug-in from working with Visual Studio 2005, as long as the 3.5 framework
is installed. 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Ok, so now we have a list of methods, and we’re filtering them based on whether or
not they are Test methods (defined by the existence of a Test attribute).&amp;nbsp; The
next thing to do is look for an Assert statement within the text of our method.&amp;nbsp;
This is another place where the Expressions Lab proves invaluable.&amp;nbsp; Looking at
Expressions Lab we discover that our Assert statement is in fact an ElementReferenceExpression
and is a child node of our Method object.&amp;nbsp; With this knowledge in hand we can
use the FindElementByName method on our Method object to look for an Assert reference:&lt;pre class="brush: csharp"&gt;var assert = method.FindChildByName("Assert") as IElementReferenceExpression&lt;/pre&gt;Now
all we have to do is test whether or not our assert variable is null, and we know
whether or not this method violates our rule. Once we do that test we can add the
appropriate Code Issue Type to the CodeIssues list using our event args. The last
piece of the puzzle then will look something like this:&lt;pre class="brush: csharp"&gt;if(assert == null)
{
    ea.AddIssue(CodeIssueType.CodeSmell,(SourceRange)method.NameRanges[0],"A Test Method should have at least one Assert");
}&lt;/pre&gt;
&lt;p&gt;
With this in place we should now be able to run our project and try it out. Using
F5 to debug a DxCore plug-in will launch a new instance of Visual Studio. From there
if you create a new project, or open an existing project, and write a test method
which does not have an Assert, you should see a red squiggle underneath the name of
the method. Hovering over that with your mouse you'll see our Code Issue test presented.
Adding an Assert will make the Code Issue disappear.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.drrandom.org/content/binary/WindowsLiveWriter/GettingaCodeRushInsideaCodeRushCodeIssue_D816/image_thumb_2.png" width="498" height="136"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Well, things are looking good here, we’ve got code that is searching for an issue,
and displaying the appropriate warning if our condition is met.&amp;nbsp; There is one
other condition we should probably consider, however.&amp;nbsp; The one case I can think
of when our rule does not apply is when we are expecting the code under test to throw
an exception.&amp;nbsp; In that case there would be an ExpectedException attribute on
the test class.&amp;nbsp; To make our users happy we should probably implement this functionality.
&lt;/p&gt;
&lt;p&gt;
The good news is we already know how to accomplish this, since we are using the same
technique to determine if the method we’re looking at is a test method.&amp;nbsp; All
we need to do is change the test condition in our Count() method so it looks for “ExpectedException”
instead of “Test”.&amp;nbsp; While we’re at it it seems like a reasonable thing to get
an instance of the attribute and then check it for null, similar to how we’re handling
the assert.&amp;nbsp; With all of this done the code should look like this:&lt;pre class="brush: csharp"&gt;var assert = method.FindChildByName("Assert") as IElementReferenceExpression;
var expectedException = method.Attributes.OfType&amp;lt;IAttributeElement&amp;gt;().FirstOrDefault(a =&amp;gt; a.Name == "ExpectedException");
if (assert == null &amp;amp;&amp;amp; expectedException == null)
{
    ea.AddIssue(CodeIssueType.CodeSmell, (SourceRange)method.NameRanges[0], "A Test Method should have at least one implicit or explicit Assertion");
}&lt;/pre&gt;So
now we should be able to run this, and see that the code issue disappears if we have
a test method with either an assert statement, or an expected exception attribute.
Pretty cool. You’ll notice that I also updated our issue message so it reflects the
fact that we are able to handle implicit assertions (in the form of our ExpectedException)
attribute.&amp;nbsp; For the sake of completeness, here is what our finished CheckCodeIssues
method looks like:&lt;pre class="brush: csharp"&gt;private void cipTestShouldAssert_CheckCodeIssues(object sender, CheckCodeIssuesEventArgs ea)
{
    var resolveScope = ea.ResolveScope();
    foreach (IMethodElement method in resolveScope.GetElementEnumerator(ea.Scope, new ElementTypeFilter(LanguageElementType.Method)))
    {
        if (method.Attributes.OfType&amp;lt;IAttributeElement&amp;gt;().Count(a =&amp;gt; a.Name == "Test") &amp;gt; 0)
        {
            var assert = method.FindChildByName("Assert") as IElementReferenceExpression;
            var expectedException = method.Attributes.OfType&amp;lt;IAttributeElement&amp;gt;().FirstOrDefault(a =&amp;gt; a.Name == "ExpectedException");
            if (assert == null &amp;amp;&amp;amp; expectedException == null)
            {
                ea.AddIssue(CodeIssueType.CodeSmell, (SourceRange)method.NameRanges[0], "A Test Method should have at least one implicit or explicit Assertion");
            }
        }
    }
}&lt;/pre&gt;
&lt;p&gt;
And that's it. Granted there are some things here I would like to change before releasing
this into the wild. We are specifically looking for NUnit/MbUnit style test method
declarations for one, and we are also looking only for the short version of the attribute
names, but this should give you a good idea of how things work. 
&lt;/p&gt;
&lt;p&gt;
If you are interested in seeing a more polished final version, you can either download
the &lt;a href="http://www.drrandom.org/downloads/CR_TestShouldAssert.zip"&gt;finished source
for this post&lt;/a&gt;, or have a look at my &lt;a href="http://code.google.com/p/dxcorecommunityplugins/wiki/CR_CreateTestMethod"&gt;CR_CreateTestMethod&lt;/a&gt; (admittedly
poorly named) plug-in on the &lt;a href="http://code.google.com/p/dxcorecommunityplugins/"&gt;DxCore
Community Plug-In's site&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=7bb82e3b-a7d0-4fa5-9ac1-0f8e4261ed11" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,7bb82e3b-a7d0-4fa5-9ac1-0f8e4261ed11.aspx</comments>
      <category>.Net</category>
      <category>C#</category>
      <category>CodeRush</category>
      <category>DxCore</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=c2e87a52-29b5-4ef9-8a22-a61a68031f0c</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,c2e87a52-29b5-4ef9-8a22-a61a68031f0c.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,c2e87a52-29b5-4ef9-8a22-a61a68031f0c.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=c2e87a52-29b5-4ef9-8a22-a61a68031f0c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I ran into this odd problem recently working with some Linq2SQL based persistence
code.  There is some code someone put together to commit a list of changed entities
to the database as part of a single transaction, which simply iterates through the
list and performs the appropriate action.  The problem I was having was that
I had an object referenced by another object that needed to be persisted first, otherwise
there was a foreign key violation.  To add to the strangeness there seemed to
be some magic going on (most likely utilizing the INotifyPropertyChanged goodness),
so that even if I tried to persist just my dependent object first, both were still
showing up in the list, and always in exactly the wrong order.  Now, I’m okay
with magic.  Magic makes a lot of things a lot easier.  The problem arises
whenever the magic is incomplete, and doesn’t follow through to take care of all of
the operation.  Its like someone comming up to you and saying “Pick A Card”,
at which point you do, and put the card back, and they say “I know what your card
was” and walking away.  Not real convincing.  This is what was going on
here.  There was the smarts to know that changes were being made to more than
one entity, and there were even attributes to define what properties contained dependent
objects, but no smarts to actually deal with a case when you would want to save more
than one object in an object graph at a time.
</p>
        <p>
So it occued to me I should be able to do some linqy magic and create some sort of
iterator that would return dependent objects in the appropriate order, so the lest
dependent of the objects get move to the beginning of the list.  My first step,
since I wasn’t really sure how to do this, was to write a test.  And I made it
more or less mirror the issue I was facing, a list of two items, one of which is a
dependency of the other.  I don’t know if there is a lot of value in posting
all of the test cases here, but the end result was rather nice.  Sure it took
several iterations, and there was plenty of infinite looping and stack overflows (which
does some fun things to studio when your running your tests with TestDriven.Net),
but I think this is a reasonable solution to the problem:
</p>
        <pre class="brush: csharp">public static IEnumerable&lt;T&gt; EnsureDependenciesFirst&lt;T&gt;(this IEnumerable&lt;T&gt; items, Func&lt;T ,IEnumerable&gt; selector)
{
    if(items.Count() &lt; 2)
        return;
    var firstPass = items.SkipWhile(t =&gt; items.Intersect(selector(t)).Count() &gt; 0);
    var remainingItems = items.Except(firstPass);
    if(items.Count() == remainingItems.Count())
        return remainingItems;
    return firstPass.Concat(remainingItems.EnsureDependenciesFirst(selector));
}
</pre>
        <p>
Ok, so what do we have here?  Well to start out I’m checking the item list to
see if there are at least two items in it, if not I just return the list.  This
provides a means to avoid an infinate loop due to the recursive call, and provides
a shortcut for a scenario with only one item.  Next off I use the SkipWhile()
method, combined with the user-supplied selector function to iterate through each
item, retrieve it’s list of dependencies (which is what the selector function does),
and checks to see if the current list contains any of the dependencies for the object. 
The results of this first pass are the objects which have no dependencies at all,
so therefore they need to be first in the list.  The next logical step is to
run the operation again for a list that <strong>does not</strong> contains the items
filtered out by the first pass.  This is done via a recursive call back to the
EnsureDependenciesFirst extension.  You will notice we’re checking the count
of the remaining items against the current list, and returning the list if they are
the same.  This is another safety precaution for dealing with infinite loops. 
If we have a circular dependency, this bit will just return the items that are interdependent.
</p>
        <p>
You will note that this is a generic function that has really noting at all to do
with the entities that I am dealing with.  This was largely due to the fact that
this was built TDD, so I just used a simple class which had a property that could
take another instance of itself.  To use this to overcome my entity committing
problem, I would have to write a not too small function to retrieve the list of dependent
objects from the entity (since there would need to be some reflection magic to look
at attributes on the properties to determine which properties contain dependencies),
but it pretty much will drop in to the foreach statement that is currently being used
to persist the entities.
</p>
        <p>
Incidently, I learned from my dev team what the “official” way of dealing with this
is a “ReorderChanges” method, which takes two entities, in the order in which they
should be persisted.  I think I like my solution better, mostly because it should
mean I don’t have to worry about it again.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=c2e87a52-29b5-4ef9-8a22-a61a68031f0c" />
      </body>
      <title>Some code for sorting lists which may contain dependencies</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,c2e87a52-29b5-4ef9-8a22-a61a68031f0c.aspx</guid>
      <link>http://www.drrandom.org/2009/09/18/SomeCodeForSortingListsWhichMayContainDependencies.aspx</link>
      <pubDate>Fri, 18 Sep 2009 20:08:47 GMT</pubDate>
      <description>&lt;p&gt;
I ran into this odd problem recently working with some Linq2SQL based persistence
code.&amp;nbsp; There is some code someone put together to commit a list of changed entities
to the database as part of a single transaction, which simply iterates through the
list and performs the appropriate action.&amp;nbsp; The problem I was having was that
I had an object referenced by another object that needed to be persisted first, otherwise
there was a foreign key violation.&amp;nbsp; To add to the strangeness there seemed to
be some magic going on (most likely utilizing the INotifyPropertyChanged goodness),
so that even if I tried to persist just my dependent object first, both were still
showing up in the list, and always in exactly the wrong order.&amp;nbsp; Now, I’m okay
with magic.&amp;nbsp; Magic makes a lot of things a lot easier.&amp;nbsp; The problem arises
whenever the magic is incomplete, and doesn’t follow through to take care of all of
the operation.&amp;nbsp; Its like someone comming up to you and saying “Pick A Card”,
at which point you do, and put the card back, and they say “I know what your card
was” and walking away.&amp;nbsp; Not real convincing.&amp;nbsp; This is what was going on
here.&amp;nbsp; There was the smarts to know that changes were being made to more than
one entity, and there were even attributes to define what properties contained dependent
objects, but no smarts to actually deal with a case when you would want to save more
than one object in an object graph at a time.
&lt;/p&gt;
&lt;p&gt;
So it occued to me I should be able to do some linqy magic and create some sort of
iterator that would return dependent objects in the appropriate order, so the lest
dependent of the objects get move to the beginning of the list.&amp;nbsp; My first step,
since I wasn’t really sure how to do this, was to write a test.&amp;nbsp; And I made it
more or less mirror the issue I was facing, a list of two items, one of which is a
dependency of the other.&amp;nbsp; I don’t know if there is a lot of value in posting
all of the test cases here, but the end result was rather nice.&amp;nbsp; Sure it took
several iterations, and there was plenty of infinite looping and stack overflows (which
does some fun things to studio when your running your tests with TestDriven.Net),
but I think this is a reasonable solution to the problem:
&lt;/p&gt;
&lt;pre class="brush: csharp"&gt;public static IEnumerable&amp;lt;T&amp;gt; EnsureDependenciesFirst&amp;lt;T&amp;gt;(this IEnumerable&amp;lt;T&amp;gt; items, Func&amp;lt;T ,IEnumerable&amp;gt; selector)
{
    if(items.Count() &amp;lt; 2)
        return;
    var firstPass = items.SkipWhile(t =&amp;gt; items.Intersect(selector(t)).Count() &amp;gt; 0);
    var remainingItems = items.Except(firstPass);
    if(items.Count() == remainingItems.Count())
        return remainingItems;
    return firstPass.Concat(remainingItems.EnsureDependenciesFirst(selector));
}
&lt;/pre&gt;
&lt;p&gt;
Ok, so what do we have here?&amp;nbsp; Well to start out I’m checking the item list to
see if there are at least two items in it, if not I just return the list.&amp;nbsp; This
provides a means to avoid an infinate loop due to the recursive call, and provides
a shortcut for a scenario with only one item.&amp;nbsp; Next off I use the SkipWhile()
method, combined with the user-supplied selector function to iterate through each
item, retrieve it’s list of dependencies (which is what the selector function does),
and checks to see if the current list contains any of the dependencies for the object.&amp;nbsp;
The results of this first pass are the objects which have no dependencies at all,
so therefore they need to be first in the list.&amp;nbsp; The next logical step is to
run the operation again for a list that &lt;strong&gt;does not&lt;/strong&gt; contains the items
filtered out by the first pass.&amp;nbsp; This is done via a recursive call back to the
EnsureDependenciesFirst extension.&amp;nbsp; You will notice we’re checking the count
of the remaining items against the current list, and returning the list if they are
the same.&amp;nbsp; This is another safety precaution for dealing with infinite loops.&amp;nbsp;
If we have a circular dependency, this bit will just return the items that are interdependent.
&lt;/p&gt;
&lt;p&gt;
You will note that this is a generic function that has really noting at all to do
with the entities that I am dealing with.&amp;nbsp; This was largely due to the fact that
this was built TDD, so I just used a simple class which had a property that could
take another instance of itself.&amp;nbsp; To use this to overcome my entity committing
problem, I would have to write a not too small function to retrieve the list of dependent
objects from the entity (since there would need to be some reflection magic to look
at attributes on the properties to determine which properties contain dependencies),
but it pretty much will drop in to the foreach statement that is currently being used
to persist the entities.
&lt;/p&gt;
&lt;p&gt;
Incidently, I learned from my dev team what the “official” way of dealing with this
is a “ReorderChanges” method, which takes two entities, in the order in which they
should be persisted.&amp;nbsp; I think I like my solution better, mostly because it should
mean I don’t have to worry about it again.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=c2e87a52-29b5-4ef9-8a22-a61a68031f0c" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,c2e87a52-29b5-4ef9-8a22-a61a68031f0c.aspx</comments>
      <category>.Net</category>
      <category>TDD</category>
      <category>tips</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=99f91720-94fc-4bde-b2f4-21d752eecb06</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,99f91720-94fc-4bde-b2f4-21d752eecb06.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,99f91720-94fc-4bde-b2f4-21d752eecb06.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=99f91720-94fc-4bde-b2f4-21d752eecb06</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As of today I have updated several things on the site.  First, I have a new hosting
provider, <a href="http://www.winhost.com">WinHost</a>.  This was primarily a
financial decision (saving $3.03 a month, not a lot but hey, every little bit helps,
right?), but it looks like there are some nice technical advantages to switching as
well.  Some of these are things like IIS 7 hosting, and SQL Server access. 
Also you get unlimited domain name pointers, so the <a href="http://www.IThinkIn.Net">IThinkIn.Net</a> domain
that I registered a few years back and could never wire up is now live.  While
I was in the process of moving to a new server I also updated to the latest version
of dasBlog, seeing as I was still running the original .Net 2.0 version from sometime
in early 2006 (I think).  I’m not sure whether there will be any immediate signs
of new and exciting things, but you never know.  You should now be able to utilize <a href="http://http://en.gravatar.com/">Gravatar</a> icons,
and <a href="http://openid.net/">OpenID</a>, so it can’t be all bad right?
</p>
        <p>
Please contact me if for any reason there is an issue with any of the content. 
As far as I know everything moved over without a hitch, but I’ve not verified everything
at this point.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=99f91720-94fc-4bde-b2f4-21d752eecb06" />
      </body>
      <title>Lot’s of Changes</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,99f91720-94fc-4bde-b2f4-21d752eecb06.aspx</guid>
      <link>http://www.drrandom.org/2009/09/09/LotsOfChanges.aspx</link>
      <pubDate>Wed, 09 Sep 2009 20:47:07 GMT</pubDate>
      <description>&lt;p&gt;
As of today I have updated several things on the site.&amp;nbsp; First, I have a new hosting
provider, &lt;a href="http://www.winhost.com"&gt;WinHost&lt;/a&gt;.&amp;nbsp; This was primarily a
financial decision (saving $3.03 a month, not a lot but hey, every little bit helps,
right?), but it looks like there are some nice technical advantages to switching as
well.&amp;nbsp; Some of these are things like IIS 7 hosting, and SQL Server access.&amp;nbsp;
Also you get unlimited domain name pointers, so the &lt;a href="http://www.IThinkIn.Net"&gt;IThinkIn.Net&lt;/a&gt; domain
that I registered a few years back and could never wire up is now live.&amp;nbsp; While
I was in the process of moving to a new server I also updated to the latest version
of dasBlog, seeing as I was still running the original .Net 2.0 version from sometime
in early 2006 (I think).&amp;nbsp; I’m not sure whether there will be any immediate signs
of new and exciting things, but you never know.&amp;nbsp; You should now be able to utilize &lt;a href="http://http://en.gravatar.com/"&gt;Gravatar&lt;/a&gt; icons,
and &lt;a href="http://openid.net/"&gt;OpenID&lt;/a&gt;, so it can’t be all bad right?
&lt;/p&gt;
&lt;p&gt;
Please contact me if for any reason there is an issue with any of the content.&amp;nbsp;
As far as I know everything moved over without a hitch, but I’ve not verified everything
at this point.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=99f91720-94fc-4bde-b2f4-21d752eecb06" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,99f91720-94fc-4bde-b2f4-21d752eecb06.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=6d8cd4bb-5b28-4950-9eae-404355cad058</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,6d8cd4bb-5b28-4950-9eae-404355cad058.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,6d8cd4bb-5b28-4950-9eae-404355cad058.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=6d8cd4bb-5b28-4950-9eae-404355cad058</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was pleased to find recently that Roy Osherove’s Art of Unit Testing was available
on Safari.  I have been following Roy’s blog for a while now, and was quite excited
at the prospect of him writing a book on Unit Testing.  It was only my personal
cheapness that kept me from shelling out the $25 to get the E-Book version from Manning
ahead of time.  I have to say, now that I have read it, that it would have been
well worth the money.  Before I get too deep I want to provide some context for
what I am about to say.
</p>
        <p>
          <strong>I consider myself an experienced TDD practitioner and Unit Test Writer<br /></strong>So that means that I was reading this book hoping to gain some insight. 
I wanted to find out how to write better, more readable, more maintainable tests. 
I was also hoping for a little bit of “atta-boy” affirmation that the way I do things
is the “right” way.  The astute reader may be able to tell that in order for
my first hope to be true, the second may have to get some points taken away. 
This was in fact the case, and to be honest, coming out of it I feel like I’ve gotten
more value from the things I’ve learned than I received from whatever ego stroking
may have occurred with what I am currently doing right.
</p>
        <p>
          <strong>So lets get started….<br /></strong>I was expecting the book to start out essentially as it did, some brief history
about the author and an introduction to Unit Testing for those who may not be familiar
with it.  I have to say I was expecting the book to be a little more TDD-centric
than it was, but I think most of that was my own bias for TDD as “The Only Way To
Write Software”.  Roy actually explained what TDD was, and also why he wasn’t
going to harp too much on it throughout the book.  I have to say, I can see why
he made the decision that he did.  I can also say that it seemed perfectly clear
to me that TDD is a technique that he feels has a lot a value, which made me happy. 
Since this is supposed to be a review from the perspective of an experienced practitioner
of TDD and Unit Testing, I’m not going to go into anything that was touched on in
the early chapters, apart from noting that they contained a general introduction to
the tools, technique and philosophy of unit testing.  I can also say that, though
I was already familiar with the material, I didn’t mind reading through it at all. 
Overall, Roy’s writing style was light and quite pleasant, even for a technical book.
</p>
        <p>
        </p>
        <p>
          <strong>And now into the meat of the book…<br /></strong>For me, things started getting interesting in Part 3 of the book.  This
is where issues of test design and organization are addressed.  This is one of
those areas that I feel like I need some guidance on, mostly because I developed my
testing idioms mostly through habit, and trial and error.  I look back on tests
I have written in the past (which could be as little as two days ago) and I wonder
how I could have come up with such a brittle, unmaintainable nightmare.  I feel
like I need guidance from the experts on what I can do better when writing my tests. 
Roy delivered on these items in chapter 7 “The pillars of good tests”.  One of
the lessons I took away from this was the value in testing one concept per test. 
I had heard this as “one assert per test” in the past, and scoffed at the idea. 
But Roy presents a very compelling argument for why this is a good idea, if you are
testing multiple concepts, you don’t know the extent of the problem when your test
fails.  And lets face it, the failing test is the reason we’re doing this whole
thing.  I’ve seen personally the failing test that just keeps failing. 
You tackle the issue from one failed assert only to rebuild, and find one right after
it which fails as well.  One of the issues I’ve had with this is the redundant
setup and configuration that could be required for exercising this concept, but this
issue is also addressed by the straight forward recommendation of creating clear and
understandable configuration methods.  In the past I have generally not been
really good about applying DRY to my test setup, which, I know, is another case of
treating tests differently from regular code.  Having someone in a position of
authority (like Roy) say, “put your setup in separate methods so you can re-use them
and make your tests more readable” made it okay to do the thing that I knew I should
be doing anyway.  The key concepts covered are making tests readable, maintainable,
and an accurate portrayal of the authors intent.
</p>
        <p>
          <strong>Even more in depth….<br /></strong>Section 4 goes even further and talks about how to integrate unit testing
into an organization which is not already doing it.  This is an interesting subject
to me as I have recently moved to a company which has not been doing unit testing
and TDD as part of their regular development process.  Roy draws on his experiences
as a consultant to provide some really good advice for how to go about enacting this
sort of change in an organization.  I particularly pleased with his candor when
he describes his failed attempts at integrating unit testing.  It would have
been quite easy to simply say “Based on my considerable expertise, these are the things
you need to do”, but he chooses instead to share some real-world experience in a straight
forward way that only adds to my respect for him as a professional.  In addition
to this, he touches on techniques for integrating testing into “legacy” code (i.e.
code which is not tested).  He does a good job at introducing some techniques
for testing what is essentially untestable code, which a very large nod at Michael
Feathers’ “Working Effectively with Legacy Code”. 
</p>
        <p>
The book ends with three appendices, one discussing the importance of testability
in the design process, one listing vairous testing tools (both Java and .Net), and
the last listing guidelines for conducting test reviews.  This last one is nice,
because it presents a concise view of all of the guidelines presented throughout the
book, and provides page references where you can get the “why” behind each.  
</p>
        <p>
          <strong>All in all…<br /></strong>This is a really good book, which should be part of any agile development
library.  It doesn’t matter if you are writing your first unit tests, or you’re
a seasoned pro, there is going to be something here for you.  I think it is great
that Roy has chosen to share his experience with the developer community in this way. 
I came into this book with some rather high expectations and I think they were met.
</p>
        <p>
          <strong>A note on TypeMock….<br /></strong>I remember seeing some criticism floating around on twitter suggesting the
book was rather pro TypeMock.  There was also the comment that Roy’s affiliation
with TypeMock was not made clear early on.  I can’t say I saw either of these
things when I was reading it.  For starters, I already knew Roy worked for TypeMock,
so perhaps that skewed my ability to objectively judge if the disclosure was done
in a timely manner or not.  I can say that the places in the book which there
seemed to be a preference for TypeMock were places where he stated things like “I
feel TypeMock has a better syntax in this case”, or “TypeMock is the only tool with
provides these capabilities”.  For starters, the first is a statement of preference. 
Sure Roy helped design the API for TypeMock, so it seems only natural that he would
prefer it to other frameworks, but having used it I would have to agree with the statement. 
It is a great API, and example if a fluent interface done well.  The second comment
is also plain fact.  Of the mocking libraries available in the .Net space, TypeMock
is the only one that allows you to swap instances of objects in place, without making
changes to the classes using them.  You can argue over whether or not this is
a good or a bad thing, but the fact remains that it is a feature specific to TypeMock. 
Maybe I was expecting something more blatant and obvious, but I just didn’t see it.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=6d8cd4bb-5b28-4950-9eae-404355cad058" />
      </body>
      <title>Review: Art of Unit Testing by Roy Osherove</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,6d8cd4bb-5b28-4950-9eae-404355cad058.aspx</guid>
      <link>http://www.drrandom.org/2009/09/02/ReviewArtOfUnitTestingByRoyOsherove.aspx</link>
      <pubDate>Wed, 02 Sep 2009 17:36:02 GMT</pubDate>
      <description>&lt;p&gt;
I was pleased to find recently that Roy Osherove’s Art of Unit Testing was available
on Safari.&amp;nbsp; I have been following Roy’s blog for a while now, and was quite excited
at the prospect of him writing a book on Unit Testing.&amp;nbsp; It was only my personal
cheapness that kept me from shelling out the $25 to get the E-Book version from Manning
ahead of time.&amp;nbsp; I have to say, now that I have read it, that it would have been
well worth the money.&amp;nbsp; Before I get too deep I want to provide some context for
what I am about to say.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;I consider myself an experienced TDD practitioner and Unit Test Writer&lt;br&gt;
&lt;/strong&gt;So that means that I was reading this book hoping to gain some insight.&amp;nbsp;
I wanted to find out how to write better, more readable, more maintainable tests.&amp;nbsp;
I was also hoping for a little bit of “atta-boy” affirmation that the way I do things
is the “right” way.&amp;nbsp; The astute reader may be able to tell that in order for
my first hope to be true, the second may have to get some points taken away.&amp;nbsp;
This was in fact the case, and to be honest, coming out of it I feel like I’ve gotten
more value from the things I’ve learned than I received from whatever ego stroking
may have occurred with what I am currently doing right.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;So lets get started….&lt;br&gt;
&lt;/strong&gt;I was expecting the book to start out essentially as it did, some brief history
about the author and an introduction to Unit Testing for those who may not be familiar
with it.&amp;nbsp; I have to say I was expecting the book to be a little more TDD-centric
than it was, but I think most of that was my own bias for TDD as “The Only Way To
Write Software”.&amp;nbsp; Roy actually explained what TDD was, and also why he wasn’t
going to harp too much on it throughout the book.&amp;nbsp; I have to say, I can see why
he made the decision that he did.&amp;nbsp; I can also say that it seemed perfectly clear
to me that TDD is a technique that he feels has a lot a value, which made me happy.&amp;nbsp;
Since this is supposed to be a review from the perspective of an experienced practitioner
of TDD and Unit Testing, I’m not going to go into anything that was touched on in
the early chapters, apart from noting that they contained a general introduction to
the tools, technique and philosophy of unit testing.&amp;nbsp; I can also say that, though
I was already familiar with the material, I didn’t mind reading through it at all.&amp;nbsp;
Overall, Roy’s writing style was light and quite pleasant, even for a technical book.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;And now into the meat of the book…&lt;br&gt;
&lt;/strong&gt;For me, things started getting interesting in Part 3 of the book.&amp;nbsp; This
is where issues of test design and organization are addressed.&amp;nbsp; This is one of
those areas that I feel like I need some guidance on, mostly because I developed my
testing idioms mostly through habit, and trial and error.&amp;nbsp; I look back on tests
I have written in the past (which could be as little as two days ago) and I wonder
how I could have come up with such a brittle, unmaintainable nightmare.&amp;nbsp; I feel
like I need guidance from the experts on what I can do better when writing my tests.&amp;nbsp;
Roy delivered on these items in chapter 7 “The pillars of good tests”.&amp;nbsp; One of
the lessons I took away from this was the value in testing one concept per test.&amp;nbsp;
I had heard this as “one assert per test” in the past, and scoffed at the idea.&amp;nbsp;
But Roy presents a very compelling argument for why this is a good idea, if you are
testing multiple concepts, you don’t know the extent of the problem when your test
fails.&amp;nbsp; And lets face it, the failing test is the reason we’re doing this whole
thing.&amp;nbsp; I’ve seen personally the failing test that just keeps failing.&amp;nbsp;
You tackle the issue from one failed assert only to rebuild, and find one right after
it which fails as well.&amp;nbsp; One of the issues I’ve had with this is the redundant
setup and configuration that could be required for exercising this concept, but this
issue is also addressed by the straight forward recommendation of creating clear and
understandable configuration methods.&amp;nbsp; In the past I have generally not been
really good about applying DRY to my test setup, which, I know, is another case of
treating tests differently from regular code.&amp;nbsp; Having someone in a position of
authority (like Roy) say, “put your setup in separate methods so you can re-use them
and make your tests more readable” made it okay to do the thing that I knew I should
be doing anyway.&amp;nbsp; The key concepts covered are making tests readable, maintainable,
and an accurate portrayal of the authors intent.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Even more in depth….&lt;br&gt;
&lt;/strong&gt;Section 4 goes even further and talks about how to integrate unit testing
into an organization which is not already doing it.&amp;nbsp; This is an interesting subject
to me as I have recently moved to a company which has not been doing unit testing
and TDD as part of their regular development process.&amp;nbsp; Roy draws on his experiences
as a consultant to provide some really good advice for how to go about enacting this
sort of change in an organization.&amp;nbsp; I particularly pleased with his candor when
he describes his failed attempts at integrating unit testing.&amp;nbsp; It would have
been quite easy to simply say “Based on my considerable expertise, these are the things
you need to do”, but he chooses instead to share some real-world experience in a straight
forward way that only adds to my respect for him as a professional.&amp;nbsp; In addition
to this, he touches on techniques for integrating testing into “legacy” code (i.e.
code which is not tested).&amp;nbsp; He does a good job at introducing some techniques
for testing what is essentially untestable code, which a very large nod at Michael
Feathers’ “Working Effectively with Legacy Code”. 
&lt;/p&gt;
&lt;p&gt;
The book ends with three appendices, one discussing the importance of testability
in the design process, one listing vairous testing tools (both Java and .Net), and
the last listing guidelines for conducting test reviews.&amp;nbsp; This last one is nice,
because it presents a concise view of all of the guidelines presented throughout the
book, and provides page references where you can get the “why” behind each.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;All in all…&lt;br&gt;
&lt;/strong&gt;This is a really good book, which should be part of any agile development
library.&amp;nbsp; It doesn’t matter if you are writing your first unit tests, or you’re
a seasoned pro, there is going to be something here for you.&amp;nbsp; I think it is great
that Roy has chosen to share his experience with the developer community in this way.&amp;nbsp;
I came into this book with some rather high expectations and I think they were met.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;A note on TypeMock….&lt;br&gt;
&lt;/strong&gt;I remember seeing some criticism floating around on twitter suggesting the
book was rather pro TypeMock.&amp;nbsp; There was also the comment that Roy’s affiliation
with TypeMock was not made clear early on.&amp;nbsp; I can’t say I saw either of these
things when I was reading it.&amp;nbsp; For starters, I already knew Roy worked for TypeMock,
so perhaps that skewed my ability to objectively judge if the disclosure was done
in a timely manner or not.&amp;nbsp; I can say that the places in the book which there
seemed to be a preference for TypeMock were places where he stated things like “I
feel TypeMock has a better syntax in this case”, or “TypeMock is the only tool with
provides these capabilities”.&amp;nbsp; For starters, the first is a statement of preference.&amp;nbsp;
Sure Roy helped design the API for TypeMock, so it seems only natural that he would
prefer it to other frameworks, but having used it I would have to agree with the statement.&amp;nbsp;
It is a great API, and example if a fluent interface done well.&amp;nbsp; The second comment
is also plain fact.&amp;nbsp; Of the mocking libraries available in the .Net space, TypeMock
is the only one that allows you to swap instances of objects in place, without making
changes to the classes using them.&amp;nbsp; You can argue over whether or not this is
a good or a bad thing, but the fact remains that it is a feature specific to TypeMock.&amp;nbsp;
Maybe I was expecting something more blatant and obvious, but I just didn’t see it.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=6d8cd4bb-5b28-4950-9eae-404355cad058" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,6d8cd4bb-5b28-4950-9eae-404355cad058.aspx</comments>
      <category>.Net</category>
      <category>TDD</category>
      <category>Review</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=24aaf20e-9858-42a8-abc0-75f6b7f128b4</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,24aaf20e-9858-42a8-abc0-75f6b7f128b4.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,24aaf20e-9858-42a8-abc0-75f6b7f128b4.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=24aaf20e-9858-42a8-abc0-75f6b7f128b4</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The folks at <a href="http://www.typemock.com/">TypeMock</a> have released a new UnitTesting
tool aimed specifically at catching deadlocks in multithreaded code called <a href="http://www.typemock.com/learn_about_typemock_racer.php">TypeMock
Racer</a>, and what's more they are <a href="http://blog.typemock.com/2009/06/easy-deadlock-detection-get-free.html" target="_blank">offering
free licenses to folks willing to review it during the 21 day free trial period</a>. 
As anyone who knows me can testify to, I am a whore for free-bees, so I decided to
take them up on this.
</p>
        <p>
          <strong>For the impatient, here is the executive summary:<br /></strong>This is a good tool.  Period.  It is, however, also a very specific
tool that is intended to help find very specific problems.  If you are not doing
any multithreaded code, there is no need to have it in your toolbox.  The cost
($890 US) is high enough that it doesn't really seem worth it to get it "just in case"
(unless, of course, you right a nice review on your blog and get a free license). 
If you <strong><em>do</em></strong> work with multithreaded code, and you<strong><em> are</em></strong> concerned
about deadlocks, this tool will save you lots of time, which ultimately means money.
</p>
        <p>
          <strong>Now, for the details</strong>
        </p>
        <p>
First of all, this is a tool from TypeMock, so I expected some pretty incredible things,
even at the 1.0 release.  After all, their flagship product <a href="http://www.typemock.com/learn_about_typemock_isolator.php">TypeMock
Isolator</a> is phenomenally powerful, so much so that the free license I was given
for <a href="http://www.drrandom.org/PermaLink,guid,5200ee4d-d92b-4931-9005-705f523228b1.aspx" target="_blank">posting
an advertisement</a> for the release of their ASP.Net product has gone largely unused. 
I'm just scared of it.  It's like having access to a 50 horse-power tablesaw
with no blade guard.  I may be careful enough to use it correctly most of the
time, but the fact that it can take off my forearm without pausing to ask my permission
makes me reluctant to get too close.  I do know that there are some very real
problems that the tool can solve that just can't be done with any other tool, so I
have every intent of getting up my courage, grabbing a first aid kit, and jumping
in to see what I can do...eventually.
</p>
        <p>
But Racer is different.  It is a very powerful tool with a very specific purpose. 
It makes it easier to run tests in multiple threads, and detect deadlocks.  As
far as I can tell, it just detects deadlocks, not race conditions, as it's name seems
to suggest.  Not that this is bad, just that it only covers half of the rather
shaky ground that is traveled while working with multithreaded code.  It is arguable,
however, that dealing with deadlocks is the more difficult of the two problems, so
getting this one tacked first is not a bad thing.
</p>
        <p>
          <strong>So how does it work?</strong>
        </p>
        <p>
Fairly straight forward really.  Start with a regular unit test, that is exercising
some code that is utilizing locks in an attempt to be thread safe.  It looks
like Racer supports just about every form of Synchronization supported by .Net, so
you can feel free to use whichever mechanism you are more comfortable with to get
the work done.  Now that you have a test, the simplest way to make use of Racer,
is to add the Typemock.Racer library reference to your test project, and then add
a ParrellelInspection attribute to the test.  This causes Racer to do it's thing,
which by default means running the test once with a single thread, and then run it
again using multiple threads (2 by default).  If there are no problems, nothing
much new happens.  You see some additional information about the test being run
first with one thread, and then multiple, and something about scenarios executed...nothing
that exciting.  The coolness happens when you actually get a deadlock. 
For starters you test output includes a bunch of new information, the most noticeable
of which is a big "DEADLOCK discovered when running the following" message. 
Also is a description of the scenario that caused the deadlock.  Something like
"Thread 1 acquired lock A, Thread 1 released lock A, Thread 2 attempted to acquire
lock B, etc".  Cooler yet is a message that says "To reproduce or debug this,
copy the following attribute, paste it on top of your test and rerun the test:", followed
by something that looks like 
<br /></p>
        <pre class="brush: csharp" name="code">[SpecificScenario("2", 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2)]</pre>
        <p>
          <br />
Which, while being completely incomprehensible to humans, causes your test to run
in the specific configuration which caused the deadlock to occur.  This means
that you can accurately recreate the exact situation that lead to the problem. 
If you have ever had to try to track down a deadlock in a live system, you will realize
that this information just saved you countless hours of trying to recreate the production
environment, and lots of trial and error getting things into the state that caused
the problem.  One word: Brilliant!
</p>
        <p>
          <strong>So what is the down side?</strong>
        </p>
        <p>
I have to say that I've not yet been able to figure out how Racer determines what
scenarios to run, or what the bits in the "SpecificScenario" attribute mean(well,
the first string parameter is the number of threads, and the other numbers refer to
the specific threads, and match the summary of the scenario, but beyond that, not
a clue).  It would be interesting to know these things, but not really critical,
as long as you are confident all appropriate scenarios are being executed.
</p>
        <p>
There is also an interesting feature that I can't quite get my head around. 
When you run a test with a deadlock, an image is generated, which is supposed to be
a visual representation of the scenario that created the deadlock.  Here is an
example:
</p>
        <p>
          <img src="content/binary/tmp442.tmp.png" border="0" />
          <br />
 
</p>
        <p>
Now, I see the three objects I was locking against (sync1, sync2, and sync3), and
I guess the odd rhombus shaped objects represent the threads, but I'm not really sure
what the diagram is trying to tell me.  This is, no doubt, something which is
still fairly raw in this early version.  I think it could be very useful if it
were clearer what the shapes and arrows represent, but at this point it is simply
a cleaver bit of kit that you can show somebody so that they can be confused too.
</p>
        <p>
The last issue I can see with it currently is the price.  At $890 US for a single
user license, it isn't an impulse buy.  Granted, I think it can pay for itself
easily after finding a few deadlocks in some production code (the earlier they are
found the more that find is worth), but I don't see it being a terribly easy sell
for management, at least if you are not actively trying to correct a threading issue. 
I feel pretty fortunate that I work for a company that understands the value of good
tools, and is willing to provide them if there is a need, but I think it would take
some convincing to get management to agree to purchase Racer simply because it is
a good tool, and could really pay off "one day".  If we were facing a threading
issue, and I could demonstrate that racer would allow us to find it, and accurately
reproduce it, it would be a fairly easy sell.  
</p>
        <p>
          <strong>So overall</strong>
        </p>
        <p>
I think this is an excellent tool.  Based on the fact that this is an early release,
I can only see it getting better over time.  It is a rather pricey tool, however,
so you may have to do some convincing to get the boss-man to get you a license. 
There is a 21-day trial, however, so if you find yourself in a situation where you
either have, or you could conceivably have, a risk of deadlock, then grab the trial,
and use the first detected deadlock as justification to get a full license.  
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=24aaf20e-9858-42a8-abc0-75f6b7f128b4" />
      </body>
      <title>Review - TypeMock Racer and Unit Testing Multithreaded Applications</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,24aaf20e-9858-42a8-abc0-75f6b7f128b4.aspx</guid>
      <link>http://www.drrandom.org/2009/06/19/ReviewTypeMockRacerAndUnitTestingMultithreadedApplications.aspx</link>
      <pubDate>Fri, 19 Jun 2009 16:31:17 GMT</pubDate>
      <description>&lt;p&gt;
The folks at &lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; have released a new UnitTesting
tool aimed specifically at catching deadlocks in multithreaded code called &lt;a href="http://www.typemock.com/learn_about_typemock_racer.php"&gt;TypeMock
Racer&lt;/a&gt;, and what's more they are &lt;a href="http://blog.typemock.com/2009/06/easy-deadlock-detection-get-free.html" target="_blank"&gt;offering
free licenses to folks willing to review it during the 21 day free trial period&lt;/a&gt;.&amp;nbsp;
As anyone who knows me can testify to, I am a whore for free-bees, so I decided to
take them up on this.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;For the impatient, here is the executive summary:&lt;br&gt;
&lt;/strong&gt;This is a good tool.&amp;nbsp; Period.&amp;nbsp; It is, however, also a very specific
tool that is intended to help find very specific problems.&amp;nbsp; If you are not doing
any multithreaded code, there is no need to have it in your toolbox.&amp;nbsp; The cost
($890 US) is high enough that it doesn't really seem worth it to get it "just in case"
(unless, of course, you right a nice review on your blog and get a free license).&amp;nbsp;
If you &lt;strong&gt;&lt;em&gt;do&lt;/em&gt;&lt;/strong&gt; work with multithreaded code, and you&lt;strong&gt;&lt;em&gt; are&lt;/em&gt;&lt;/strong&gt; concerned
about deadlocks, this tool will save you lots of time, which ultimately means money.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Now, for the details&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
First of all, this is a tool from TypeMock, so I expected some pretty incredible things,
even at the 1.0 release.&amp;nbsp; After all, their flagship product &lt;a href="http://www.typemock.com/learn_about_typemock_isolator.php"&gt;TypeMock
Isolator&lt;/a&gt; is phenomenally powerful, so much so that the free license I was given
for &lt;a href="http://www.drrandom.org/PermaLink,guid,5200ee4d-d92b-4931-9005-705f523228b1.aspx" target="_blank"&gt;posting
an advertisement&lt;/a&gt; for the release of their ASP.Net product has gone largely unused.&amp;nbsp;
I'm just scared of it.&amp;nbsp; It's like having access to a 50 horse-power tablesaw
with no blade guard.&amp;nbsp; I may be careful enough to use it correctly most of the
time, but the fact that it can take off my forearm without pausing to ask my permission
makes me reluctant to get too close.&amp;nbsp; I do know that there are some very real
problems that the tool can solve that just can't be done with any other tool, so I
have every intent of getting up my courage, grabbing a first aid kit, and jumping
in to see what I can do...eventually.
&lt;/p&gt;
&lt;p&gt;
But Racer is different.&amp;nbsp; It is a very powerful tool with a very specific purpose.&amp;nbsp;
It makes it easier to run tests in multiple threads, and detect deadlocks.&amp;nbsp; As
far as I can tell, it just detects deadlocks, not race conditions, as it's name seems
to suggest.&amp;nbsp; Not that this is bad, just that it only covers half of the rather
shaky ground that is traveled while working with multithreaded code.&amp;nbsp; It is arguable,
however, that dealing with deadlocks is the more difficult of the two problems, so
getting this one tacked first is not a bad thing.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;So how does it work?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Fairly straight forward really.&amp;nbsp; Start with a regular unit test, that is exercising
some code that is utilizing locks in an attempt to be thread safe.&amp;nbsp; It looks
like Racer supports just about every form of Synchronization supported by .Net, so
you can feel free to use whichever mechanism you are more comfortable with to get
the work done.&amp;nbsp; Now that you have a test, the simplest way to make use of Racer,
is to add the Typemock.Racer library reference to your test project, and then add
a ParrellelInspection attribute to the test.&amp;nbsp; This causes Racer to do it's thing,
which by default means running the test once with a single thread, and then run it
again using multiple threads (2 by default).&amp;nbsp; If there are no problems, nothing
much new happens.&amp;nbsp; You see some additional information about the test being run
first with one thread, and then multiple, and something about scenarios executed...nothing
that exciting.&amp;nbsp; The coolness happens when you actually get a deadlock.&amp;nbsp;
For starters you test output includes a bunch of new information, the most noticeable
of which is a big "DEADLOCK discovered when running the following" message.&amp;nbsp;
Also is a description of the scenario that caused the deadlock.&amp;nbsp; Something like
"Thread 1 acquired lock A, Thread 1 released lock A, Thread 2 attempted to acquire
lock B, etc".&amp;nbsp; Cooler yet is a message that says "To reproduce or debug this,
copy the following attribute, paste it on top of your test and rerun the test:", followed
by something that looks like 
&lt;br&gt;
&lt;/p&gt;
&lt;pre class="brush: csharp" name="code"&gt;[SpecificScenario("2", 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2)]&lt;/pre&gt;
&lt;p&gt;
&lt;br&gt;
Which, while being completely incomprehensible to humans, causes your test to run
in the specific configuration which caused the deadlock to occur.&amp;nbsp; This means
that you can accurately recreate the exact situation that lead to the problem.&amp;nbsp;
If you have ever had to try to track down a deadlock in a live system, you will realize
that this information just saved you countless hours of trying to recreate the production
environment, and lots of trial and error getting things into the state that caused
the problem.&amp;nbsp; One word: Brilliant!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;So what is the down side?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
I have to say that I've not yet been able to figure out how Racer determines what
scenarios to run, or what the bits in the "SpecificScenario" attribute mean(well,
the first string parameter is the number of threads, and the other numbers refer to
the specific threads, and match the summary of the scenario, but beyond that, not
a clue).&amp;nbsp; It would be interesting to know these things, but not really critical,
as long as you are confident all appropriate scenarios are being executed.
&lt;/p&gt;
&lt;p&gt;
There is also an interesting feature that I can't quite get my head around.&amp;nbsp;
When you run a test with a deadlock, an image is generated, which is supposed to be
a visual representation of the scenario that created the deadlock.&amp;nbsp; Here is an
example:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="content/binary/tmp442.tmp.png" border="0"&gt;
&lt;br&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Now, I see the three objects I was locking against (sync1, sync2, and sync3), and
I guess the odd rhombus shaped objects represent the threads, but I'm not really sure
what the diagram is trying to tell me.&amp;nbsp; This is, no doubt, something which is
still fairly raw in this early version.&amp;nbsp; I think it could be very useful if it
were clearer what the shapes and arrows represent, but at this point it is simply
a cleaver bit of kit that you can show somebody so that they can be confused too.
&lt;/p&gt;
&lt;p&gt;
The last issue I can see with it currently is the price.&amp;nbsp; At $890 US for a single
user license, it isn't an impulse buy.&amp;nbsp; Granted, I think it can pay for itself
easily after finding a few deadlocks in some production code (the earlier they are
found the more that find is worth), but I don't see it being a terribly easy sell
for management, at least if you are not actively trying to correct a threading issue.&amp;nbsp;
I feel pretty fortunate that I work for a company that understands the value of good
tools, and is willing to provide them if there is a need, but I think it would take
some convincing to get management to agree to purchase Racer simply because it is
a good tool, and could really pay off "one day".&amp;nbsp; If we were facing a threading
issue, and I could demonstrate that racer would allow us to find it, and accurately
reproduce it, it would be a fairly easy sell.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;So overall&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
I think this is an excellent tool.&amp;nbsp; Based on the fact that this is an early release,
I can only see it getting better over time.&amp;nbsp; It is a rather pricey tool, however,
so you may have to do some convincing to get the boss-man to get you a license.&amp;nbsp;
There is a 21-day trial, however, so if you find yourself in a situation where you
either have, or you could conceivably have, a risk of deadlock, then grab the trial,
and use the first detected deadlock as justification to get a full license.&amp;nbsp; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=24aaf20e-9858-42a8-abc0-75f6b7f128b4" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,24aaf20e-9858-42a8-abc0-75f6b7f128b4.aspx</comments>
      <category>.Net</category>
      <category>Review</category>
      <category>TDD</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=5200ee4d-d92b-4931-9005-705f523228b1</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,5200ee4d-d92b-4931-9005-705f523228b1.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,5200ee4d-d92b-4931-9005-705f523228b1.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=5200ee4d-d92b-4931-9005-705f523228b1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <br />
        <a href="http://www.typemock.com/">Unit Testing</a> ASP.NET? <a href="http://www.typemock.com/ASP.NET_unit_testing_page.php">ASP.NET
unit testing</a> has never been this easy.<br /><br />
Typemock is launching a new product for ASP.NET developers – the <strong>ASP.NET Bundle</strong> -
and for the launch will be giving out <span style="color:#006600;"><strong>FREE licenses</strong></span> to
bloggers and their readers.<br /><br />
The ASP.NET Bundle is the ultimate ASP.NET unit testing solution, and offers both <a href="http://www.typemock.com/">Typemock
Isolator</a>, a <a href="http://www.typemock.com/">unit test</a> tool and <a href="http://sm-art.biz/Ivonna.aspx">Ivonna</a>,
the Isolator add-on for <a href="http://sm-art.biz/Ivonna.aspx">ASP.NET unit testing</a>,
for a bargain price.<br /><br />
Typemock Isolator is a leading <a href="http://www.typemock.com/">.NET unit testing</a> tool
(C# and VB.NET) for many ‘hard to test’ technologies such as <a href="http://typemock.com/sharepointpage.php">SharePoint</a>, <a href="http://www.typemock.com/ASP.NET_unit_testing_page.php">ASP.NET</a>, <a href="http://www.typemock.com/ASP.NET_unit_testing_page.php">MVC</a>, <a href="http://www.typemock.com/wcfpage.php">WCF</a>,
WPF, <a href="http://www.typemock.com/Silverlight_unit_testing_page.php">Silverlight</a> and
more. Note that for <a href="http://www.typemock.com/Silverlight_unit_testing_page.php">unit
testing Silverlight</a> there is an open source Isolator add-on called <a href="http://www.typemock.com/Silverlight_unit_testing_page.php">SilverUnit</a>.<br /><br />
The first 60 bloggers who will blog this text in their blog and <a href="http://blog.typemock.com/2009/05/get-free-typemock-licenses-aspnet.html">tell
us about it</a>, will get a Free Isolator ASP.NET Bundle license (Typemock Isolator
+ Ivonna). If you post this in an ASP.NET <strong>dedicated</strong> blog, you'll
get a license automatically (even if more than 60 submit) during the first week of
this announcement.<br /><br />
Also 8 bloggers will get an <strong>additional 2 licenses</strong> (each) to give
away to their readers <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=5200ee4d-d92b-4931-9005-705f523228b1" /></body>
      <title>Typemock License Giveaway</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,5200ee4d-d92b-4931-9005-705f523228b1.aspx</guid>
      <link>http://www.drrandom.org/2009/05/20/TypemockLicenseGiveaway.aspx</link>
      <pubDate>Wed, 20 May 2009 16:46:43 GMT</pubDate>
      <description>&lt;/span&gt;
&lt;br /&gt;
&lt;a href="http://www.typemock.com/"&gt;Unit Testing&lt;/a&gt; ASP.NET? &lt;a href="http://www.typemock.com/ASP.NET_unit_testing_page.php"&gt;ASP.NET
unit testing&lt;/a&gt; has never been this easy.&lt;br /&gt;
&lt;br /&gt;
Typemock is launching a new product for ASP.NET developers – the &lt;strong&gt;ASP.NET Bundle&lt;/strong&gt; -
and for the launch will be giving out &lt;span style="color:#006600;"&gt;&lt;strong&gt;FREE licenses&lt;/strong&gt;&lt;/span&gt; to
bloggers and their readers.&lt;br /&gt;
&lt;br /&gt;
The ASP.NET Bundle is the ultimate ASP.NET unit testing solution, and offers both &lt;a href="http://www.typemock.com/"&gt;Typemock
Isolator&lt;/a&gt;, a &lt;a href="http://www.typemock.com/"&gt;unit test&lt;/a&gt; tool and &lt;a href="http://sm-art.biz/Ivonna.aspx"&gt;Ivonna&lt;/a&gt;,
the Isolator add-on for &lt;a href="http://sm-art.biz/Ivonna.aspx"&gt;ASP.NET unit testing&lt;/a&gt;,
for a bargain price.&lt;br /&gt;
&lt;br /&gt;
Typemock Isolator is a leading &lt;a href="http://www.typemock.com/"&gt;.NET unit testing&lt;/a&gt; tool
(C# and VB.NET) for many ‘hard to test’ technologies such as &lt;a href="http://typemock.com/sharepointpage.php"&gt;SharePoint&lt;/a&gt;, &lt;a href="http://www.typemock.com/ASP.NET_unit_testing_page.php"&gt;ASP.NET&lt;/a&gt;, &lt;a href="http://www.typemock.com/ASP.NET_unit_testing_page.php"&gt;MVC&lt;/a&gt;, &lt;a href="http://www.typemock.com/wcfpage.php"&gt;WCF&lt;/a&gt;,
WPF, &lt;a href="http://www.typemock.com/Silverlight_unit_testing_page.php"&gt;Silverlight&lt;/a&gt; and
more. Note that for &lt;a href="http://www.typemock.com/Silverlight_unit_testing_page.php"&gt;unit
testing Silverlight&lt;/a&gt; there is an open source Isolator add-on called &lt;a href="http://www.typemock.com/Silverlight_unit_testing_page.php"&gt;SilverUnit&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
The first 60 bloggers who will blog this text in their blog and &lt;a href="http://blog.typemock.com/2009/05/get-free-typemock-licenses-aspnet.html"&gt;tell
us about it&lt;/a&gt;, will get a Free Isolator ASP.NET Bundle license (Typemock Isolator
+ Ivonna). If you post this in an ASP.NET &lt;strong&gt;dedicated&lt;/strong&gt; blog, you'll
get a license automatically (even if more than 60 submit) during the first week of
this announcement.&lt;br /&gt;
&lt;br /&gt;
Also 8 bloggers will get an &lt;strong&gt;additional 2 licenses&lt;/strong&gt; (each) to give
away to their readers &lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=5200ee4d-d92b-4931-9005-705f523228b1" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,5200ee4d-d92b-4931-9005-705f523228b1.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=df7ca78a-8a93-4a21-9245-39514a67aea4</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,df7ca78a-8a93-4a21-9245-39514a67aea4.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,df7ca78a-8a93-4a21-9245-39514a67aea4.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=df7ca78a-8a93-4a21-9245-39514a67aea4</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>Some (good?) string extension methods</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,df7ca78a-8a93-4a21-9245-39514a67aea4.aspx</guid>
      <link>http://www.drrandom.org/2009/02/22/SomeGoodStringExtensionMethods.aspx</link>
      <pubDate>Sun, 22 Feb 2009 17:19:09 GMT</pubDate>
      <description>&lt;p&gt;
So, to take a slightly different turn from my usual meta discussions of process, theory,
and architecture, there have been several people who have offered up some examples
of extension methods that they have found useful, now that .Net 3.5 is roaring along
nicely. There are some collections of such utilities, like the &lt;a href="http://www.codeplex.com/umbrella"&gt;Umbrella
project&lt;/a&gt;, and some folks like &lt;a href="http://srtsolutions.com/blogs/billwagner/default.aspx"&gt;Bill
Wagner&lt;/a&gt; who have &lt;a href="http://www.amazon.com/More-Effective-Specific-Software-Development/dp/0321485890"&gt;written
books&lt;/a&gt; on the subject (okay, there are other things in there too), so I thought
I might as well throw my hat into the ring as well. Specifically, there was this &lt;a href="http://twitter.com/elijahmanor/status/1219521290"&gt;tweet&lt;/a&gt; from &lt;a href="http://twitter.com/elijahmanor"&gt;@elijahmanor&lt;/a&gt; a
few days ago. It points to a positing which includes some extensions on string to
convert from strings to value types (int, long, short, etc). I pointed out that in
our current project we have distilled this down to a single extension method: To&lt;T&gt;
().
&lt;/p&gt;
&lt;p&gt;
He suggested I blog about it, so here it is:
&lt;/p&gt;
&lt;p&gt;
So we actually have two classes of conversions, one converts from a string to a value
type, and they other converts from a string to a Nullable value type. In the case
of our project, the nullable version came first, and so it became very easy to create
the version that returned a non-nullable value. Here are the methods of interest:
&lt;/p&gt;
&lt;pre class="brush: csharp" name="code"&gt;public static T To&lt;T&gt;
(this string input) where T : struct { return input.To&lt;T&gt;
(default(T)); } public static T To&lt;T&gt;
(this string input, T defaultValue) where T: struct { return input.ToNullable&lt;T&gt;
() ?? defaultValue; } public static T? ToNullable&lt;T&gt;
(this string input) where T : struct { if (string.IsNullOrEmpty(input)) return null;
var tryParse = GetTryParse&lt;T&gt;
(); return (T?)tryParse(input); }
&lt;/pre&gt;
&lt;p&gt;&lt;&gt; delegate that will run the string input through the try parse and return either a null (in case the TryParse fails), or a boxed version of the result.  So, lets see what it looks like before we discuss pros and cons&lt;/p&gt;
Okay, so this is pretty straight forward. The non-nullable version calls through to
the nullable version, and if it is null, it returns default(T). But, as I'm sure you
are an astute reader, you will see that there is some magic going on; namely the GetTryParse()
method. This little guy goes off and looks for a TryParse method on whatever T happens
to be, and then returns a Func&lt;pre class="brush: csharp" &gt;&lt;string,object&gt;private static Func GetTryParse&lt;T&gt;
() { var tryParseEx = GetTryParseExpression&lt;T&gt;&lt;Func&lt;string,object&gt;
(); return (s) =&gt; tryParseEx.Compile()(s,default(T)); } private static Expression&gt;
GetTryParseExpression&lt;T&gt;&lt;Func&lt;string, T, object&gt;&lt;Func&lt;string,object&gt;
() { if (_tryParseCache.ContainsKey(typeof(T))) return _tryParseCache[typeof(T)] as
Expression&gt;; MethodInfo tryParse = typeof(T).GetMethod("TryParse", new Type[] { typeof(string),
typeof(T).MakeByRefType() }); Ensure.IsNotNull(tryParse, string.Format("Cannot convert
from type string to type {0} because {0} does not have a TryParse method", typeof(T).FullName));
var stringArg = Expression.Parameter(typeof(string), "input"); var tempArg = Expression.Parameter(typeof(T),
"tmp"); var tryParseEx = Expression.Lambda&gt;( Expression.Condition( Expression.Call(tryParse,
stringArg, tempArg) , Expression.Convert(tempArg, typeof(object)) , Expression.Constant(null))
, stringArg, tempArg); _tryParseCache.Add(typeof(T), tryParseEx); return tryParseEx;
}
&lt;/pre&gt;
&lt;p&gt;
So here we have some code looking for a TryParse method, and building an expression
(using Linq Expression Trees) to execute it. Now, I'll be honest, this is not the
code I'm using in the project where this originally came from...mostly because I didn't
think of it then. In that case I'm actually doing a big case statement, checking the
type of T and running the appropriate method. This is much shorter, but potentially
much slower at runtime. So that is where the _tryParseCache comes in. This is a simple
static dictionary which contains the expressions created for each of the types, which
means you only get the runtime performance hit once when you first ask to parse a
specific type. The declaration for this object looks like this:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="brush: csharp" name="code"&gt;private static Dictionary&lt;Type ,Expression&gt;
_tryParseCache = new Dictionary&lt;type ,Expression&gt;
(); 
&lt;/pre&gt;
&lt;p&gt;
There you have it, my first (and possibly last??) contribution into the world of extension
methods. Please commence criticisms
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=df7ca78a-8a93-4a21-9245-39514a67aea4" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,df7ca78a-8a93-4a21-9245-39514a67aea4.aspx</comments>
      <category>.Net</category>
      <category>tips</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=2e66da2d-0f2f-43b4-b7da-80f498300018</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,2e66da2d-0f2f-43b4-b7da-80f498300018.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,2e66da2d-0f2f-43b4-b7da-80f498300018.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=2e66da2d-0f2f-43b4-b7da-80f498300018</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
So previously I posed a <a href="http://www.drrandom.org/PermaLink,guid,b5ed52fc-4fe4-43e2-a287-daa60a269cc0.aspx">question</a>,
which in it's simplest form is: Should you write code for the rest of your group (or
at their proficency level), or should you write code as advanced as you need. and
let it serve as an example for those on your team who are less advanced in their abilities. 
The practical answer I have come up with is, like most answers of this type, "It depends".
</p>
        <p>
I have decided to handle things this way:  
<br />
First, don't compromise.  If I feel something is a bad practice, or ultimately
going to restrain future development, then do what needs to be done.<br />
But Also: Try to avoid introducing advanced concepts and idioms until there is a compelling
example of what their benefit is.  This is probably something that applies more
to working with existing apps, then greenfield development, but it certainly has bearing
in both cases.  The big example for this that I ran into was IoC.  I am
a big fan of IoC, but it is hard to come up with a good, concise explanation of why
you need this additional tool.  I've been wanting to introduce IoC since I started
working at <a href="http://www.envisagenow.com/">Envisage</a>, but the explanation
"This will make things much easier later on" is not good enough...particularly when
you are trying to embrace YAGNI.  So the key is to wait until you can actually
demonstrate the advantage, and provide a before and after example of how things are
done.
</p>
        <p>
Lead by example, but make sure you have the examples.  To bring the food analogy
back into play, it isn't good enough to create a gourmet meal, and tell the people
who say they don't like it that, no, it really is better, and their just not sophisticated
enough to know it.  It is better to start smaller, and build their appreciation
up in increments.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=2e66da2d-0f2f-43b4-b7da-80f498300018" />
      </body>
      <title>Do I have the answer yet? Not really</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,2e66da2d-0f2f-43b4-b7da-80f498300018.aspx</guid>
      <link>http://www.drrandom.org/2009/02/08/DoIHaveTheAnswerYetNotReally.aspx</link>
      <pubDate>Sun, 08 Feb 2009 00:31:31 GMT</pubDate>
      <description>&lt;p&gt;
So previously I posed a &lt;a href="http://www.drrandom.org/PermaLink,guid,b5ed52fc-4fe4-43e2-a287-daa60a269cc0.aspx"&gt;question&lt;/a&gt;,
which in it's simplest form is: Should you write code for the rest of your group (or
at their proficency level), or should you write code as advanced as you need. and
let it serve as an example for those on your team who are less advanced in their abilities.&amp;nbsp;
The practical answer I have come up with is, like most answers of this type, "It depends".
&lt;/p&gt;
&lt;p&gt;
I have decided to handle things this way:&amp;nbsp; 
&lt;br&gt;
First, don't compromise.&amp;nbsp; If I feel something is a bad practice, or ultimately
going to restrain future development, then do what needs to be done.&lt;br&gt;
But Also: Try to avoid introducing advanced concepts and idioms until there is a compelling
example of what their benefit is.&amp;nbsp; This is probably something that applies more
to working with existing apps, then greenfield development, but it certainly has bearing
in both cases.&amp;nbsp; The big example for this that I ran into was IoC.&amp;nbsp; I am
a big fan of IoC, but it is hard to come up with a good, concise explanation of why
you need this additional tool.&amp;nbsp; I've been wanting to introduce IoC since I started
working at &lt;a href="http://www.envisagenow.com/"&gt;Envisage&lt;/a&gt;, but the explanation
"This will make things much easier later on" is not good enough...particularly when
you are trying to embrace YAGNI.&amp;nbsp; So the key is to wait until you can actually
demonstrate the advantage, and provide a before and after example of how things are
done.
&lt;/p&gt;
&lt;p&gt;
Lead by example, but make sure you have the examples.&amp;nbsp; To bring the food analogy
back into play, it isn't good enough to create a gourmet meal, and tell the people
who say they don't like it that, no, it really is better, and their just not sophisticated
enough to know it.&amp;nbsp; It is better to start smaller, and build their appreciation
up in increments.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=2e66da2d-0f2f-43b4-b7da-80f498300018" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,2e66da2d-0f2f-43b4-b7da-80f498300018.aspx</comments>
      <category>Practices</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=af366215-2454-4d54-bad7-463d5222f547</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,af366215-2454-4d54-bad7-463d5222f547.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,af366215-2454-4d54-bad7-463d5222f547.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=af366215-2454-4d54-bad7-463d5222f547</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
At <a href="http://www.envisagenow.com">Envisage</a>, we have a 1 week iteration. 
This means that we typically don't want a single story to go longer than one week. 
We also change up the pair rotation once per week.  The estimation process is
not perfect, though, and we have a lot of support from management to choose doing
things right, rather than doing things now, which leads to stories going beyond a
single iteration.  So when this happens, there is usually a small rock/paper/scissors
session with the developers involved to determine who will be taking the story. 
More often then not, the story goes with the machine (and the developer) that was
used to do the work, since it is usually not practical to check in changes at the
end of the week (also, our QA builds on Fri for a demo, so a green build is needed
on Fri).
</p>
        <p>
One approach to this, which occurred to myself, and one of our other developers at
close to the same time, was to utilize the concept of a personal branch.  This
is something that I believe is supported transparently in TFS, though I'm not 100%
sure.  We are using Subversion, so the process is somewhat manual, but overall
pretty easy to get started.  Once a branch was created, I found it extremely
liberating.  I have apparently been making decisions about how much to change
while I'm refactoring code at least partly based on how much work it will be to integrate
directly back into the trunk.  Having a private, protected area for me to work
made it much easier to change things in the way they needed to be changed.  It
also meant that I could check in more often, including checking in changes which would
leave the app in a non-functional state.  Having those commit points meant that
I could more easily undo changes, and gave me a nice warm and fuzzy feeling about
the changes I was making.  There was also another interesting advantage, and
that was when another developer was asking me about how the API would look on some
of the objects I was working on, and I was able to point him directly to my branch
to see the changes.
</p>
        <p>
There were a few issues, however.  The biggest was that, though we are running
the Subversion 1.5 server, our repository has not been updated, so the <a href="http://subversion.tigris.org/merge-tracking/">automatic
merge tracking</a> was not working.  This meant that I had to keep track of the
revision numbers myself whenever I needed to merge updates to the trunk into my branch. 
And this also made the "Reintegrate Branch" merge function impossible when I was ready
to check my changes in.  Despite these issues, I think in this particular case
(the story lasted about 3 weeks) I was worth the extra effort, and made the overall
process much easier.  We will be updating our repository this week, which may
make having a personal branch a viable solution for normal day-to-day work, but as
it is the effort involved was a bit more than what I would want to deal with on a
regular basis.  I will certainly not hesitate to break out this tool whenever
I've got either a long running, or a large scope (meaning either large numbers of
files effected, or a large change to parts of the API) story.  I certainly recommend
giving it a try.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=af366215-2454-4d54-bad7-463d5222f547" />
      </body>
      <title>Use of a &amp;quot;Personal Branch&amp;quot; for long-running stories</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,af366215-2454-4d54-bad7-463d5222f547.aspx</guid>
      <link>http://www.drrandom.org/2009/02/08/UseOfAQuotPersonalBranchquotForLongrunningStories.aspx</link>
      <pubDate>Sun, 08 Feb 2009 00:09:21 GMT</pubDate>
      <description>&lt;p&gt;
At &lt;a href="http://www.envisagenow.com"&gt;Envisage&lt;/a&gt;, we have a 1 week iteration.&amp;nbsp;
This means that we typically don't want a single story to go longer than one week.&amp;nbsp;
We also change up the pair rotation once per week.&amp;nbsp; The estimation process is
not perfect, though, and we have a lot of support from management to choose doing
things right, rather than doing things now, which leads to stories going beyond a
single iteration.&amp;nbsp; So when this happens, there is usually a small rock/paper/scissors
session with the developers involved to determine who will be taking the story.&amp;nbsp;
More often then not, the story goes with the machine (and the developer) that was
used to do the work, since it is usually not practical to check in changes at the
end of the week (also, our QA builds on Fri for a demo, so a green build is needed
on Fri).
&lt;/p&gt;
&lt;p&gt;
One approach to this, which occurred to myself, and one of our other developers at
close to the same time, was to utilize the concept of a personal branch.&amp;nbsp; This
is something that I believe is supported transparently in TFS, though I'm not 100%
sure.&amp;nbsp; We are using Subversion, so the process is somewhat manual, but overall
pretty easy to get started.&amp;nbsp; Once a branch was created, I found it extremely
liberating.&amp;nbsp; I have apparently been making decisions about how much to change
while I'm refactoring code at least partly based on how much work it will be to integrate
directly back into the trunk.&amp;nbsp; Having a private, protected area for me to work
made it much easier to change things in the way they needed to be changed.&amp;nbsp; It
also meant that I could check in more often, including checking in changes which would
leave the app in a non-functional state.&amp;nbsp; Having those commit points meant that
I could more easily undo changes, and gave me a nice warm and fuzzy feeling about
the changes I was making.&amp;nbsp; There was also another interesting advantage, and
that was when another developer was asking me about how the API would look on some
of the objects I was working on, and I was able to point him directly to my branch
to see the changes.
&lt;/p&gt;
&lt;p&gt;
There were a few issues, however.&amp;nbsp; The biggest was that, though we are running
the Subversion 1.5 server, our repository has not been updated, so the &lt;a href="http://subversion.tigris.org/merge-tracking/"&gt;automatic
merge tracking&lt;/a&gt; was not working.&amp;nbsp; This meant that I had to keep track of the
revision numbers myself whenever I needed to merge updates to the trunk into my branch.&amp;nbsp;
And this also made the "Reintegrate Branch" merge function impossible when I was ready
to check my changes in.&amp;nbsp; Despite these issues, I think in this particular case
(the story lasted about 3 weeks) I was worth the extra effort, and made the overall
process much easier.&amp;nbsp; We will be updating our repository this week, which may
make having a personal branch a viable solution for normal day-to-day work, but as
it is the effort involved was a bit more than what I would want to deal with on a
regular basis.&amp;nbsp; I will certainly not hesitate to break out this tool whenever
I've got either a long running, or a large scope (meaning either large numbers of
files effected, or a large change to parts of the API) story.&amp;nbsp; I certainly recommend
giving it a try.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=af366215-2454-4d54-bad7-463d5222f547" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,af366215-2454-4d54-bad7-463d5222f547.aspx</comments>
      <category>Practices</category>
      <category>Version Control</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=3af104dc-01e3-4fc0-80c5-9d74bf112415</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,3af104dc-01e3-4fc0-80c5-9d74bf112415.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,3af104dc-01e3-4fc0-80c5-9d74bf112415.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=3af104dc-01e3-4fc0-80c5-9d74bf112415</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Like so many others, <a href="http://stackoverflow.com/users/20504/ckramer">I've</a> been
sucked into the alure of <a href="http://www.stackoverflow.com">StackOverflow</a>.
</p>
        <p>
This is kinda like a porn addiction, only more destructive to personal relationships.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=3af104dc-01e3-4fc0-80c5-9d74bf112415" />
      </body>
      <title>New addiction: StackOverflow.com</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,3af104dc-01e3-4fc0-80c5-9d74bf112415.aspx</guid>
      <link>http://www.drrandom.org/2008/10/16/NewAddictionStackOverflowcom.aspx</link>
      <pubDate>Thu, 16 Oct 2008 03:00:12 GMT</pubDate>
      <description>&lt;p&gt;
Like so many others, &lt;a href="http://stackoverflow.com/users/20504/ckramer"&gt;I've&lt;/a&gt; been
sucked into the alure of &lt;a href="http://www.stackoverflow.com"&gt;StackOverflow&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
This is kinda like a porn addiction, only more destructive to personal relationships.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=3af104dc-01e3-4fc0-80c5-9d74bf112415" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,3af104dc-01e3-4fc0-80c5-9d74bf112415.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=b5ed52fc-4fe4-43e2-a287-daa60a269cc0</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,b5ed52fc-4fe4-43e2-a287-daa60a269cc0.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,b5ed52fc-4fe4-43e2-a287-daa60a269cc0.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=b5ed52fc-4fe4-43e2-a287-daa60a269cc0</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We had a friend visiting from out of town last night, and she is apparently fond of
"Top Chef".  This was the first time I had encountered this particular "reality"
based show, and I found in a lot of ways it was like the majority of the rest of the
shows out there; trying hard to create drama where there really isn't any.  In
this particular episode there was a challenge to cook food for a neighborhood block
party.  The group that did the worst in this particular case cited the fact that
they were preparing food for everyone including kids, as a reason for not getting
jiggy with the menu (in a culinary sense).  The response from the judges was
that good food would speak for itself, and they should have considered it their responsibility
to raise the collective bar of quality for the neighborhood.
</p>
        <p>
I find this quite interesting because it mirrors an internal dilemma I am facing with
the code I am currently putting together.  The dilemma is this:  Should
I create things which are more "advanced" and more difficult for those who are not
familiar with the concepts, or should I take the audience into consideration, and
forego some of the more advanced concepts in favor of simplicity and discoverability? 
</p>
        <p>
My gut tells me that I should do the latter.  I'm a big believer in the power
of writing code that is easy to understand and maintain.  This is particularly
true whenever you are writing code which will potentially be consumed by other developers
working within the application.  If someone cannot figure out how to utilize
the work you've done, then chances are they are going to go off and duplicate it. 
The eventual result of this being half a dozen ways to accomplish what is basically
the same thing.
</p>
        <p>
The idea brought up on the show seems to go against this philosophy by suggesting
that you have the ability to expand the pallets of those who are consuming your work
(the food metaphor is staring to get pretty rich here), and so you would be doing
them a disservice not to.  In my case, I've found places where my choice to keep
things more like what everyone is used to has added complexity and ugliness elsewhere.  
</p>
        <p>
So does this mean I should forge ahead and present concepts which are going to be
new to others on the team, and potentially create code that will not be re-used as
it should because it does not make sense to those needing to re-use it?  If I
don't introduce these concepts am I missing an opportunity to bring up the overall
quality of the code being by everyone?  Am I just struggling to fid answers to
questions that I really shouldn't be asking, since the YAGNI police are keeping their
eyes on things?
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=b5ed52fc-4fe4-43e2-a287-daa60a269cc0" />
      </body>
      <title>How important is your Code Audience?</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,b5ed52fc-4fe4-43e2-a287-daa60a269cc0.aspx</guid>
      <link>http://www.drrandom.org/2008/04/08/HowImportantIsYourCodeAudience.aspx</link>
      <pubDate>Tue, 08 Apr 2008 17:30:04 GMT</pubDate>
      <description>&lt;p&gt;
We had a friend visiting from out of town last night, and she is apparently fond of
"Top Chef".&amp;nbsp; This was the first time I had encountered this particular "reality"
based show, and I found in a lot of ways it was like the majority of the rest of the
shows out there; trying hard to create drama where there really isn't any.&amp;nbsp; In
this particular episode there was a challenge to cook food for a neighborhood block
party.&amp;nbsp; The group that did the worst in this particular case cited the fact that
they were preparing food for everyone including kids, as a reason for not getting
jiggy with the menu (in a culinary sense).&amp;nbsp; The response from the judges was
that good food would speak for itself, and they should have considered it their responsibility
to raise the collective bar of quality for the neighborhood.
&lt;/p&gt;
&lt;p&gt;
I find this quite interesting because it mirrors an internal dilemma I am facing with
the code I am currently putting together.&amp;nbsp; The dilemma is this:&amp;nbsp; Should
I create things which are more "advanced" and more difficult for those who are not
familiar with the concepts, or should I take the audience into consideration, and
forego some of the more advanced concepts in favor of simplicity and discoverability? 
&lt;/p&gt;
&lt;p&gt;
My gut tells me that I should do the latter.&amp;nbsp; I'm a big believer in the power
of writing code that is easy to understand and maintain.&amp;nbsp; This is particularly
true whenever you are writing code which will potentially be consumed by other developers
working within the application.&amp;nbsp; If someone cannot figure out how to utilize
the work you've done, then chances are they are going to go off and duplicate it.&amp;nbsp;
The eventual result of this being half a dozen ways to accomplish what is basically
the same thing.
&lt;/p&gt;
&lt;p&gt;
The idea brought up on the show seems to go against this philosophy by suggesting
that you have the ability to expand the pallets of those who are consuming your work
(the food metaphor is staring to get pretty rich here), and so you would be doing
them a disservice not to.&amp;nbsp; In my case, I've found places where my choice to keep
things more like what everyone is used to has added complexity and ugliness elsewhere.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
So does this mean I should forge ahead and present concepts which are going to be
new to others on the team, and potentially create code that will not be re-used as
it should because it does not make sense to those needing to re-use it?&amp;nbsp; If I
don't introduce these concepts am I missing an opportunity to bring up the overall
quality of the code being by everyone?&amp;nbsp; Am I just struggling to fid answers to
questions that I really shouldn't be asking, since the YAGNI police are keeping their
eyes on things?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=b5ed52fc-4fe4-43e2-a287-daa60a269cc0" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,b5ed52fc-4fe4-43e2-a287-daa60a269cc0.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=9af39795-771d-4950-8d5f-032801341634</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,9af39795-771d-4950-8d5f-032801341634.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,9af39795-771d-4950-8d5f-032801341634.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=9af39795-771d-4950-8d5f-032801341634</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I think this falls pretty solidly in the
DUH! category.<br /><br /><br /><p></p><a href="http://www.nerdtests.com/nt2ref.html"><img src="http://www.nerdtests.com/images/badge/nt2/477d73ef5030526f.png" alt="NerdTests.com says I'm a Kinda Dorky Nerd King.  What are you?  Click here!" /></a><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=9af39795-771d-4950-8d5f-032801341634" /></body>
      <title>I'm a Nerd</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,9af39795-771d-4950-8d5f-032801341634.aspx</guid>
      <link>http://www.drrandom.org/2007/10/10/ImANerd.aspx</link>
      <pubDate>Wed, 10 Oct 2007 23:06:15 GMT</pubDate>
      <description>I think this falls pretty solidly in the DUH! category.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;a href="http://www.nerdtests.com/nt2ref.html"&gt; &lt;img src="http://www.nerdtests.com/images/badge/nt2/477d73ef5030526f.png" alt="NerdTests.com says I'm a Kinda Dorky Nerd King.  What are you?  Click here!"&gt; &lt;/a&gt;&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=9af39795-771d-4950-8d5f-032801341634" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,9af39795-771d-4950-8d5f-032801341634.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=4ec5e15f-86a5-49b2-bdde-569311078d63</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,4ec5e15f-86a5-49b2-bdde-569311078d63.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,4ec5e15f-86a5-49b2-bdde-569311078d63.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=4ec5e15f-86a5-49b2-bdde-569311078d63</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I'm currently finding myself in the midst of an evolutionary change.  And I'm
not talking about my super-human mutant powers, I'm talking about the way I'm thinking
about solving a specific set of problems. 
</p>
        <p>
Let's start with a sample....Lets take something like processing credit-cards as a
benign and IP free place to start.  As a subject that I really have no practical
experience with, it seems like an appropriate choice.  I'm going to assume that
there are different rules for doing checksum validation on credit card numbers, depending
on what the card is (Mastercard/Visa/Discover/etc). Now, here is evolutionary step
1: Use a basic case statement to process the various cards.  Here is what something
like that would look like:<br /></p>
        <pre class="brush: csharp">switch(CardType)
{
    case CardType.MasterCard:
        CardValidators.MasterCardValidator(card.CardNumber);
        break;
    case CardType.Visa:
        CardValidators.VisaValidator(card.CardNumber);
        break;
    case CardType.Discover:
        CardValidators.DiscoverValidator(card.CardNumber);
        break;
}</pre>
        <p>
 
</p>
        <p>
This looks pretty straight-forward, and as it stands it isn't too bad from a maintainability
stand point.  But what happens when there are many different types of cards? 
An then what happens when you find a large amount of duplication between the validation
functions?
</p>
        <p>
Well, any student of GoF should be able to tell you that a Chain Of Responsibility
pattern looks like a perfect fit for this sort of scenario.  So, evolutionary
step 2: Create separate classes to handle the different types of validation, and configure
them in a Chain of Responsibility pattern where each instance decides for itself whether
it can process the input.
</p>
        <p>
Here is a quick and dirty look at what something like that would look like:<br /><img style="border-width: 0px;" alt="ClassDiagram1" src="http://www.drrandom.org/content/binary/ClassDiagram1.png" border="0" height="421" width="571" /></p>
        <p>
 
</p>
        <p>
The two most interesting things here are the GetValidator() method in the AbstractCardValidator,
and the individual CanValidate() methods in the concrete implementations.  What
this does is it allows each class to decide for itself how it is going to determine
whether or not it can be used as a validator for a specific card (thats the CanValidate()
part), and also provides a single point which the consumer of the API can use to get <em>the</em> validator
for the card instance they have.  You would probably want to build and Abstract
Factory around this, which would instantiate all of the ICardValidator classes, and
then run the GetValidator() method to get the correct one.
</p>
        <p>
Now we are at a point where things are looking pretty good; we've got the ability
to do some fairly complex logic to make the decision about which validator to use,
and we have a way to simply ask for one, and the correct one appears.  Pretty
cool.
</p>
        <p>
This is actually the place where I have found myself in the not to distant past. 
I have previously been perfectly content with this arrangement, and been fairly happy
with the separation of concerns among the classes...I mean, after all, who better
to decide whether or not a specific class should be used to validate a card than the
class itself.  So what is the issue?  Well, recently I have become aware
of two problems with this arrangement: Tight Coupling, and a violation of the Single
Responsibility Principle.  Let's start with the first:
</p>
        <p>
          <strong>Tight Coupling<br /></strong>The credit card example may be a bit contrived when it comes to this issue,
but bear with me.  Overall, the issue is that specific instances of ICardValidtor
objects are being created and handed around.  The use of an interface and an
Abstract Factory pattern would actually help the situation out some, but effectively
all it does is move the coupling from the consuming class to the Factory (okay, it
also consolidates coupling to a single class, which makes maintenance a lot easier). 
As I said, contained, but still there.  It would be nice if the factory didn't
need any knowledge of what concrete instances of ICardValidator were out there. 
Before we tackle that, though, lets also look at the second issue:
</p>
        <p>
          <strong>Violation of the "Single Responsibility Principle"<br /></strong>The SRP states that a class should have one, and only one, thing it is responsible
for.  Sounds pretty easy doesn't it?  The problem is that this can be difficult
to obtain without a fair amount of discipline.  The violation of SRP which
I'm seeing is that the ICardValidator is responsible for both validating a credit
card <em>and</em> determining which validator is appropriate.  But wait! 
Didn't I just say that moving this check into the ICardValidator instance was a "Good
Thing"?  Well, lets go as far as saying it is <em>better</em> than the previous
method, but still not perfect.  Applying the SRP would move the task of selecting
a validator from the ICardValidator instance, and put it on it's own somewhere. 
So, thusly we come to our:
</p>
        <p>
          <strong>Inversion Of Control Container</strong>.<br />
That's right, we are now going to get crazy and move the responsibility of creating
these instances to another component all together.  The nice thing about this
is that it allows us to move all of the knowledge about dependencies off somewhere
else.  How does this apply to this example?  Well, lets assume we have an
object of type <em>Card</em> which requires as a dependency an instance of an <em>ICardValidator.  </em>We'll
also assume that <em>Card</em> is subclassed based on the type of credit card. 
It now becomes trivial to configure our IoC container to supply a <em>specific implementation</em> (read
sub-type) of <em>ICardValidator</em> for each implementation (again, read sub-type)
of <em>Card</em>.  Now, when you want a <em>Card</em> instance, you ask the IoC
container for one, and depending on what type of card it is, you will get the appropriate <em>ICardValidator</em> as
well.
</p>
        <p>
What's the catch?  Well there is some additional complexity which will show up
somewhere in the application due to the IoC, but typically IoC configuration can be
delegated down to the configuration file level, so even then the ugliness is pushed
away to it's own dark corner.
</p>
        <p>
But wait!  Why should we have different instances of <em>Card</em>?  What
if the Card class is just a container for the card data?  Well, our Ioc still
gives us some advantages.  If we look back at our first example with the switch
statement, we've got a nice <em>CardType</em> enum, which could be a property of our <em>Card</em> class. 
Using an IoC container like the one provided by the Castle project, you have the ability
to configure a key string for your instances.  This would make it trivial to
map the enum choices to specific keys within the container, which the <em>Card</em> class
would use to get an ICardValidator instance.  This would also make it possible
to make the validators slightly more advanced by adding something like a Decorator
pattern, in which specific aspects of the validation could be factored into separate
classes, and then "stacked" to produce the final validation logic (This is the same
concept used by the Stream classes in .Net and Java.  You can modify the behavior
of a stream by passing it to the constructor of a stream with different behavior).
</p>
        <p>
It is definatly worth mentioning that there is a sudden appearance
of tight coupling to the IoC container itself from our consuming classes.  You
probably want to try to abstract away the fact that the IoC container exists from
the majority of the application.  Factory classes go a fair ways in making this
happen, but another good idea is to introduce a single service to do type resolution. 
The Factory classes can then ask this service for the object they want, and they never
need to know the IoC container is there.  This approach also gives you the ability
to create some objects using IoC and others in another (more traditional) way.
</p>
        <p>
So is this it?  Have I finally found the answer I've been looking for? 
It's hard to say right now.  For the time being this is a decent way to handle
things, provided the complexity of the underlying system, and the need for loose-coupling
are both high enough to justify the additional complexity of the IoC.  But who
knows, in another couple months I may find something new, or even something old, which
seems better, cleaner, simpler.  That, after all, is my final goal....And I need
to remind myself of that regularly, lest I become complacent.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=4ec5e15f-86a5-49b2-bdde-569311078d63" />
      </body>
      <title>The evolution of design, and the continued search for &amp;quot;The Way&amp;quot;</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,4ec5e15f-86a5-49b2-bdde-569311078d63.aspx</guid>
      <link>http://www.drrandom.org/2007/10/02/TheEvolutionOfDesignAndTheContinuedSearchForQuotTheWayquot.aspx</link>
      <pubDate>Tue, 02 Oct 2007 20:53:13 GMT</pubDate>
      <description>&lt;p&gt;
I'm currently finding myself in the midst of an evolutionary change.&amp;nbsp; And I'm
not talking about my super-human mutant powers, I'm talking about the way I'm thinking
about solving a specific set of problems. 
&lt;/p&gt;
&lt;p&gt;
Let's start with a sample....Lets take something like processing credit-cards as a
benign and IP free place to start.&amp;nbsp; As a subject that I really have no practical
experience with, it seems like an appropriate choice.&amp;nbsp; I'm going to assume that
there are different rules for doing checksum validation on credit card numbers, depending
on what the card is (Mastercard/Visa/Discover/etc). Now, here is evolutionary step
1: Use a basic case statement to process the various cards.&amp;nbsp; Here is what something
like that would look like:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="brush: csharp"&gt;switch(CardType)
{
    case CardType.MasterCard:
        CardValidators.MasterCardValidator(card.CardNumber);
        break;
    case CardType.Visa:
        CardValidators.VisaValidator(card.CardNumber);
        break;
    case CardType.Discover:
        CardValidators.DiscoverValidator(card.CardNumber);
        break;
}&lt;/pre&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This looks pretty straight-forward, and as it stands it isn't too bad from a maintainability
stand point.&amp;nbsp; But what happens when there are many different types of cards?&amp;nbsp;
An then what happens when you find a large amount of duplication between the validation
functions?
&lt;/p&gt;
&lt;p&gt;
Well, any student of GoF should be able to tell you that a Chain Of Responsibility
pattern looks like a perfect fit for this sort of scenario.&amp;nbsp; So, evolutionary
step 2: Create separate classes to handle the different types of validation, and configure
them in a Chain of Responsibility pattern where each instance decides for itself whether
it can process the input.
&lt;/p&gt;
&lt;p&gt;
Here is a quick and dirty look at what something like that would look like:&lt;br&gt;
&lt;img style="border-width: 0px;" alt="ClassDiagram1" src="http://www.drrandom.org/content/binary/ClassDiagram1.png" border="0" height="421" width="571"&gt; 
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The two most interesting things here are the GetValidator() method in the AbstractCardValidator,
and the individual CanValidate() methods in the concrete implementations.&amp;nbsp; What
this does is it allows each class to decide for itself how it is going to determine
whether or not it can be used as a validator for a specific card (thats the CanValidate()
part), and also provides a single point which the consumer of the API can use to get &lt;em&gt;the&lt;/em&gt; validator
for the card instance they have.&amp;nbsp; You would probably want to build and Abstract
Factory around this, which would instantiate all of the ICardValidator classes, and
then run the GetValidator() method to get the correct one.
&lt;/p&gt;
&lt;p&gt;
Now we are at a point where things are looking pretty good; we've got the ability
to do some fairly complex logic to make the decision about which validator to use,
and we have a way to simply ask for one, and the correct one appears.&amp;nbsp; Pretty
cool.
&lt;/p&gt;
&lt;p&gt;
This is actually the place where I have found myself in the not to distant past.&amp;nbsp;
I have previously been perfectly content with this arrangement, and been fairly happy
with the separation of concerns among the classes...I mean, after all, who better
to decide whether or not a specific class should be used to validate a card than the
class itself.&amp;nbsp; So what is the issue?&amp;nbsp; Well, recently I have become aware
of two problems with this arrangement: Tight Coupling, and a violation of the Single
Responsibility Principle.&amp;nbsp; Let's start with the first:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Tight Coupling&lt;br&gt;
&lt;/strong&gt;The credit card example may be a bit contrived when it comes to this issue,
but bear with me.&amp;nbsp; Overall, the issue is that specific instances of ICardValidtor
objects are being created and handed around.&amp;nbsp; The use of an interface and an
Abstract Factory pattern would actually help the situation out&amp;nbsp;some, but effectively
all it does is move the coupling from the consuming class to the Factory (okay, it
also consolidates coupling to a single class, which makes maintenance a lot easier).&amp;nbsp;
As I said, contained, but still there.&amp;nbsp; It would be nice if the factory didn't
need any knowledge of what concrete instances of ICardValidator were out there.&amp;nbsp;
Before we tackle that, though, lets also look at the second issue:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Violation of the "Single Responsibility Principle"&lt;br&gt;
&lt;/strong&gt;The SRP states that a class should have one, and only one, thing it is responsible
for.&amp;nbsp; Sounds pretty easy doesn't it?&amp;nbsp; The problem is that this can be difficult
to obtain without a fair&amp;nbsp;amount of discipline.&amp;nbsp; The violation of SRP which
I'm seeing is that the ICardValidator is responsible for both validating a credit
card &lt;em&gt;and&lt;/em&gt; determining which validator is appropriate.&amp;nbsp; But wait!&amp;nbsp;
Didn't I just say that moving this check into the ICardValidator instance was a "Good
Thing"?&amp;nbsp; Well, lets go as far as saying it is &lt;em&gt;better&lt;/em&gt; than the previous
method, but still not perfect.&amp;nbsp; Applying the SRP would move the task of selecting
a validator from the ICardValidator instance, and put it on it's own somewhere.&amp;nbsp;
So, thusly we come to our:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Inversion Of Control Container&lt;/strong&gt;.&lt;br&gt;
That's right, we are now going to get crazy and move the responsibility of creating
these instances to another component all together.&amp;nbsp; The nice thing about this
is that it allows us to move all of the knowledge about dependencies off somewhere
else.&amp;nbsp; How does this apply to this example?&amp;nbsp; Well, lets assume we have an
object of type &lt;em&gt;Card&lt;/em&gt; which requires as a dependency an instance of an &lt;em&gt;ICardValidator.&amp;nbsp; &lt;/em&gt;We'll
also assume that &lt;em&gt;Card&lt;/em&gt; is subclassed based on the type of credit card.&amp;nbsp;
It now becomes trivial to configure our IoC container to supply a &lt;em&gt;specific implementation&lt;/em&gt; (read
sub-type) of &lt;em&gt;ICardValidator&lt;/em&gt; for each implementation (again, read sub-type)
of &lt;em&gt;Card&lt;/em&gt;.&amp;nbsp; Now, when you want a &lt;em&gt;Card&lt;/em&gt; instance, you ask the IoC
container for one, and depending on what type of card it is, you will get the appropriate &lt;em&gt;ICardValidator&lt;/em&gt; as
well.
&lt;/p&gt;
&lt;p&gt;
What's the catch?&amp;nbsp; Well there is some additional complexity which will show up
somewhere in the application due to the IoC, but typically IoC configuration can be
delegated down to the configuration file level, so even then the ugliness is pushed
away to it's own dark corner.
&lt;/p&gt;
&lt;p&gt;
But wait!&amp;nbsp; Why should we have different instances of &lt;em&gt;Card&lt;/em&gt;?&amp;nbsp; What
if the Card class is just a container for the card data?&amp;nbsp; Well, our Ioc still
gives us some advantages.&amp;nbsp; If we look back at our first example with the switch
statement, we've got a nice &lt;em&gt;CardType&lt;/em&gt; enum, which could be a property of our &lt;em&gt;Card&lt;/em&gt; class.&amp;nbsp;
Using an IoC container like the one provided by the Castle project, you have the ability
to configure a key string for your instances.&amp;nbsp; This would make it trivial to
map the enum choices to specific keys within the container, which the &lt;em&gt;Card&lt;/em&gt; class
would use to get an ICardValidator instance.&amp;nbsp; This would also make it possible
to make the validators slightly more advanced by adding something like a Decorator
pattern, in which specific aspects of the validation could be factored into separate
classes, and then "stacked" to produce the final validation logic (This is the same
concept used by the Stream classes in .Net and Java.&amp;nbsp; You can modify the behavior
of a stream by passing it to the constructor of a stream with different behavior).
&lt;/p&gt;
&lt;p&gt;
It is definatly&amp;nbsp;worth mentioning&amp;nbsp;that there is a&amp;nbsp;sudden appearance
of tight coupling to the IoC container itself from our consuming classes.&amp;nbsp; You
probably want to try to abstract away the fact that the IoC container exists from
the majority of the application.&amp;nbsp; Factory classes go a fair ways in making this
happen, but another good idea is to introduce a single service to do type resolution.&amp;nbsp;
The Factory classes can then ask this service for the object they want, and they never
need to know the IoC container is there.&amp;nbsp; This approach also gives you the ability
to create some objects using IoC and others in another (more traditional) way.
&lt;/p&gt;
&lt;p&gt;
So is this it?&amp;nbsp; Have I finally found the answer I've been looking for?&amp;nbsp;
It's hard to say right now.&amp;nbsp; For the time being this is a decent way to handle
things, provided the complexity of the underlying system, and the need for loose-coupling
are both high enough to justify the additional complexity of the IoC.&amp;nbsp; But who
knows, in another couple months I may find something new, or even something old, which
seems better, cleaner, simpler.&amp;nbsp; That, after all, is my final goal....And I need
to remind myself of that regularly, lest I become complacent.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=4ec5e15f-86a5-49b2-bdde-569311078d63" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,4ec5e15f-86a5-49b2-bdde-569311078d63.aspx</comments>
      <category>.Net</category>
      <category>IoC</category>
      <category>tips</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=5d6be24f-f400-4d27-a14e-72f5e9f86f4f</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,5d6be24f-f400-4d27-a14e-72f5e9f86f4f.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,5d6be24f-f400-4d27-a14e-72f5e9f86f4f.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=5d6be24f-f400-4d27-a14e-72f5e9f86f4f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
About two weeks ago I crafted my first Fluent Interface.  Since then I'm finding
myself seeing more and more places where I think such an approach would be useful. 
The part that I'm finding odd is that it is something that just recently became a
possibility for me.  The big motivating factor behind that I believe was reading
the <a href="http://martinfowler.com/bliki/FluentInterface.html">post</a> that <a href="http://martinfowler.com/bliki">Martin
Fowler</a> did on the subject, in which he basically describes it as a super-great
idea (okay, I'm paraphrasing, but you get the idea).  The concept is fairly simple;
write an API that reads like a sentence.  
</p>
        <p>
This isn't a new concept, in fact I seem to recall reading quite a bit in the world
of agile and TDD in which the authors encourage you to make method/property/variable
names verbose and more like natural language in order to improve readability of code,
and make the items more self-documenting.  I think the big difference, though,
is that fluent interfaces tend to be more granular.  Instead of a single method
that reads like a sentence, you are building a sentence using method and property
names, with Intellisense there to help you determine what is possible at the end.
</p>
        <p>
The big shift, I think, is in the realization that within this context method names
like <font face="Consolas">With</font>, <font face="Consolas">For</font>, and <font face="Consolas">And</font> are
perfectly okay, and as a matter of fact make things better in the end.  Its like
a taboo has been lifted, and suddenly I have a whole new landscape of possibilities
opened up.
</p>
        <p>
Since the original implementation of a small fluent interface I created for a small
part of my project (I'm using it to describe discrete elements of a document to be
parsed), I've found myself creating a new fluent interface to play with .Net 3.5 extension
methods (replicating the Ruby 10.Minutes.Ago semantics), and also adding a new interface
to the same production project as the first which is being used to grab component
services from my IoC container.
</p>
        <p>
I'm not sure if this is a new paradigm, or just a new hammer looking for nails, but
it is interesting none-the-less. It has also opened up new challenges around testing
and intellisense documentation, which I've not quite figured out yet.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=5d6be24f-f400-4d27-a14e-72f5e9f86f4f" />
      </body>
      <title>I'm getting more fluent...and its kinda strange</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,5d6be24f-f400-4d27-a14e-72f5e9f86f4f.aspx</guid>
      <link>http://www.drrandom.org/2007/09/15/ImGettingMoreFluentandItsKindaStrange.aspx</link>
      <pubDate>Sat, 15 Sep 2007 15:29:40 GMT</pubDate>
      <description>&lt;p&gt;
About two weeks ago I crafted my first Fluent Interface.&amp;nbsp; Since then I'm finding
myself seeing more and more places where I think such an approach would be useful.&amp;nbsp;
The part that I'm finding odd is that it is something that just recently became a
possibility for me.&amp;nbsp; The big motivating factor behind that I believe was reading
the &lt;a href="http://martinfowler.com/bliki/FluentInterface.html"&gt;post&lt;/a&gt; that &lt;a href="http://martinfowler.com/bliki"&gt;Martin
Fowler&lt;/a&gt; did on the subject, in which he basically describes it as a super-great
idea (okay, I'm paraphrasing, but you get the idea).&amp;nbsp; The concept is fairly simple;
write an API that reads like a sentence.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
This isn't a new concept, in fact I seem to recall reading quite a bit in the world
of agile and TDD in which the authors encourage you to make method/property/variable
names verbose and more like natural language in order to improve readability of code,
and make the items more self-documenting.&amp;nbsp; I think the big difference, though,
is that fluent interfaces tend to be more granular.&amp;nbsp; Instead of a single method
that reads like a sentence, you are building a sentence using method and property
names, with Intellisense there to help you determine what is possible at the end.
&lt;/p&gt;
&lt;p&gt;
The big shift, I think, is in the realization that within this context method names
like &lt;font face="Consolas"&gt;With&lt;/font&gt;, &lt;font face="Consolas"&gt;For&lt;/font&gt;, and &lt;font face="Consolas"&gt;And&lt;/font&gt; are
perfectly okay, and as a matter of fact make things better in the end.&amp;nbsp; Its like
a taboo has been lifted, and suddenly I have a whole new landscape of possibilities
opened up.
&lt;/p&gt;
&lt;p&gt;
Since the original implementation of a small fluent interface I created for a small
part of my project (I'm using it to describe discrete elements of a document to be
parsed), I've found myself creating a new fluent interface to play with .Net 3.5 extension
methods (replicating the Ruby 10.Minutes.Ago semantics), and also adding a new interface
to the same production project as the first which is being used to grab component
services from my IoC container.
&lt;/p&gt;
&lt;p&gt;
I'm not sure if this is a new paradigm, or just a new hammer looking for nails, but
it is interesting none-the-less. It has also opened up new challenges around testing
and intellisense documentation, which I've not quite figured out yet.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=5d6be24f-f400-4d27-a14e-72f5e9f86f4f" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,5d6be24f-f400-4d27-a14e-72f5e9f86f4f.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=a4a3874a-539b-4f0e-b285-efd180a3b7bf</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,a4a3874a-539b-4f0e-b285-efd180a3b7bf.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,a4a3874a-539b-4f0e-b285-efd180a3b7bf.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=a4a3874a-539b-4f0e-b285-efd180a3b7bf</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I found this little jewel in <a href="http://martinfowler.com/bliki">Martin Fowler's</a> recent
post <a href="http://martinfowler.com/bliki/OneLanguage.html">OneLanguage</a></p>
        <blockquote>
          <p>
            <em>... a jigger of 80 proof ugliness ...</em>
          </p>
        </blockquote>
        <p>
Check the post for the full context if you need to know <em>what</em> is a jigger
of 80 proof ugliness, but this phrase, for whatever reason, gave me large amounts
of joy just now.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=a4a3874a-539b-4f0e-b285-efd180a3b7bf" />
      </body>
      <title>My new favorite phrase</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,a4a3874a-539b-4f0e-b285-efd180a3b7bf.aspx</guid>
      <link>http://www.drrandom.org/2007/09/04/MyNewFavoritePhrase.aspx</link>
      <pubDate>Tue, 04 Sep 2007 15:45:16 GMT</pubDate>
      <description>&lt;p&gt;
I found this little jewel in &lt;a href="http://martinfowler.com/bliki"&gt;Martin Fowler's&lt;/a&gt; recent
post &lt;a href="http://martinfowler.com/bliki/OneLanguage.html"&gt;OneLanguage&lt;/a&gt;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;em&gt;... a jigger of 80 proof ugliness ...&lt;/em&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Check the post for the full context if you need to know &lt;em&gt;what&lt;/em&gt; is a jigger
of 80 proof ugliness, but this phrase, for whatever reason, gave me large amounts
of joy just now.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=a4a3874a-539b-4f0e-b285-efd180a3b7bf" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,a4a3874a-539b-4f0e-b285-efd180a3b7bf.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=11a503e2-ba17-47ad-baec-d238fd5dccb4</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,11a503e2-ba17-47ad-baec-d238fd5dccb4.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,11a503e2-ba17-47ad-baec-d238fd5dccb4.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=11a503e2-ba17-47ad-baec-d238fd5dccb4</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I ran into this issue today when trying to find a quick and dirty script to enforce
redirection from HTTP to HTTPS for an intranet site we're enabling for HTTPS (yes,
I know SSL on an intranet???  One word - Audit).  I thought this would be
easy...I half expected that there would be an IIS setting to handle this for me; I
was wrong on both counts.  So what I ended up doing is using an old DNN HttpModule
which was set up to allow the user to specify specific tabs in DNN for SSL, and greatly
simplifying things to work to my advantage.  I thought I would post it so I wouldn't
have to look for it again.
</p>
        <p>
To give a quick overview of what is going on, this is an HTTP Module which looks at
a value in the web.config to determine whether or not to enforce HTTPS or not. 
If the setting is set to true (or yes), then I'm just grabbing the Url property from
the Request object, loading it up in a UriBuilder, and setting the Scheme to "https",
and the port to 443 (this may not be necessary, but it was generating an URL with
a port of 80 before, which defeats the purpose so I decided to play it safe). 
It then feeds the generated URI to Response.Redirect(), and your off.  There
is some additional code in there to disable the feature if your on localhost, which
is mostly to keep from blowing up your dev box.
</p>
        <p>
Here is the class:
</p>
        <pre class="brush: csharp" name="code">using System;
using System.Configuration;
using System.Web;


namespace HTTPSRedirectHandler
{
    /// &lt;summary&gt;
    /// An HttpModule which redirects traffic to HTTPS based on configuration settings.
    /// &lt;/summary&gt;
    public class HttpsRedirector : IHttpModule
    {
        HttpApplication _context;

        public HttpsRedirector()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #region IHttpModule Members

        /// &lt;summary&gt;
        /// Initializes a module and prepares it to handle
        /// requests.
        /// &lt;/summary&gt;
        /// &lt;param name="context"&gt;An &lt;see cref="T:System.Web.HttpApplication"/&gt; that provides access to the methods, properties, and events common to all application objects within an ASP.NET application&lt;/param&gt;
        public void Init(HttpApplication context)
        {
            _context = context;
            _context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        /// &lt;summary&gt;
        /// Disposes of the resources (other than memory) used by the
        /// module that implements &lt;see langword="IHttpModule."/&gt;
        /// &lt;/summary&gt;
        public void Dispose()
        {
            _context.BeginRequest -= new EventHandler(context_BeginRequest);
            _context.Dispose();
        }

        #endregion

        /// &lt;summary&gt;
        /// Handles the BeginRequest event of the current Http Context.
        /// &lt;/summary&gt;
        private void context_BeginRequest(object sender, EventArgs e)
        {
            bool useSSL = false;
            string result = null;
            if((result = ConfigurationSettings.AppSettings["RequireSSL"]) != null)
            {
                if(result.ToUpper() == "TRUE" || result.ToUpper() == "YES")
                    useSSL = true;
            }
            if (useSSL)
                EnforceSSL();
        }

        /// &lt;summary&gt;
        /// Enforces a redirection to HTTPS if the current connection is using HTTP (port 80).
        /// &lt;/summary&gt;
        private void EnforceSSL()
        {
            if(_context.Request.ServerVariables["SERVER_NAME"].ToLower() != "localhost")
            {
                if(_context.Request.ServerVariables["SERVER_PORT"] == "80")
                {
                    UriBuilder uri = new UriBuilder(_context.Request.Url);
                    uri.Scheme = "https";
                    uri.Port = 443;
                    _context.Response.Redirect(uri.ToString());
                }
            }
        }
    }
}
</pre>
        <p>
          <a href="http://11011.net/software/vspaste">
          </a> 
</p>
        <p>
Here is the web.config settings you need to use it:
</p>
        <pre class="brush: xml" name="code">&lt;httpModules&gt;
    &lt;add name="SSLRedirect" type="HTTPSRedirectHandler.HttpsRedirector, HTTPSRedirectHandler" /&gt;<br />
&lt;/httpModules&gt;</pre>
        <pre class="xml" name="code"> </pre>
        <pre class="brush: xml" name="code">&lt;appSettings&gt;<br />
&lt;add key="RequireSSL" value="True" /&gt; &lt;/appSettings&gt;</pre>
        <p>
        </p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=11a503e2-ba17-47ad-baec-d238fd5dccb4" />
      </body>
      <title>Forcing redirection to HTTPS in ASP.Net</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,11a503e2-ba17-47ad-baec-d238fd5dccb4.aspx</guid>
      <link>http://www.drrandom.org/2007/08/17/ForcingRedirectionToHTTPSInASPNet.aspx</link>
      <pubDate>Fri, 17 Aug 2007 21:02:01 GMT</pubDate>
      <description>&lt;p&gt;
I ran into this issue today when trying to find a quick and dirty script to enforce
redirection from HTTP to HTTPS for an intranet site we're enabling for HTTPS (yes,
I know SSL on an intranet???&amp;nbsp; One word - Audit).&amp;nbsp; I thought this would be
easy...I half expected that there would be an IIS setting to handle this for me; I
was wrong on both counts.&amp;nbsp; So what I ended up doing is using an old DNN HttpModule
which was set up to allow the user to specify specific tabs in DNN for SSL, and greatly
simplifying things to work to my advantage.&amp;nbsp; I thought I would post it so I wouldn't
have to look for it again.
&lt;/p&gt;
&lt;p&gt;
To give a quick overview of what is going on, this is an HTTP Module which looks at
a value in the web.config to determine whether or not to enforce HTTPS or not.&amp;nbsp;
If the setting is set to true (or yes), then I'm just grabbing the Url property from
the Request object, loading it up in a UriBuilder, and setting the Scheme to "https",
and the port to 443 (this may not be necessary, but it was generating an URL with
a port of 80 before, which defeats the purpose so I decided to play it safe).&amp;nbsp;
It then feeds the generated URI to Response.Redirect(), and your off.&amp;nbsp; There
is some additional code in there to disable the feature if your on localhost, which
is mostly to keep from blowing up your dev box.
&lt;/p&gt;
&lt;p&gt;
Here is the class:
&lt;/p&gt;
&lt;pre class="brush: csharp" name="code"&gt;using System;
using System.Configuration;
using System.Web;


namespace HTTPSRedirectHandler
{
    /// &amp;lt;summary&amp;gt;
    /// An HttpModule which redirects traffic to HTTPS based on configuration settings.
    /// &amp;lt;/summary&amp;gt;
    public class HttpsRedirector : IHttpModule
    {
        HttpApplication _context;

        public HttpsRedirector()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        #region IHttpModule Members

        /// &amp;lt;summary&amp;gt;
        /// Initializes a module and prepares it to handle
        /// requests.
        /// &amp;lt;/summary&amp;gt;
        /// &amp;lt;param name="context"&amp;gt;An &amp;lt;see cref="T:System.Web.HttpApplication"/&amp;gt; that provides access to the methods, properties, and events common to all application objects within an ASP.NET application&amp;lt;/param&amp;gt;
        public void Init(HttpApplication context)
        {
            _context = context;
            _context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        /// &amp;lt;summary&amp;gt;
        /// Disposes of the resources (other than memory) used by the
        /// module that implements &amp;lt;see langword="IHttpModule."/&amp;gt;
        /// &amp;lt;/summary&amp;gt;
        public void Dispose()
        {
            _context.BeginRequest -= new EventHandler(context_BeginRequest);
            _context.Dispose();
        }

        #endregion

        /// &amp;lt;summary&amp;gt;
        /// Handles the BeginRequest event of the current Http Context.
        /// &amp;lt;/summary&amp;gt;
        private void context_BeginRequest(object sender, EventArgs e)
        {
            bool useSSL = false;
            string result = null;
            if((result = ConfigurationSettings.AppSettings["RequireSSL"]) != null)
            {
                if(result.ToUpper() == "TRUE" || result.ToUpper() == "YES")
                    useSSL = true;
            }
            if (useSSL)
                EnforceSSL();
        }

        /// &amp;lt;summary&amp;gt;
        /// Enforces a redirection to HTTPS if the current connection is using HTTP (port 80).
        /// &amp;lt;/summary&amp;gt;
        private void EnforceSSL()
        {
            if(_context.Request.ServerVariables["SERVER_NAME"].ToLower() != "localhost")
            {
                if(_context.Request.ServerVariables["SERVER_PORT"] == "80")
                {
                    UriBuilder uri = new UriBuilder(_context.Request.Url);
                    uri.Scheme = "https";
                    uri.Port = 443;
                    _context.Response.Redirect(uri.ToString());
                }
            }
        }
    }
}
&lt;/pre&gt;
&lt;p&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Here is the web.config settings you need to use it:
&lt;/p&gt;
&lt;pre class="brush: xml" name="code"&gt;&amp;lt;httpModules&amp;gt;
    &amp;lt;add name="SSLRedirect" type="HTTPSRedirectHandler.HttpsRedirector, HTTPSRedirectHandler" /&amp;gt;&lt;br&gt;
&amp;lt;/httpModules&amp;gt;&lt;/pre&gt;&lt;pre class="xml" name="code"&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class="brush: xml" name="code"&gt;&amp;lt;appSettings&amp;gt;&lt;br&gt;
&amp;lt;add key="RequireSSL" value="True" /&amp;gt; &amp;lt;/appSettings&amp;gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=11a503e2-ba17-47ad-baec-d238fd5dccb4" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,11a503e2-ba17-47ad-baec-d238fd5dccb4.aspx</comments>
      <category>tips</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=d33d038e-731c-44d2-a2cd-96c52024365a</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,d33d038e-731c-44d2-a2cd-96c52024365a.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,d33d038e-731c-44d2-a2cd-96c52024365a.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=d33d038e-731c-44d2-a2cd-96c52024365a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
So I had this analogy pop into my head a while back and I've been sitting on it because,
quite frankly, I was almost embarrassed to have thought of it.  I finally decided
that I might as well post it since no one is going to read this anyway, so here goes:
</p>
        <p>
Writing software without TDD is like having unprotected sex.  Its extremely irresponsible
in this day and age when everyone is supposed to know better, but it still happens
a lot.  Sure, it feels better, and let's face it in the heat of the moment
you really don't want to take the time to make sure you've taken all of the right
precautions...you might loose your edge.  The problem is if we don't <a href="http://www.drrandom.org/blog_images/ProtectYourselfUseTDD_140F8/condoms450744170.jpg" atomicselection="true"><img style="border-right: 0px; border-top: 0px; margin: 5px 0px 0px 10px; border-left: 0px; border-bottom: 0px" height="111" alt="condoms-450-744170" src="http://www.drrandom.org/blog_images/ProtectYourselfUseTDD_140F8/condoms450744170_thumb.jpg" width="148" align="right" border="0" /></a>do
it we have that lingering fear in the back of our minds, that "What if?" that keeps
popping up at the worst moments.  Most of the time its okay, and everything is
fine, but it only takes one time for things to go wrong to make you regret your decisions. 
</p>
        <p>
So come on folks, we all know what we should be doing, so no more making excuses. 
After a while you get used to it, and you find that the peace of mind it gives
you far outweighs the momentary delights of living on the wild side.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=d33d038e-731c-44d2-a2cd-96c52024365a" />
      </body>
      <title>Protect Yourself - Use TDD</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,d33d038e-731c-44d2-a2cd-96c52024365a.aspx</guid>
      <link>http://www.drrandom.org/2007/07/18/ProtectYourselfUseTDD.aspx</link>
      <pubDate>Wed, 18 Jul 2007 06:33:57 GMT</pubDate>
      <description>&lt;p&gt;
So I had this analogy pop into my head a while back and I've been sitting on it because,
quite frankly, I was almost embarrassed to have thought of it.&amp;nbsp; I finally decided
that I might as well post it since no one is going to read this anyway, so here goes:
&lt;/p&gt;
&lt;p&gt;
Writing software without TDD is like having unprotected sex.&amp;nbsp; Its extremely irresponsible
in this day and age when everyone is supposed to&amp;nbsp;know better, but it still happens
a lot.&amp;nbsp; Sure, it feels better, and let's&amp;nbsp;face it in the heat of the moment
you really don't want to take the time to make sure you've taken all of the right
precautions...you might loose your edge.&amp;nbsp; The problem is if we don't &lt;a href="http://www.drrandom.org/blog_images/ProtectYourselfUseTDD_140F8/condoms450744170.jpg" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 5px 0px 0px 10px; border-left: 0px; border-bottom: 0px" height="111" alt="condoms-450-744170" src="http://www.drrandom.org/blog_images/ProtectYourselfUseTDD_140F8/condoms450744170_thumb.jpg" width="148" align="right" border="0"&gt;&lt;/a&gt;do
it we have that lingering fear in the back of our minds, that "What if?" that keeps
popping up at the worst moments.&amp;nbsp; Most of the time its okay, and everything is
fine, but it only takes one time for things to go wrong to make you regret your decisions. 
&lt;/p&gt;
&lt;p&gt;
So come on folks, we all know what we should be doing, so no more making excuses.&amp;nbsp;
After&amp;nbsp;a while you get used to it, and you find that the peace of mind it gives
you far outweighs the momentary delights of living on the wild side.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=d33d038e-731c-44d2-a2cd-96c52024365a" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,d33d038e-731c-44d2-a2cd-96c52024365a.aspx</comments>
      <category>TDD</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=85ea64f1-6bb7-4046-9045-506697093ddd</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,85ea64f1-6bb7-4046-9045-506697093ddd.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,85ea64f1-6bb7-4046-9045-506697093ddd.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=85ea64f1-6bb7-4046-9045-506697093ddd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I recently decided to take the plunge and get <a href="http://www.devexpress.com/Products/NET/IDETools/CodeRush/Index.xml">CodeRush</a> and <a href="http://www.devexpress.com/Products/NET/IDETools/Refactor/Index.xml">Refactor!
Pro</a> (along with <a href="http://www.devexpress.com/Products/NET/IDETools/DXCore/Index.xml">DxCore</a>) loaded
instead of <a href="http://www.jetbrains.com/resharper/">Resharper</a>.  Now,
don't get me wrong, there is a lot I like about Resharper, but overall the performance
was becoming an issue.  There were often problems with VS freezing for no
particular reason, and then coming back as if nothing was wrong...I swear it was like
my IDE had narcolepsy or something.
</p>
        <p>
One of the things I noticed immediately about CodeRush was the fact that there was
a single installer, and when I went to run it I was able to install it on all versions
of Visual Studio, including the Orcas Beta.  This was nice when compared to Resharper's
separate install for vs 2005 and vs 2003.  It also makes me feel good about improvements
in the product being available for all versions of the IDE.  One thing that I
noticed about R# was that there was some work being done in the VS 2005 version around
performance, but that did not seem to trickle down to the VS 2003 version.  I
think the big reason for this is the fact that CodeRush and Refactor! are implemented
on top of DxCore, which provides a very clean abstraction from the scariness that
is the Visual Studio integration layer.
</p>
        <p>
Here are the things I really like about CodeRush/Refactor:<br /></p>
        <ul>
          <li>
The visualizations are stunning!  No, seriously this is some amazing stuff. 
Circles, arrows, animations, eye candy yes, but useful eye candy.</li>
          <li>
The Refactoring Live Preview is crazy brilliant.  <a href="http://www.doitwith.net/">Mark
Miller</a> mentioned this on a <a href="http://www.dotnetrocks.com/default.aspx?showNum=185">DNR
episode</a>, and I agree with his comment that the live preview allows you to discover
new useful refactorings that may not be completely obvious from the name.</li>
          <li>
Performance is great.  'Nuf said.</li>
          <li>
It works with VB.Net.  Granted I don't use VB.Net, but some of my co-workers
do, and occasionally I have to work on VB.Net projects.</li>
          <li>
Dynamic Templates rock.  The fact that I can create a new mnemonic for my type,
and then use predefined prefixes and do <font face="Consolas" color="#808080">vee&lt;space&gt;</font> to
create a new Employee Entity for example is pure bliss.</li>
          <li>
Template contexts are way cool.  By default they have NUnit templates defined,
and with contexts, <font color="#808080">t&lt;space&gt;</font> creates both a TestFixture
class and a Test method</li>
          <li>
Markers and navigation are dreamy.</li>
          <li>
There are some crazy-cool template functions, like the ability to do a foreach within
a template, so things like creating a switch/case statement for all items in an enum
can be done easily.  This also powers a conditional to case refactoring that
is pretty sweet.</li>
        </ul>
        <p>
Here are the things that I miss from Resharper:
</p>
        <ul>
          <li>
Automatically adding a using statement in VS 2003 was sweet.  VS 2005 can do
it with the buit-in intellisense features, but I got very used to it.</li>
          <li>
The VS 2003 test runner was very nice.  I use the <a href="http://www.testdriven.net/">Testdriven.Net</a> plugin,
which I cannot live without, but I like the graphical runner in the IDE.  The <a href="http://www.jetbrains.com/unitrun/">free
test runner</a> from JetBrains is for VS 2005 only, so it doesn't help those of us
in VS 2003.  I do like the fact that they released it as a free tool, though.</li>
          <li>
The "Extract Field" refactoring doesn't exist in Refactor!...This shocked me a lot.</li>
          <li>
The Find Usages task.  This I think is part of the reason why R# was slow, but
it did a brilliant job.  I think the rename in R# was more powerful as well. 
I think there is a rename in Beta for Refactor! that is supposed to be able to work
accross an entire project/solution, but I haven't had a chance to really test it yet.</li>
          <li>
The pre-build error checking is nice.</li>
        </ul>
        <p>
The good news is that the DxCore extensibility model means that most if not all of
these items could be recreated.  The bad news is that there isn't a lot of documentation
around the extensibility model, particularly when it comes to creating new refactorings. 
The test runner is one of the most painful points for me right now, so I've started
exploring the process of creating one using the DxCore APIs.  It opens up the
possibility of refining things too, which would be nice.  What I would really
like would be the ability to detect and integrate with TestDriven.Net.
</p>
        <p>
The folks over at <a href="http://blog.eleutian.com/">Eleutian</a> are evidently <a href="http://blog.eleutian.com/2007/01/28/ProductivityToolsPart1.aspx">running
both</a>, which they claim is possible with some tweaking, but the performance
issues for VS 2003 are the biggest downer on the R# side, so I will probably not go
down that path.  I may load up the test runner for VS 2005, unless I get some
time to try and build one using DxCore, in which case I'll share it with the rest
of the world.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=85ea64f1-6bb7-4046-9045-506697093ddd" />
      </body>
      <title>Taking the CodeRush Plunge</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,85ea64f1-6bb7-4046-9045-506697093ddd.aspx</guid>
      <link>http://www.drrandom.org/2007/07/13/TakingTheCodeRushPlunge.aspx</link>
      <pubDate>Fri, 13 Jul 2007 15:00:21 GMT</pubDate>
      <description>&lt;p&gt;
I recently decided to take the plunge and get &lt;a href="http://www.devexpress.com/Products/NET/IDETools/CodeRush/Index.xml"&gt;CodeRush&lt;/a&gt; and &lt;a href="http://www.devexpress.com/Products/NET/IDETools/Refactor/Index.xml"&gt;Refactor!
Pro&lt;/a&gt; (along with &lt;a href="http://www.devexpress.com/Products/NET/IDETools/DXCore/Index.xml"&gt;DxCore&lt;/a&gt;)&amp;nbsp;loaded
instead of &lt;a href="http://www.jetbrains.com/resharper/"&gt;Resharper&lt;/a&gt;.&amp;nbsp; Now,
don't get me wrong, there is a lot&amp;nbsp;I like about Resharper, but overall the performance
was becoming an&amp;nbsp;issue.&amp;nbsp; There were often problems with VS freezing for no
particular reason, and then coming back as if nothing was wrong...I swear it was like
my IDE had narcolepsy or something.
&lt;/p&gt;
&lt;p&gt;
One of the things I noticed immediately about CodeRush was the fact that there was
a single installer, and when I went to run it I was able to install it on all versions
of Visual Studio, including the Orcas Beta.&amp;nbsp; This was nice when compared to Resharper's
separate install for vs 2005 and vs 2003.&amp;nbsp; It also makes me feel good about improvements
in the product being available for all versions of the IDE.&amp;nbsp; One thing that I
noticed about R# was that there was some work being done in the VS 2005 version around
performance, but that did not seem to trickle down to the VS 2003 version.&amp;nbsp; I
think the big reason for this is the fact that CodeRush and Refactor! are implemented
on top of DxCore, which provides a very clean abstraction from the scariness that
is the Visual Studio integration layer.
&lt;/p&gt;
&lt;p&gt;
Here are the things I really like about CodeRush/Refactor:&lt;br&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The visualizations are stunning!&amp;nbsp; No, seriously this is some amazing stuff.&amp;nbsp;
Circles, arrows, animations, eye candy yes, but useful eye candy.&lt;/li&gt;
&lt;li&gt;
The Refactoring Live Preview is crazy brilliant.&amp;nbsp; &lt;a href="http://www.doitwith.net/"&gt;Mark
Miller&lt;/a&gt; mentioned this on a &lt;a href="http://www.dotnetrocks.com/default.aspx?showNum=185"&gt;DNR
episode&lt;/a&gt;, and I agree with his comment that the live preview allows you to discover
new useful refactorings that may not be completely obvious from the name.&lt;/li&gt;
&lt;li&gt;
Performance is great.&amp;nbsp; 'Nuf said.&lt;/li&gt;
&lt;li&gt;
It works with VB.Net.&amp;nbsp; Granted I don't use VB.Net, but some of my co-workers
do, and occasionally I have to work on VB.Net projects.&lt;/li&gt;
&lt;li&gt;
Dynamic Templates rock.&amp;nbsp; The fact that I can create a new mnemonic for my type,
and then use predefined prefixes and do &lt;font face="Consolas" color="#808080"&gt;vee&amp;lt;space&amp;gt;&lt;/font&gt; to
create a new Employee Entity for example is pure bliss.&lt;/li&gt;
&lt;li&gt;
Template contexts are way cool.&amp;nbsp; By default they have NUnit templates defined,
and with contexts, &lt;font color="#808080"&gt;t&amp;lt;space&amp;gt;&lt;/font&gt; creates both a TestFixture
class and a Test method&lt;/li&gt;
&lt;li&gt;
Markers and navigation are dreamy.&lt;/li&gt;
&lt;li&gt;
There are some crazy-cool template functions, like the ability to do a foreach within
a template, so things like creating a switch/case statement for all items in an enum
can be done easily.&amp;nbsp; This also powers a conditional to case refactoring that
is pretty sweet.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Here are the things that I miss from Resharper:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Automatically adding a using statement in VS 2003 was sweet.&amp;nbsp; VS 2005 can do
it with the buit-in intellisense features, but I got very used to it.&lt;/li&gt;
&lt;li&gt;
The VS 2003 test runner was very nice.&amp;nbsp; I use the &lt;a href="http://www.testdriven.net/"&gt;Testdriven.Net&lt;/a&gt; plugin,
which I cannot live without, but I like the graphical runner in the IDE.&amp;nbsp; The &lt;a href="http://www.jetbrains.com/unitrun/"&gt;free
test runner&lt;/a&gt; from JetBrains is for VS 2005 only, so it doesn't help those of us
in VS 2003.&amp;nbsp; I do like the fact that they released it as a free tool, though.&lt;/li&gt;
&lt;li&gt;
The "Extract Field" refactoring doesn't exist in Refactor!...This shocked me a lot.&lt;/li&gt;
&lt;li&gt;
The Find Usages task.&amp;nbsp; This I think is part of the reason why R# was slow, but
it did a brilliant job.&amp;nbsp; I think the rename in R# was more powerful as well.&amp;nbsp;
I think there is a rename in Beta for Refactor! that is supposed to be able to work
accross an entire project/solution, but I haven't had a chance to really test it yet.&lt;/li&gt;
&lt;li&gt;
The pre-build error checking is nice.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The good news is that the DxCore extensibility model means that most if not all of
these items could be recreated.&amp;nbsp; The bad news is that there isn't a lot of documentation
around the extensibility model, particularly when it comes to creating new refactorings.&amp;nbsp;
The test runner is one of the most painful points for me right now, so I've started
exploring the process of creating one using the DxCore APIs.&amp;nbsp; It opens up the
possibility of refining things too, which would be nice.&amp;nbsp; What I would really
like would be the ability to detect and integrate with TestDriven.Net.
&lt;/p&gt;
&lt;p&gt;
The folks over at &lt;a href="http://blog.eleutian.com/"&gt;Eleutian&lt;/a&gt; are evidently &lt;a href="http://blog.eleutian.com/2007/01/28/ProductivityToolsPart1.aspx"&gt;running
both&lt;/a&gt;, which they claim is possible with some tweaking,&amp;nbsp;but the performance
issues for VS 2003 are the biggest downer on the R# side, so I will probably not go
down that path.&amp;nbsp; I may load up the test runner for VS 2005, unless I get some
time to try and build one using DxCore, in which case I'll share it with the rest
of the world.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=85ea64f1-6bb7-4046-9045-506697093ddd" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,85ea64f1-6bb7-4046-9045-506697093ddd.aspx</comments>
      <category>.Net</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=27b621b5-13b5-4fd0-9522-38a7b8f40d9e</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,27b621b5-13b5-4fd0-9522-38a7b8f40d9e.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,27b621b5-13b5-4fd0-9522-38a7b8f40d9e.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=27b621b5-13b5-4fd0-9522-38a7b8f40d9e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
So if you recall from some of my earlier posts, I've talked about the concept of the
"Friend" class in C++ and how it could apply to TDD within .Net.  Well, today,
with the help of Roy Osherove, I just stumbled upon the <a title="InternalsVisibleToAttribute" href="http://msdn2.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx" target="_blank">InternalsVisibleToAttribute</a> within
.Net 2.0.  This allows you to specify within one assembly, another assembly that
should have access to the <strong>internal</strong> members of your assembly. 
This is genius, and goes a long way towards allowing you to keep your code encapsulated,
while still being testable.  If we could just get them to go one step farther,
and allow for access to private and protected members as well, life would be good,
and there would be no more of this OOD vs TOOD junk.
</p>
        <p>
The other interesting thing about this is that it could allow you to give a separate
utility...say the Castle Microkernel, access to internal class constructors, and thus
enforce creation of your objects through the Kernel from outside assemblies. 
This is actually a feature I am desperately wanting in my current project,  but
sadly, I am limited to .Net 1.1, so I can't quite get there.
</p>
        <p>
Here is a quick look at how this works.  Here is a very unrealistic class in
an assembly that I want to test: 
</p>
        <pre class="brush: csharp">class TestClass
{
    internal TestClass()
    {}

    private bool PrivateMethod()
    {
        return false;
    }

    internal bool SomeMethod()
    {
        return true;
    }

    public string PublicMethod()
    {
        return "You can see me";
    }
}
</pre>
Now, I add the following to the AssemblyInfo.cs file: <pre class="brush: csharp">[assembly: InternalsVisibleTo("TestAssembly")]
</pre><p>
And here is what Intellisense looks like in my test class<br /><a href="http://www.drrandom.org/content/binary/InternalVisibleIntellisense.png" atomicselection="true"><img style="border-width: 0px;" src="http://www.drrandom.org/content/binary/InternalVisibleIntellisense.png" border="0" height="248" width="576" /></a></p>
Not bad.  Overall I would say this is defiantly a good feature to have in your
toolbox.  Internals are not perfect, but they are much more versatile than a
lot of folks give them credit for.  Now if only I could get something like this
in .Net 1.1<img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=27b621b5-13b5-4fd0-9522-38a7b8f40d9e" /></body>
      <title>More On Testing and &amp;quot;Friend&amp;quot; Assemblies</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,27b621b5-13b5-4fd0-9522-38a7b8f40d9e.aspx</guid>
      <link>http://www.drrandom.org/2007/06/18/MoreOnTestingAndQuotFriendquotAssemblies.aspx</link>
      <pubDate>Mon, 18 Jun 2007 15:33:09 GMT</pubDate>
      <description>&lt;p&gt;
So if you recall from some of my earlier posts, I've talked about the concept of the
"Friend" class in C++ and how it could apply to TDD within .Net.&amp;nbsp; Well, today,
with&amp;nbsp;the help of Roy Osherove,&amp;nbsp;I just stumbled upon the &lt;a title="InternalsVisibleToAttribute" href="http://msdn2.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx" target="_blank"&gt;InternalsVisibleToAttribute&lt;/a&gt;&amp;nbsp;within
.Net 2.0.&amp;nbsp; This allows you to specify within one assembly, another assembly that
should have access to the &lt;strong&gt;internal&lt;/strong&gt; members of your assembly.&amp;nbsp;
This is genius, and goes a long way towards allowing you to keep your code encapsulated,
while still being testable.&amp;nbsp; If we could just get them to go one step farther,
and allow for access to private and protected members as well, life would be good,
and there would be no more of this OOD vs TOOD junk.
&lt;/p&gt;
&lt;p&gt;
The other interesting thing about this is that it could allow you to give a separate
utility...say the Castle Microkernel, access to internal class constructors, and thus
enforce creation of your objects through the Kernel from outside assemblies.&amp;nbsp;
This is actually a feature I am desperately wanting in my current project,&amp;nbsp; but
sadly, I am limited to .Net 1.1, so I can't quite get there.
&lt;/p&gt;
&lt;p&gt;
Here is a quick look at how this works.&amp;nbsp; Here is a very unrealistic class in
an assembly that I want to test: 
&lt;/p&gt;
&lt;pre class="brush: csharp"&gt;class TestClass
{
    internal TestClass()
    {}

    private bool PrivateMethod()
    {
        return false;
    }

    internal bool SomeMethod()
    {
        return true;
    }

    public string PublicMethod()
    {
        return "You can see me";
    }
}
&lt;/pre&gt;
Now, I add the following to the AssemblyInfo.cs file: &lt;pre class="brush: csharp"&gt;[assembly: InternalsVisibleTo("TestAssembly")]
&lt;/pre&gt;
&lt;p&gt;
And here is what Intellisense looks like in my test class&lt;br&gt;
&lt;a href="http://www.drrandom.org/content/binary/InternalVisibleIntellisense.png" atomicselection="true"&gt;&lt;img style="border-width: 0px;" src="http://www.drrandom.org/content/binary/InternalVisibleIntellisense.png" border="0" height="248" width="576"&gt;&lt;/a&gt; 
&lt;/p&gt;
Not bad.&amp;nbsp; Overall I would say this is defiantly a good feature to have in your
toolbox.&amp;nbsp; Internals are not perfect, but they are much more versatile than a
lot of folks give them credit for.&amp;nbsp; Now if only I could get something like this
in .Net 1.1&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=27b621b5-13b5-4fd0-9522-38a7b8f40d9e" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,27b621b5-13b5-4fd0-9522-38a7b8f40d9e.aspx</comments>
      <category>.Net</category>
      <category>TDD</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=208c2048-ba7a-4bde-bac7-37f52b5420cc</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,208c2048-ba7a-4bde-bac7-37f52b5420cc.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,208c2048-ba7a-4bde-bac7-37f52b5420cc.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=208c2048-ba7a-4bde-bac7-37f52b5420cc</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The project I'm working on now has a huge need for auto-update.  Strangely enough,
there aren't a whole lot of documented solutions for an auto-update application for
.Net 1.1.  In the 2.0 world you have ClickOnce, which handles those sorts of
things for you (and in a way that isn't terribly difficult to manage as a developer...as
long as you pay attention to what your doing), but the only real option you get from
MS on this is the AutoUpdater Application Block from the Patterns and Practices guys. 
I took a look at this when it was in it's 1.0 version a while back, and really didn't
care for it much.  The big reason was that it required you set up an AppStart.exe
file, which would take a look at your config file to determine which directory to
start the app from.  When updates arrived, they were put in new directories based
on versions.  This seemed like a lot of effort, and a lot of overhead. 
The good news is that there is now a 2.0 version of the application block, and it
looks like it is much more configurable, and has the ability to do inproc updates.
</p>
        <p>
So here is my issue.  I want to change the default downloader (used to retrieve
the updated files) from the BITSDownloader that ships with the block to one which
will allow me to copy files from a UNC path.  Fortunately, a sample implementation
of such a thing exists in the documentation, so there is a starting point.  It
is pretty rough around the edges, and isn't testable, so I am working creating a nicer,
testable version of the sample downloader.  Here is the problem, though; the
dependencies are insane!  And it doesn't look like even mock objects will be
able to help.  Initially I found this a little strange since I know that the
Patterns and Practices group was headed up by some folks who were heavy into the Agile
methodologies.  I also know for a fact that the Enterprise Library components
have test included.  So I pulled up the AutoUpdater Application Block to see
how they were testing things....and what do you think I found?  They were not
testing anything!  I can only assume that the updater block came from another
group, because there was no tests in sight.  So, since I had the source code,
I'm reduced to making modifications to the block to support testing.  For the
most part this involved marking public methods/properties as virtual so that Rhino.Mocks
can mock them.  I also added some parameters to the constructor of the UpdateTask
class so that I could supply mock versions of some of the dependencies.
</p>
        <p>
I can't imagine trying to test this without the source code to modify...as it stands
I don't feel real good about shipping around a non-standard version of the library. 
Overall I'm quite disappointed in the P&amp;P folks on this one.  I had high
hopes whenever I saw the rest of the Enterprise Library that I would be able to test
my extensions fairly easily.  I guess that goes to show that even in organizations
(or specifically groups) where TDD is a best practice, it still is finding hurdles
to acceptance.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=208c2048-ba7a-4bde-bac7-37f52b5420cc" />
      </body>
      <title>Struggles with the UpdaterApplicationBlock</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,208c2048-ba7a-4bde-bac7-37f52b5420cc.aspx</guid>
      <link>http://www.drrandom.org/2007/06/11/StrugglesWithTheUpdaterApplicationBlock.aspx</link>
      <pubDate>Mon, 11 Jun 2007 18:53:07 GMT</pubDate>
      <description>&lt;p&gt;
The project I'm working on now has a huge need for auto-update.&amp;nbsp; Strangely enough,
there aren't a whole lot of documented solutions for an auto-update application for
.Net 1.1.&amp;nbsp; In the 2.0 world you have ClickOnce, which handles those sorts of
things for you (and in a way that isn't terribly difficult to manage as a developer...as
long as you pay attention to what your doing), but the only real option you get from
MS on this is the AutoUpdater Application Block from the Patterns and Practices guys.&amp;nbsp;
I took a look at this when it was in it's 1.0 version a while back, and really didn't
care for it much.&amp;nbsp; The big reason was that it required you set up an AppStart.exe
file, which would take a look at your config file to determine which directory to
start the app from.&amp;nbsp; When updates arrived, they were put in new directories based
on versions.&amp;nbsp; This seemed like a lot of effort, and a lot of overhead.&amp;nbsp;
The good news is that there is now a 2.0 version of the application block, and it
looks like it is much more configurable, and has the ability to do inproc updates.
&lt;/p&gt;
&lt;p&gt;
So here is my issue.&amp;nbsp; I want to change the default downloader (used to retrieve
the updated files) from the BITSDownloader that ships with the block to one which
will allow me to copy files from a UNC path.&amp;nbsp; Fortunately, a sample implementation
of such a thing exists in the documentation, so there is a starting point.&amp;nbsp; It
is pretty rough around the edges, and isn't testable, so I am working creating a nicer,
testable version of the sample downloader.&amp;nbsp; Here is the problem, though; the
dependencies are insane!&amp;nbsp; And it doesn't look like even mock objects will be
able to help.&amp;nbsp; Initially I found this a little strange since I know that the
Patterns and Practices group was headed up by some folks who were heavy into the Agile
methodologies.&amp;nbsp; I also know for a fact that the Enterprise Library components
have test included.&amp;nbsp; So I pulled up the AutoUpdater Application Block to see
how they were testing things....and what do you think I found?&amp;nbsp; They were not
testing anything!&amp;nbsp; I can only assume that the updater block came from another
group, because there was no tests in sight.&amp;nbsp; So, since I had the source code,
I'm reduced to making modifications to the block to support testing.&amp;nbsp; For the
most part this involved marking public methods/properties as virtual so that Rhino.Mocks
can mock them.&amp;nbsp; I also added some parameters to the constructor of the UpdateTask
class so that I could supply mock versions of some of the dependencies.
&lt;/p&gt;
&lt;p&gt;
I can't imagine trying to test this without the source code to modify...as it stands
I don't feel real good about shipping around a non-standard version of the library.&amp;nbsp;
Overall I'm quite disappointed in the P&amp;amp;P folks on this one.&amp;nbsp; I had high
hopes whenever I saw the rest of the Enterprise Library that I would be able to test
my extensions fairly easily.&amp;nbsp; I guess that goes to show that even in organizations
(or specifically groups) where TDD is a best practice, it still is finding hurdles
to acceptance.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=208c2048-ba7a-4bde-bac7-37f52b5420cc" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,208c2048-ba7a-4bde-bac7-37f52b5420cc.aspx</comments>
      <category>.Net</category>
      <category>TDD</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=f8982bdd-c3ab-4463-927b-314a7810cc80</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,f8982bdd-c3ab-4463-927b-314a7810cc80.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,f8982bdd-c3ab-4463-927b-314a7810cc80.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=f8982bdd-c3ab-4463-927b-314a7810cc80</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been doing a lot of poking around the <a href="http://www.mythtv.org">MythTV</a> and <a href="http://www.mysettopbox.tv/knoppmyth.html">Knoppmyth</a> sites
recently trying to figure out what is going to work best in my current situation. 
Since I've got cable, and not satellite, it would seem that it is possible to get
all of the non-encrypted content from my provider, as long as I have a capture card
with QAM support.  These cards seem to be HD cards overall (at least I haven't
found one that is supported that is not HD), which makes sense given the QAM signal
will be a digital signal.  It sounds like getting the channel mapping put together
for the QAM content can be somewhat tedious depending on how well Myth can auto-discover
your channels (which it would seem is not that good), so I know there is some work
involved in getting the digital channels.  For analog, any of the supported analog
capture cards would work, and it seems that my wife and I tend to watch more of the
analog stations than the digital (though, in my current line-up all of the "expanded"
cable stations (Discovery, Comedy Central, TBS, etc) have both an analog station and
a digital station...pretty strange.  I also know that I want the ability to watch
and record at the same time, which means at least two tuners.  Here is the trick,
though, since I need different tuners for digital vs analog, how many tuners do I
really need?  And how many PCI slots do I want to eat up in the quest for multiple
record?
</p>
        <p>
So here is what I've decided.  Since I'm mostly concerned with analog, I went
with a <a href="http://www.hauppauge.com">Hauppauge</a> WinTV PVR-500, which is a
dual-tuner analog PCI card, and which seems to be supported just fine in myth (looks
like two PVR-150 cards from the sound of it).  That by itself takes care of my
analog needs.  As for the digital, I haven't decided for sure yet, but I'm leaning
towards the <a href="http://www.fusionhdtv.co.kr/eng/Products/RTLite.aspx">DVICO FusionHDTV
RT Lite,</a> which seems to have good support in Myth.  It also has the advantage
of being one of the few HD cards with a hardware encoder.
</p>
        <p>
I should take a step back here and explain this.  You have two choices when watching
or recording TV on a PC.  You can have your machine take care of encoding and
decoding the MPEG4 video that is your TV show, or you can let the capture card do
it.  If you let the capture card do it, then your machine is going to not be
nearly as busy as it would otherwise.  This presents a couple advantages: 1. 
You can get away with less horse-power on the machine, which means parts will be cheaper
(spend the cash on storage if you can). 2. You're machine will consume less power
(I'm talking wattage here), and so therefore you are less likely to have a machine
in your living room that sounds like a Lear jet taking off when your trying to watch
all of your recorded episodes of "Eating bugs with the Stars", or whatever the latest
reality fad is.  
</p>
        <p>
The PVR-500 contains a hardware encoder, so if I can get the same thing on the digital
side, I'll be in good shape.  While I'm on the subject of power, I'm also seriously
looking at an AMD Turion based system.  This is the AMD mobile processor, so
it is designed with a low-power footprint in mind.  It also seems that there
are several motherboards out there which will support it, and some additional components
which will help keep it cool.  The only other major sources of noise are the
power-supply, and the hard-drive.  Cooler-Master makes some nice quite power
supplies, so I will probably check there first.  As for hard drives, I haven't
really started looking yet.  If I can find noise specs on them, then I may use
that as a criteria when deciding which to buy, but my primary concern is how many
GB can I get for my money.
</p>
        <p>
The other components have been moved to the end of the decision-tree.  I like
the Sliverstone cases I mentioned in my last post, but I decided that I should get
the components together first, since I didn't really want to end up with a nice-looking
case where I couldn't fit all of my goodies.  I also need to decide whether or
not to go with a DVD writer in the case....could be handy, but then I can also grab
stuff off the network, so is it really needed (I've got a CD writer lying around,
which may be my stand-in for a while)?
</p>
        <p>
Overall this is going to be a fun project, and lets face it, how often do you get
a geek project that your wife is behind 100%?
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=f8982bdd-c3ab-4463-927b-314a7810cc80" />
      </body>
      <title>Linux PVR - Part 2</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,f8982bdd-c3ab-4463-927b-314a7810cc80.aspx</guid>
      <link>http://www.drrandom.org/2007/06/10/LinuxPVRPart2.aspx</link>
      <pubDate>Sun, 10 Jun 2007 13:17:08 GMT</pubDate>
      <description>&lt;p&gt;
I've been doing a lot of poking around the &lt;a href="http://www.mythtv.org"&gt;MythTV&lt;/a&gt; and &lt;a href="http://www.mysettopbox.tv/knoppmyth.html"&gt;Knoppmyth&lt;/a&gt; sites
recently trying to figure out what is going to work best in my current situation.&amp;nbsp;
Since I've got cable, and not satellite, it would seem that it is possible to get
all of the non-encrypted content from my provider, as long as I have a capture card
with QAM support.&amp;nbsp; These cards seem to be HD cards overall (at least I haven't
found one that is supported that is not HD), which makes sense given the QAM signal
will be a digital signal.&amp;nbsp; It sounds like getting the channel mapping put together
for the QAM content can be somewhat tedious depending on how well Myth can auto-discover
your channels (which it would seem is not that good), so I know there is some work
involved in getting the digital channels.&amp;nbsp; For analog, any of the supported analog
capture cards would work, and it seems that my wife and I tend to watch more of the
analog stations than the digital (though, in my current line-up all of the "expanded"
cable stations (Discovery, Comedy Central, TBS, etc) have both an analog station and
a digital station...pretty strange.&amp;nbsp; I also know that I want the ability to watch
and record at the same time, which means at least two tuners.&amp;nbsp; Here is the trick,
though, since I need different tuners for digital vs analog, how many tuners do I
really need?&amp;nbsp; And how many PCI slots do I want to eat up in the quest for multiple
record?
&lt;/p&gt;
&lt;p&gt;
So here is what I've decided.&amp;nbsp; Since I'm mostly concerned with analog, I went
with a &lt;a href="http://www.hauppauge.com"&gt;Hauppauge&lt;/a&gt; WinTV PVR-500, which is a
dual-tuner analog PCI card, and which seems to be supported just fine in myth (looks
like two PVR-150 cards from the sound of it).&amp;nbsp; That by itself takes care of my
analog needs.&amp;nbsp; As for the digital, I haven't decided for sure yet, but I'm leaning
towards the &lt;a href="http://www.fusionhdtv.co.kr/eng/Products/RTLite.aspx"&gt;DVICO FusionHDTV
RT Lite,&lt;/a&gt; which seems to have good support in Myth.&amp;nbsp; It also has the advantage
of being one of the few HD cards with a hardware encoder.
&lt;/p&gt;
&lt;p&gt;
I should take a step back here and explain this.&amp;nbsp; You have two choices when watching
or recording TV on a PC.&amp;nbsp; You can have your machine take care of encoding and
decoding the MPEG4 video that is your TV show, or you can let the capture card do
it.&amp;nbsp; If you let the capture card do it, then your machine is going to not be
nearly as busy as it would otherwise.&amp;nbsp; This presents a couple advantages: 1.&amp;nbsp;
You can get away with less horse-power on the machine, which means parts will be cheaper
(spend the cash on storage if you can). 2. You're machine will consume less power
(I'm talking wattage here), and so therefore you are less likely to have a machine
in your living room that sounds like a Lear jet taking off when your trying to watch
all of your recorded episodes of "Eating bugs with the Stars", or whatever the latest
reality fad is.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
The PVR-500 contains a hardware encoder, so if I can get the same thing on the digital
side, I'll be in good shape.&amp;nbsp; While I'm on the subject of power, I'm also seriously
looking at an AMD Turion based system.&amp;nbsp; This is the AMD mobile processor, so
it is designed with a low-power footprint in mind.&amp;nbsp; It also seems that there
are several motherboards out there which will support it, and some additional components
which will help keep it cool.&amp;nbsp; The only other major sources of noise are the
power-supply, and the hard-drive.&amp;nbsp; Cooler-Master makes some nice quite power
supplies, so I will probably check there first.&amp;nbsp; As for hard drives, I haven't
really started looking yet.&amp;nbsp; If I can find noise specs on them, then I may use
that as a criteria when deciding which to buy, but my primary concern is how many
GB can I get for my money.
&lt;/p&gt;
&lt;p&gt;
The other components have been moved to the end of the decision-tree.&amp;nbsp; I like
the Sliverstone cases I mentioned in my last post, but I decided that I should get
the components together first, since I didn't really want to end up with a nice-looking
case where I couldn't fit all of my goodies.&amp;nbsp; I also need to decide whether or
not to go with a DVD writer in the case....could be handy, but then I can also grab
stuff off the network, so is it really needed (I've got a CD writer lying around,
which may be my stand-in for a while)?
&lt;/p&gt;
&lt;p&gt;
Overall this is going to be a fun project, and lets face it, how often do you get
a geek project that your wife is behind 100%?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=f8982bdd-c3ab-4463-927b-314a7810cc80" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,f8982bdd-c3ab-4463-927b-314a7810cc80.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=d548bcb8-7d19-4938-965f-b50c907979fc</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,d548bcb8-7d19-4938-965f-b50c907979fc.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,d548bcb8-7d19-4938-965f-b50c907979fc.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=d548bcb8-7d19-4938-965f-b50c907979fc</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've been trying to catch up on past episodes of .Net Rocks while on my hour+ drive
to work everyday, and this morning listened to the interview with <a href="http://www.jnsk.se/weblog/">Jimmy
Nilsson</a> (<a title="DNR Episode 191" href="http://dotnetrocks.com/default.aspx?showID=194">episode
# 191</a>) on Domain Driven Design.  I'll admit now that I have not had time
to read his book all the way through, but it is one of the ones that I'm most eager
to dig into, since not only is he talking about DDD, but he's also talking about the <a href="http://www.martinfowler.com">Martin
Fowler</a> design patterns from <a title="Patterns of Enterprise Application Architecture" href="http://www.martinfowler.com/books.html#eaa">PoEEA</a>.
</p>
        <p>
One of the things brought up on the show was <a title="SOA-Q: SOA the opposite to DDD?" href="http://www.jnsk.se/weblog/posts/SOA-QDDDTheOpposite.htm">this
post</a> on Jimmy's blog.  I was shocked at the idea that SOA and DDD could
be considered opposite strategies by anyone.  One of the comments made by the
DNR hosts was that SOA was a technology in search of a problem to solve, whereas DDD
is focused on the problem domain to the exclusion of specific technologies. 
This is the sort of brutal mischaracterization of SOA, that I think
is still quite prevalent despite the efforts of folks like <a title="Ron Jacobs" href="http://blogs.msdn.com/rjacobs/">Ron
Jacobs</a> who are trying to spread the word of SOA done right.  So
here is my rundown of why, in fact, SOA and DDD go together like peanut butter and
chocolate:
</p>
        <p>
SOA is not a technology, it is a design strategy.  It is a way of thinking about
your <em>business</em> in terms of what services can be provided.  The idea that
if your using SOA then you are automatically using Web Services is just plain wrong. 
You can create a business application that is <em>Service Oriented</em> without ever
firing up the Web Service designer in .Net.  The core concept is to model the
services used in your organization.  These services should in fact be recognizable
objects from your Domain Model.  Business people should be able to talk about
the services in the same language they use to talk about the same concepts
within the business.  If that isn't happening, then you are not designing the
right services.
</p>
        <p>
The process of modeling services should be derived directly from the Domain Model
created using DDD if those services are going to be useful to the business. 
One of the arguments for going SOA is "Business Agility".  What does that mean
in the real world?  Basically the ability to allow all of the aspects of your
business to share information in a way that provides a measurable benefit.  The
agility comes in when you are able to connect parts of your business in ways that
were impossible before.  Once again, this has nothing to do with the technology
behind SOA, it has to do with the business needs.  Granted from a technical standpoint,
the easiest way to achieve the sort of connections we're talking about is to use a
technology like web services, but that is not the <em>point</em> of creating the SOA,
and it certainly shouldn't be the overwhelming factor in deciding to use SOA.
</p>
        <p>
So, in answer to Jimmy's question in his post (As I see it, there is lot of useful
ideas there for SOA as well, or what am I missing?):  No, you aren't missing
something, the SOA'ers (as you refer to them) are missing something.  You're
right on.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=d548bcb8-7d19-4938-965f-b50c907979fc" />
      </body>
      <title>You got your DDD in my SOA!</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,d548bcb8-7d19-4938-965f-b50c907979fc.aspx</guid>
      <link>http://www.drrandom.org/2007/06/05/YouGotYourDDDInMySOA.aspx</link>
      <pubDate>Tue, 05 Jun 2007 14:09:50 GMT</pubDate>
      <description>&lt;p&gt;
I've been trying to catch up on past episodes of .Net Rocks while on my hour+ drive
to work everyday, and this morning listened to the interview with &lt;a href="http://www.jnsk.se/weblog/"&gt;Jimmy
Nilsson&lt;/a&gt; (&lt;a title="DNR Episode 191" href="http://dotnetrocks.com/default.aspx?showID=194"&gt;episode
# 191&lt;/a&gt;) on Domain Driven Design.&amp;nbsp; I'll admit now that I have not had time
to read his book all the way through, but it is one of the ones that I'm most eager
to dig into, since not only is he talking about DDD, but he's also talking about the &lt;a href="http://www.martinfowler.com"&gt;Martin
Fowler&lt;/a&gt; design patterns from &lt;a title="Patterns of Enterprise Application Architecture" href="http://www.martinfowler.com/books.html#eaa"&gt;PoEEA&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
One of the things brought up on the show was &lt;a title="SOA-Q: SOA the opposite to DDD?" href="http://www.jnsk.se/weblog/posts/SOA-QDDDTheOpposite.htm"&gt;this
post&lt;/a&gt;&amp;nbsp;on Jimmy's blog.&amp;nbsp; I was shocked at the idea that SOA and DDD could
be considered opposite strategies by anyone.&amp;nbsp; One of the comments made by the
DNR hosts was that SOA was a technology in search of a problem to solve, whereas DDD
is focused on the problem domain to the exclusion of specific technologies.&amp;nbsp;
This is&amp;nbsp;the sort of&amp;nbsp;brutal mischaracterization of&amp;nbsp;SOA, that I think
is still quite prevalent despite the efforts of folks like &lt;a title="Ron Jacobs" href="http://blogs.msdn.com/rjacobs/"&gt;Ron
Jacobs&lt;/a&gt; who are&amp;nbsp;trying to spread&amp;nbsp;the word of SOA done right.&amp;nbsp; So
here is my rundown of why, in fact, SOA and DDD go together like peanut butter and
chocolate:
&lt;/p&gt;
&lt;p&gt;
SOA is not a technology, it is a design strategy.&amp;nbsp; It is a way of thinking about
your &lt;em&gt;business&lt;/em&gt; in terms of what services can be provided.&amp;nbsp; The idea that
if your using SOA then you are automatically using Web Services is just plain wrong.&amp;nbsp;
You can create a business application that is &lt;em&gt;Service Oriented&lt;/em&gt; without ever
firing up the Web Service designer in .Net.&amp;nbsp; The core concept is to model the
services used in your organization.&amp;nbsp; These services should in fact be recognizable
objects from your Domain Model.&amp;nbsp; Business people should be able to talk about
the services in the same&amp;nbsp;language&amp;nbsp;they use to&amp;nbsp;talk about the same&amp;nbsp;concepts
within the business.&amp;nbsp; If that isn't happening, then you are not designing the
right services.
&lt;/p&gt;
&lt;p&gt;
The process of modeling services&amp;nbsp;should be derived directly from the Domain Model
created using DDD if those services are going to be useful to the business.&amp;nbsp;
One of the arguments for going SOA is "Business Agility".&amp;nbsp; What does that mean
in the real world?&amp;nbsp; Basically the ability to allow all of the aspects of your
business to share information in a way that provides a measurable benefit.&amp;nbsp; The
agility comes in when you are able to connect parts of your business in ways that
were impossible before.&amp;nbsp; Once again, this has nothing to do with the technology
behind SOA, it has to do with the business needs.&amp;nbsp; Granted from a technical standpoint,
the easiest way to achieve the sort of connections we're talking about is to use a
technology like web services, but that is not the &lt;em&gt;point&lt;/em&gt; of creating the SOA,
and it certainly shouldn't be the overwhelming factor in deciding to use SOA.
&lt;/p&gt;
&lt;p&gt;
So, in answer to Jimmy's question in his post (As I see it, there is lot of useful
ideas there for SOA as well, or what am I missing?):&amp;nbsp; No, you aren't missing
something, the SOA'ers (as you refer to them) are missing something.&amp;nbsp; You're
right on.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=d548bcb8-7d19-4938-965f-b50c907979fc" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,d548bcb8-7d19-4938-965f-b50c907979fc.aspx</comments>
      <category>SOA</category>
      <category>DDD</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=8ab4bb1a-5802-481b-b626-0deb2b92604d</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,8ab4bb1a-5802-481b-b626-0deb2b92604d.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,8ab4bb1a-5802-481b-b626-0deb2b92604d.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=8ab4bb1a-5802-481b-b626-0deb2b92604d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Thinking about <a title="To TOOP or OOP?  How to decide?" href="http://www.drrandom.org/PermaLink,guid,a45a48b9-1bca-479e-a5a0-5412ad66da6b.aspx">my
earlier post</a> discussing the OOP vs TOOP problem, I mentioned at the end that the
best solution to this problem in my mind would be integrated language support for
test classes.  Specifically, a way to let the Compiler/Runtime know that a specific
class is a test class, and should therefore be able to access any and every property
of a class.
</p>
        <p>
It occurred to me that such blatant intrusion into the privacy of a class is not unknown
in the programming world.  C++ has the notion of a "Friend" class.  This
is a class that can access all members of another class regardless of their protection
level.  To keep things civil, so that just any class can't declare itself to
be a Friend of any class it wants, the class that the Friend class would be accessing
would declare specifically that classes X, Y and Z are fiends, and so can have free
reign.  Granted this is considered to be rather scary, and one of those features
that makes C++ an ideal tool for shooting ones own foot off.
</p>
        <p>
But, this concept has some merit within the context of Test classes.  In the
.Net world we could potentially use attributes on a class to identify what the test
class (or classes I suppose) for a class are.  The compiler and runtime could
then use that information to provide unlimited access only to the classes listed in
the test class list.  For more protection perhaps it would also validate that
the classes in the list also have the appropriate attribute (TestFixture in NUnit,
TestClass in TFS) before allowing access.  You would need some additional tooling
in the development environment so that you would get Intellisense on all of the private/protected
members, but that should be easy for the MS guys after building in the test support,
right?
</p>
        <p>
There is some additional danger in this approach since there is some potential to
modify IL at runtime, but couldn't there be additional protections around such things? 
As someone with no knowledge of the internal workings of the CLR, I can't say for
sure, but its worth trying.
</p>
        <p>
So, I know officially propose to Microsoft that this feature be added to the 4.0 version
of the framework.
</p>
        <p>
Do you think they heard me?
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=8ab4bb1a-5802-481b-b626-0deb2b92604d" />
      </body>
      <title>More Thoughts on Language Support of TDD</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,8ab4bb1a-5802-481b-b626-0deb2b92604d.aspx</guid>
      <link>http://www.drrandom.org/2007/06/04/MoreThoughtsOnLanguageSupportOfTDD.aspx</link>
      <pubDate>Mon, 04 Jun 2007 14:21:47 GMT</pubDate>
      <description>&lt;p&gt;
Thinking about &lt;a title="To TOOP or OOP?  How to decide?" href="http://www.drrandom.org/PermaLink,guid,a45a48b9-1bca-479e-a5a0-5412ad66da6b.aspx"&gt;my
earlier post&lt;/a&gt; discussing the OOP vs TOOP problem, I mentioned at the end that the
best solution to this problem in my mind would be integrated language support for
test classes.&amp;nbsp; Specifically, a way to let the Compiler/Runtime know that a specific
class is a test class, and should therefore be able to access any and every property
of a class.
&lt;/p&gt;
&lt;p&gt;
It occurred to me that such blatant intrusion into the privacy of a class is not unknown
in the programming world.&amp;nbsp; C++ has the notion of a "Friend" class.&amp;nbsp; This
is a class that can access all members of another class regardless of their protection
level.&amp;nbsp; To keep things civil, so that just any class can't declare itself to
be a Friend of any class it wants, the class that the Friend class would be accessing
would declare specifically that classes X, Y and Z are fiends, and so can have free
reign.&amp;nbsp; Granted this is considered to be rather scary, and one of those features
that makes C++ an ideal tool for shooting ones own foot off.
&lt;/p&gt;
&lt;p&gt;
But, this concept has some merit within the context of Test classes.&amp;nbsp; In the
.Net world we could potentially use attributes on a class to identify what the test
class (or classes I suppose) for a class are.&amp;nbsp; The compiler and runtime could
then use that information to provide unlimited access only to the classes listed in
the test class list.&amp;nbsp; For more protection perhaps it would also validate that
the classes in the list also have the appropriate attribute (TestFixture in NUnit,
TestClass in TFS) before allowing access.&amp;nbsp; You would need some additional tooling
in the development environment so that you would get Intellisense on all of the private/protected
members, but that should be easy for the MS guys after building in the test support,
right?
&lt;/p&gt;
&lt;p&gt;
There is some additional danger in this approach since there is some potential to
modify IL at runtime, but couldn't there be additional protections around such things?&amp;nbsp;
As someone with no knowledge of the internal workings of the CLR, I can't say for
sure, but its worth trying.
&lt;/p&gt;
&lt;p&gt;
So, I know officially propose to Microsoft that this feature be added to the 4.0 version
of the framework.
&lt;/p&gt;
&lt;p&gt;
Do you think they heard me?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=8ab4bb1a-5802-481b-b626-0deb2b92604d" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,8ab4bb1a-5802-481b-b626-0deb2b92604d.aspx</comments>
      <category>.Net</category>
      <category>TDD</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=02c8aec1-ee41-4d03-b81c-bdd71ff8ebeb</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,02c8aec1-ee41-4d03-b81c-bdd71ff8ebeb.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,02c8aec1-ee41-4d03-b81c-bdd71ff8ebeb.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=02c8aec1-ee41-4d03-b81c-bdd71ff8ebeb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here is something I've been kicking around in my head for a while, and thought I would
put it down in more or less a "permanent" format so maybe I'll do something about
it sometime...
</p>
        <p>
Back when I was first trying to get my head around TDD, one of the things that I found
most clarifying was an idea I first saw in <a title="Test Driven Development in Microsoft .Net" href="http://www.amazon.com/Test-Driven-Development-Microsoft-NET-Professional/dp/0735619484" target="_blank">Test
Driven Development in Microsoft .Net</a> (Microsoft Press).  The idea is that
you write tests based on your requirements.  So as a developer, you should have
hopefully been given a list of requirements by someone for the project you are working
on.  When you go to build the software you start looking at the requirements
list, and the pick on (usually a simple one) to start implementing.  Once you
have your requirement you start brainstorming tests that can be implemented to fulfill
that requirement.  Once you can no longer think of tests for a requirement, you
move on to the next one.  After that once you have run out of requirements, then
your done writing the software.
</p>
        <p>
This struck me not only as a good way to approach the problem of how do I come up
with tests, but also as a potentially powerful tool for tracking progress within a
project.  I can imagine something not unlike the NUnit Test Runner that, instead
of listing all of the tests, lists all of the requirements.  If there are tests
written for a requirement, then you could potentially expand the requirement to see
the list of tests.  When you execute the tests, you can then see which requirements
are complete (more on this in a minute), and also which ones are functional. 
The assumption being, if a test fails, then there is a functional problem with the
requirements.
</p>
        <p>
To support this a few modifications to the standard TDD toolset may be needed. 
First a place to put the list of requirements in code would be useful.  This
could be an XML document with the test descriptions and IDs, or maybe even a plain
text document, or a piece of code.  I actually like the idea of the XML document
because potentially you could build an InfoPath form or something that a BA could
use to put together the requirement list, and then hand the XML doc over to the development
team.  From there an additional attribute would be added to the NUnit tests,
so that a specific test could be associated with a specific requirement.  If
you wanted to be able to give a "percentage implemented" on a requirement, then you
would probably want to do something like create all of the test methods you can come
up with during a brainstorming session, and put an Ignore attribute on them. 
At that point it should be feasible to see how many of the methods are implemented,
and how many are still being Ignored, and then grab a percentage.  This number
would change as time progressed and the development team came up with additional tests
for specific requirements, but it would probably stabilize by the time serious work
started into a specific requirement.
</p>
        <p>
So that's it...my brilliant idea.  I actually think there wouldn't be a whole
lot of work involved in getting it going either...A new attribute, an updated Unit
Test Runner, and some XML work.  It would be nice to be able to define the requirements
in a way that would let you use Intellisense to select the requirements while in VS.Net....maybe
code-generate a struct or enum based on the XML doc?
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=02c8aec1-ee41-4d03-b81c-bdd71ff8ebeb" />
      </body>
      <title>Using Unit Testing To Document Requirements</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,02c8aec1-ee41-4d03-b81c-bdd71ff8ebeb.aspx</guid>
      <link>http://www.drrandom.org/2007/06/01/UsingUnitTestingToDocumentRequirements.aspx</link>
      <pubDate>Fri, 01 Jun 2007 15:17:02 GMT</pubDate>
      <description>&lt;p&gt;
Here is something I've been kicking around in my head for a while, and thought I would
put it down in more or less a "permanent" format so maybe I'll do something about
it sometime...
&lt;/p&gt;
&lt;p&gt;
Back when I was first trying to get my head around TDD, one of the things that I found
most clarifying was an idea I first saw in &lt;a title="Test Driven Development in Microsoft .Net" href="http://www.amazon.com/Test-Driven-Development-Microsoft-NET-Professional/dp/0735619484" target="_blank"&gt;Test
Driven Development in Microsoft .Net&lt;/a&gt; (Microsoft Press).&amp;nbsp; The idea is that
you write tests based on your requirements.&amp;nbsp; So as a developer, you should have
hopefully been given a list of requirements by someone for the project you are working
on.&amp;nbsp; When you go to build the software you start looking at the requirements
list, and the pick on (usually a simple one) to start implementing.&amp;nbsp; Once you
have your requirement you start brainstorming tests that can be implemented to fulfill
that requirement.&amp;nbsp; Once you can no longer think of tests for a requirement, you
move on to the next one.&amp;nbsp; After that once you have run out of requirements, then
your done writing the software.
&lt;/p&gt;
&lt;p&gt;
This struck me not only as a good way to approach the problem of how do I come up
with tests, but also as a potentially powerful tool for tracking progress within a
project.&amp;nbsp; I can imagine something not unlike the NUnit Test Runner that, instead
of listing all of the tests, lists all of the requirements.&amp;nbsp; If there are tests
written for a requirement, then you could potentially expand the requirement to see
the list of tests.&amp;nbsp; When you execute the tests, you can then see which requirements
are complete (more on this in a minute), and also which ones are functional.&amp;nbsp;
The assumption being, if a test fails, then there is a functional problem with the
requirements.
&lt;/p&gt;
&lt;p&gt;
To support this a few modifications to the standard TDD toolset may be needed.&amp;nbsp;
First a place to put the list of requirements in code would be useful.&amp;nbsp; This
could be an XML document with the test descriptions and IDs, or maybe even a plain
text document, or a piece of code.&amp;nbsp; I actually like the idea of the XML document
because potentially you could build an InfoPath form or something that a BA could
use to put together the requirement list, and then hand the XML doc over to the development
team.&amp;nbsp;&amp;nbsp;From there an additional attribute would be added to the NUnit tests,
so that a specific test could be associated with a specific requirement.&amp;nbsp; If
you wanted to be able to give a "percentage implemented" on a requirement, then you
would probably want to do something like create all of the test methods you can come
up with during a brainstorming session, and put an Ignore attribute on them.&amp;nbsp;
At that point it should be feasible to see how many of the methods are implemented,
and how many are still being Ignored, and then grab a percentage.&amp;nbsp; This number
would change as time progressed and the development team came up with additional tests
for specific requirements, but it would probably stabilize by the time serious work
started into a specific requirement.
&lt;/p&gt;
&lt;p&gt;
So that's it...my brilliant idea.&amp;nbsp; I actually think there wouldn't be a whole
lot of work involved in getting it going either...A new attribute, an updated Unit
Test Runner, and some XML work.&amp;nbsp; It would be nice to be able to define the requirements
in a way that would let you use Intellisense to select the requirements while in VS.Net....maybe
code-generate a struct or enum based on the XML doc?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=02c8aec1-ee41-4d03-b81c-bdd71ff8ebeb" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,02c8aec1-ee41-4d03-b81c-bdd71ff8ebeb.aspx</comments>
      <category>TDD</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=a45a48b9-1bca-479e-a5a0-5412ad66da6b</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,a45a48b9-1bca-479e-a5a0-5412ad66da6b.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,a45a48b9-1bca-479e-a5a0-5412ad66da6b.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=a45a48b9-1bca-479e-a5a0-5412ad66da6b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Its been a while now, but <a title="ISerializable" href="http://weblogs.asp.net/rosherove/default.aspx">Roy
Osherove</a> posted <a title="TOOP 1" href="http://weblogs.asp.net/rosherove/archive/2007/02/25/why-you-should-think-about-ootp-object-oriented-testable-programming.aspx">some</a><a title="TOOP 2" href="http://weblogs.asp.net/rosherove/archive/2007/03/02/testable-designs-round-2-tooling-design-smells-and-bad-analogies.aspx">articles</a> about
Testable Object-Oriented Programming.  That is, designing your code to be testable
by default.  The part of this that is most interesting is that he suggests that
sometimes you need to sacrifice encapsulation in favor of being able to test your
code.  This is where one of the biggest flaws with TDD (at least in my opinion)
begins to show.  I think the idea of making code testable breaking encapsulation
is one of the only arguments against TDD that I have heard that I can't give a good
defense for, and it makes me crazy.
</p>
        <p>
Overall I would consider myself a competent OO programmer...I might even venture to
say that I'm really good, so this issue is one that bugs me.  I think encapsulation
is one of the most powerful tools out there for making good OO code.  So now
I'm a big fan of TDD, which does not allow me to use this tool as much as I would
like....so what gives?
</p>
        <p>
          <strong>The Problem<br /></strong>There are many cases (at least that I've seen) where it makes sense to restrict
the visibility of pieces of your object model.  In this context the situation
is generally calling for classes/methods to be Internal (Package in Java), or Protected
Internal.  I have a feeling, even though I have no evidence to back it up, that
this is probably the least-used of all the visibility constraints.  What I've
found, though, is that using it allows you to create well-factored classes, that abide
by the Single Responsibility Principle, and still present a minimal interface to other
layers/users of your code.  There is also the problem of exposing internal dependencies
so that those dependencies can be injected during testing (this is where stubs or
mock objects come into play).  In many cases there is no real reason to expose
this information, and in fact making it available is probably a bad thing because
it will make code that is consuming your object more aware of the implementation than
it needs to be...And Steve McConnell did a good job at letting us know this is bad.
</p>
        <p>
These are extremely brief introductions to the problems, and even though these are
simple examples, such things can get ugly quickly in a large project.  The main
reason being that all of a sudden there are many, many more things available to the
developer who is just trying to use your class to get some work done.
</p>
        <p>
          <strong>Some Solutions<br /></strong>There are some solutions which can reduce the complexity somewhat. 
In the case of using Internal objects, there is always the option of including your
test classes in the same project as the code you are testing.  Microsoft seems
to have done this with EnterpriseLibrary 1.1.  The biggest downside to this,
however, is that in a lot of cases you don't want to ship your tests with the rest
of your production code, so you have to figure out how to do some clever things like
conditional compilation to avoid compiling those classes into your production assemblies. 
Granted with a build tool like NAnt this becomes easier, but if your not familiar
with it, there is a rather steep learning curve.
</p>
        <p>
In the realm of exposing implementation details, one possible course of action is
to use a Inversion Of Control container like the <a title="Castle Project" href="http://www.castleproject.org">Castle</a><a title="IoC components" href="http://www.castleproject.org/container/index.html" target="_blank">Microkernel/Windsor</a> tools. 
With these you can write your objects so that they request instances of the dependencies
from the IoC container, and not create new instances themselves (or expect you to
provide them).  This begs the question of where the IoC container lives, though. 
In the case of testing you would want to fill the container with mocks or stubs of
the appropriate objects, so that the class your testing gets those objects instead. 
In some cases this may mean that your IoC container needs to live in a central repository
where all of the objects can get to it...or you could pass around your IoC instance,
instead of your dependencies.
</p>
        <p>
The other solution, which was the point of the 2nd post from Roy on TOOD, is to use
a tool like <a title="TypeMock" href="http://www.typemock.com/" target="_blank">TypeMock</a>,
which has the remarkable ability to mock objects and give you access to the internal/protected/private
members in your tests.  Pretty serious stuff.  It doesn't solve the problem
of dependency injection completely, though.  There is also the issue of cost
if you want all of the really nifty features (though the Community Edition seems to
include the ability to mock all methods/properties of an object).
</p>
        <p>
          <strong>The Ultimate Solution</strong>
          <br />
In my mind what is needed to really bridge the divide between the issues here (which
are testability and good OO practices like encapsulation) is to make support for TDD
a first-class feature of a language or runtime.  What I mean by that is that
the .Net Framework, for example, would have knowledge of test classes and test methods,
and loosen the visibility restrictions while running a test.  Most likely this
would mean some serious changes to the CLR, but it seems like it should be possible
to set up a sandbox environment for testing, where the CLR would evaluate the objects
being tested, and then allow full access to all fields and methods.  It would
have to be seriously limited, and there may even need to be some restrictions around
when and where this sort of behavior can happen, but ultimately it seems like the
best solution.  It seems like a stretch, but in my mind it is the only real solution
to the problem.  Until that point, we are stuck making decisions about where
to draw the line between testability and good OO design.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=a45a48b9-1bca-479e-a5a0-5412ad66da6b" />
      </body>
      <title>To TOOP or OOP? How to decide?</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,a45a48b9-1bca-479e-a5a0-5412ad66da6b.aspx</guid>
      <link>http://www.drrandom.org/2007/05/29/ToTOOPOrOOPHowToDecide.aspx</link>
      <pubDate>Tue, 29 May 2007 21:12:42 GMT</pubDate>
      <description>&lt;p&gt;
Its been a while now, but &lt;a title="ISerializable" href="http://weblogs.asp.net/rosherove/default.aspx"&gt;Roy
Osherove&lt;/a&gt;&amp;nbsp;posted &lt;a title="TOOP 1" href="http://weblogs.asp.net/rosherove/archive/2007/02/25/why-you-should-think-about-ootp-object-oriented-testable-programming.aspx"&gt;some&lt;/a&gt; &lt;a title="TOOP 2" href="http://weblogs.asp.net/rosherove/archive/2007/03/02/testable-designs-round-2-tooling-design-smells-and-bad-analogies.aspx"&gt;articles&lt;/a&gt; about
Testable Object-Oriented Programming.&amp;nbsp; That is, designing your code to be testable
by default.&amp;nbsp; The part of this that is most interesting is that he suggests that
sometimes you need to sacrifice encapsulation in favor of being able to test your
code.&amp;nbsp; This is where one of the biggest flaws with TDD (at least in my opinion)
begins to show.&amp;nbsp; I think the idea of making code testable breaking encapsulation
is one of the only arguments against TDD that I have heard that I can't give a good
defense for, and it makes me crazy.
&lt;/p&gt;
&lt;p&gt;
Overall I would consider myself a competent OO programmer...I might even venture to
say that I'm really good, so this issue is one that bugs me.&amp;nbsp; I think encapsulation
is one of the most powerful tools out there for making good OO code.&amp;nbsp; So now
I'm a big fan of TDD, which does not allow me to use this tool as much as I would
like....so what gives?
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;The Problem&lt;br&gt;
&lt;/strong&gt;There are many cases (at least that I've seen) where it makes sense to restrict
the visibility of pieces of your object model.&amp;nbsp; In this context the situation
is generally calling for classes/methods to be Internal (Package in Java), or Protected
Internal.&amp;nbsp; I have a feeling, even though I have no evidence to back it up, that
this is probably the least-used of all the visibility constraints.&amp;nbsp; What I've
found, though, is that using it allows you to create well-factored classes, that abide
by the Single Responsibility Principle, and still present a minimal interface to other
layers/users of your code.&amp;nbsp; There is also the problem of exposing internal dependencies
so that those dependencies can be injected during testing (this is where stubs or
mock objects come into play).&amp;nbsp; In many cases there is no real reason to expose
this information, and in fact making it available is probably a bad thing because
it will make code that is consuming your object more aware of the implementation than
it needs to be...And Steve McConnell did a good job at letting us know this is bad.
&lt;/p&gt;
&lt;p&gt;
These are extremely brief introductions to the problems, and even though these are
simple examples, such things can get ugly quickly in a large project.&amp;nbsp; The main
reason being that all of a sudden there are many, many more things available to the
developer who is just trying to use your class to get some work done.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Some Solutions&lt;br&gt;
&lt;/strong&gt;There are some solutions which can reduce the complexity somewhat.&amp;nbsp;
In the case of using Internal objects, there is always the option of including your
test classes in the same project as the code you are testing.&amp;nbsp; Microsoft seems
to have done this with EnterpriseLibrary 1.1.&amp;nbsp; The biggest downside to this,
however, is that in a lot of cases you don't want to ship your tests with the rest
of your production code, so you have to figure out how to do some clever things like
conditional compilation to avoid compiling those classes into your production assemblies.&amp;nbsp;
Granted with a build tool like NAnt this becomes easier, but if your not familiar
with it, there is a rather steep learning curve.
&lt;/p&gt;
&lt;p&gt;
In the realm of exposing implementation details, one possible course of action is
to use a Inversion Of Control container like the &lt;a title="Castle Project" href="http://www.castleproject.org"&gt;Castle&lt;/a&gt; &lt;a title="IoC components" href="http://www.castleproject.org/container/index.html" target="_blank"&gt;Microkernel/Windsor&lt;/a&gt; tools.&amp;nbsp;
With these you can write your objects so that they request instances of the dependencies
from the IoC container, and not create new instances themselves (or expect you to
provide them).&amp;nbsp; This begs the question of where the IoC container lives, though.&amp;nbsp;
In the case of testing you would want to fill the container with mocks or stubs of
the appropriate objects, so that the class your testing gets those objects instead.&amp;nbsp;
In some cases this may mean that your IoC container needs to live in a central repository
where all of the objects can get to it...or you could pass around your IoC instance,
instead of your dependencies.
&lt;/p&gt;
&lt;p&gt;
The other solution, which was the point of the 2nd post from Roy on TOOD, is to use
a tool like &lt;a title="TypeMock" href="http://www.typemock.com/" target="_blank"&gt;TypeMock&lt;/a&gt;,
which has the remarkable ability to mock objects and give you access to the internal/protected/private
members in your tests.&amp;nbsp; Pretty serious stuff.&amp;nbsp; It doesn't solve the problem
of dependency injection completely, though.&amp;nbsp; There is also the issue of cost
if you want all of the really nifty features (though the Community Edition seems to
include the ability to mock all methods/properties of an object).
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;The Ultimate Solution&lt;/strong&gt;
&lt;br&gt;
In my mind what is needed to really bridge the divide between the issues here (which
are testability and good OO practices like encapsulation) is to make support for TDD
a first-class feature of a language or runtime.&amp;nbsp; What I mean by that is that
the .Net Framework, for example, would have knowledge of test classes and test methods,
and loosen the visibility restrictions while running a test.&amp;nbsp; Most likely this
would mean some serious changes to the CLR, but it seems like it should be possible
to set up a sandbox environment for testing, where the CLR would evaluate the objects
being tested, and then allow full access to all fields and methods.&amp;nbsp; It would
have to be seriously limited, and there may even need to be some restrictions around
when and where this sort of behavior can happen, but ultimately it seems like the
best solution.&amp;nbsp; It seems like a stretch, but in my mind it is the only real solution
to the problem.&amp;nbsp; Until that point, we are stuck making decisions about where
to draw the line between testability and good OO design.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=a45a48b9-1bca-479e-a5a0-5412ad66da6b" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,a45a48b9-1bca-479e-a5a0-5412ad66da6b.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=fafbc9c6-e165-4170-9e40-31336032dcc8</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,fafbc9c6-e165-4170-9e40-31336032dcc8.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,fafbc9c6-e165-4170-9e40-31336032dcc8.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=fafbc9c6-e165-4170-9e40-31336032dcc8</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have officially crossed over....I am now using Mock Objects in my tests and <strong>loving
it</strong>.  After much humming and hawing, and trying to figure out how to
write truly effective tests, I decided to give it a go, and so grabbed a copy of <a title="Rhino Mocks Home" href="http://www.ayende.com/projects/rhino-mocks.aspx" target="_blank">Rhino
Mocks</a> and started the grueling task of converting some data access code so that
I no longer needed a database to run the tests.  It took a little bit to get
my mind around the new way of thinking, but I have to say it worked great.  I'm
now able to test my data access routines with complete success, and about a 95% code
coverage rate.  This is all on top of the fact that I'm using Enterprise Library
(for 1.1) for data access and exception handling.
</p>
        <p>
Now, there is a very interesting article from <a title="Martin Fowler" href="http://www.martinfowler.com" target="_blank">Martin
Fowler</a> which is called simply <a title="Mocks aren't Stubs" href="http://martinfowler.com/articles/mocksArentStubs.html">"Mocks
aren't Stubs"</a>.  In this article he is discussing two approaches for dealing
with the sort of problem that I had with my data access code.  One is to create
object stubs within your tests that you can use to feed known values back to your
tests.  This is not at all a bad approach, and I am using it in some cases in
conjunction with my mock objects.  The other approach is to use Mock Objects
for all of the tricky stuff.  He observed an interesting dichotomy between the
sort of TDD folks who follow each approach:  The folks that use stubs tend to
be very results oriented in their testing...That is they are verifying the values
of various object after performing an action using the test frameworks Assert calls. 
This, I think, is most in line with the way TDD is supposed to work.  For
the Mock Object folks, though, another thing starts to happen.  These test gain
the ability to verify that specific methods are called in a specific order, and therefore
the tests that come from this approach start becoming less results-oriented, and rely
more on the method verification from the Mocking framework.  He points out these
two styles of testing without really saying one is better than the other (he does
indicate that he tends to be in the Stub camp, but I think that is a personal choice
and level of comfort thing), beyond pointing out that relying on the results of the
test tends to be more in line with the pure TDD way of doing things.
</p>
        <p>
Now, I had read this article before I started using mocks within my project. 
I thought about using stubs throughout, but since I was testing data access code,
I would have a lot of methods to implement in my stub objects that wouldn't really
be part of what I was testing, so it seemed a large waste of my time.  As I started
implementing mocks in the tests, I paid attention to how I was testing to see if I
was becoming a "Mockist" in the Fowler sense.  Overall I would say that I am
not, currently, a "Mockist".  I'm still overwhelmingly validating the results
of calls based on the methods I'm testing, and just using the mocks to feed appropriate
values into the classes I'm trying to test.  As a matter of fact, I could probably
remove the call to <font face="Courier">_mocks.VerifyAll()</font> at the end of my
tests, since I don't really care.  I can say, though, that the ability to verify
what is being called with what arguments has been extremely useful in my data access
testing space.  I've basically got objects which are making calls to stored procs
on Oracle to do my data work. The DAL is a real simple deal that doesn't have much
in the way of smarts, but works well enough for a small project.  Because of
the fact that I'm making stored proc calls to the database, I can now use the mocks
to make sure that when I call the <font face="Courier">Save()</font> method on my
User object (for example), It's calling <font face="Courier">ExecuteNonQuery()</font> with
the proc name of <font face="Courier">SAVE_USER</font>.  I can also verify that
all of the input an output parameters are being set correctly, which is a big consideration
when adding a property to the data objects.  In that way I can know that my <font face="Courier">Save()</font> method
is doing what it is supposed to even though it returns no value.  This checking
could probably be done by stubbing the EnterpriseLibrary Database and DBCommand objects,
and then setting values within my stub object, which I could verify using an Assert
call, but that seems like an awful lot of work when I have the option to simply set
expectations, and then do a <font face="Courier">VerifyAll().</font></p>
        <p>
I think the Fowler article may be making much of a practice which is not that common
among people using mocks in TDD.  Or maybe there is a slow creep that happens
to the developer after months and years of using mocks in their tests that turn them
into Mockists.  Personally I find that there is a very broad and comfortable
middle ground which allows me more flexibility to express my intent quickly and concisely. 
And after all, expressing intent is one of the major boons of TDD.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=fafbc9c6-e165-4170-9e40-31336032dcc8" />
      </body>
      <title>I love Mock Objects, but am I a &amp;quot;Mockist&amp;quot;?</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,fafbc9c6-e165-4170-9e40-31336032dcc8.aspx</guid>
      <link>http://www.drrandom.org/2007/05/29/ILoveMockObjectsButAmIAQuotMockistquot.aspx</link>
      <pubDate>Tue, 29 May 2007 15:45:50 GMT</pubDate>
      <description>&lt;p&gt;
I have officially crossed over....I am now using Mock Objects in my tests and &lt;strong&gt;loving
it&lt;/strong&gt;.&amp;nbsp; After much humming and hawing, and trying to figure out how to
write truly effective tests, I decided to give it a go, and so grabbed a copy of &lt;a title="Rhino Mocks Home" href="http://www.ayende.com/projects/rhino-mocks.aspx" target="_blank"&gt;Rhino
Mocks&lt;/a&gt; and started the grueling task of converting some data access code so that
I no longer needed a database to run the tests.&amp;nbsp; It took a little bit to get
my mind around the new way of thinking, but I have to say it worked great.&amp;nbsp; I'm
now able to test my data access routines with complete success, and about a 95% code
coverage rate.&amp;nbsp; This is all on top of the fact that I'm using Enterprise Library
(for 1.1) for data access and exception handling.
&lt;/p&gt;
&lt;p&gt;
Now, there is a very interesting article from &lt;a title="Martin Fowler" href="http://www.martinfowler.com" target="_blank"&gt;Martin
Fowler&lt;/a&gt; which is called simply &lt;a title="Mocks aren't Stubs" href="http://martinfowler.com/articles/mocksArentStubs.html"&gt;"Mocks
aren't Stubs"&lt;/a&gt;.&amp;nbsp; In this article he is discussing two approaches for dealing
with the sort of problem that I had with my data access code.&amp;nbsp; One is to create
object stubs within your tests that you can use to feed known values back to your
tests.&amp;nbsp; This is not at all a bad approach, and I am using it in some cases in
conjunction with my mock objects.&amp;nbsp; The other approach is to use Mock Objects
for all of the tricky stuff.&amp;nbsp; He observed an interesting dichotomy between the
sort of TDD folks who follow each approach:&amp;nbsp; The folks that use stubs tend to
be very results oriented in their testing...That is they are verifying the values
of various object after performing an action using the test frameworks Assert calls.&amp;nbsp;
This, I think, is&amp;nbsp;most in line with the way TDD is supposed to work.&amp;nbsp; For
the Mock Object folks, though, another thing starts to happen.&amp;nbsp; These test gain
the ability to verify that specific methods are called in a specific order, and therefore
the tests that come from this approach start becoming less results-oriented, and rely
more on the method verification from the Mocking framework.&amp;nbsp; He points out these
two styles of testing without really saying one is better than the other (he does
indicate that he tends to be in the Stub camp, but I think that is a personal choice
and level of comfort thing), beyond pointing out that relying on the results of the
test tends to be more in line with the pure TDD way of doing things.
&lt;/p&gt;
&lt;p&gt;
Now, I had read this article before I started using mocks within my project.&amp;nbsp;
I thought about using stubs throughout, but since&amp;nbsp;I was testing data access code,
I would have a lot of methods to implement in my stub objects that wouldn't really
be part of what I was testing, so it seemed a large waste of my time.&amp;nbsp; As I started
implementing mocks in the tests, I paid attention to how I was testing to see if I
was becoming a "Mockist" in the Fowler sense.&amp;nbsp; Overall I would say that I am
not, currently, a "Mockist".&amp;nbsp; I'm still overwhelmingly validating the results
of calls based on the methods I'm testing, and just using the mocks to feed appropriate
values into the classes I'm trying to test.&amp;nbsp; As a matter of fact, I could probably
remove the call to &lt;font face="Courier"&gt;_mocks.VerifyAll()&lt;/font&gt; at the end of my
tests, since I don't really care.&amp;nbsp; I can say, though, that the ability to verify
what is being called with what arguments has been extremely useful in my data access
testing space.&amp;nbsp; I've basically got objects which are making calls to stored procs
on Oracle to do my data work. The DAL is a real simple deal that doesn't have much
in the way of smarts, but works well enough for a small project.&amp;nbsp; Because of
the fact that I'm making stored proc calls to the database, I can now use the mocks
to make sure that when I call the &lt;font face="Courier"&gt;Save()&lt;/font&gt; method on my
User object (for example), It's calling &lt;font face="Courier"&gt;ExecuteNonQuery()&lt;/font&gt; with
the proc name of &lt;font face="Courier"&gt;SAVE_USER&lt;/font&gt;.&amp;nbsp; I can also verify that
all of the input an output parameters are being set correctly, which is a big consideration
when adding a property to the data objects.&amp;nbsp; In that way I can know that my &lt;font face="Courier"&gt;Save()&lt;/font&gt; method
is doing what it is supposed to even though it returns no value.&amp;nbsp; This checking
could probably be done by stubbing the EnterpriseLibrary Database and DBCommand objects,
and then setting values within my stub object, which I could verify using an Assert
call, but that seems like an awful lot of work when I have the option to simply set
expectations, and then do a &lt;font face="Courier"&gt;VerifyAll().&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
I think the Fowler article may be making much of a practice which is not that common
among people using mocks in TDD.&amp;nbsp; Or maybe there is a slow creep that happens
to the developer after months and years of using mocks in their tests that turn them
into Mockists.&amp;nbsp; Personally I find that there is a very broad and comfortable
middle ground which allows me more flexibility to express my intent quickly and concisely.&amp;nbsp;
And after all, expressing intent is one of the major boons of TDD.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=fafbc9c6-e165-4170-9e40-31336032dcc8" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,fafbc9c6-e165-4170-9e40-31336032dcc8.aspx</comments>
      <category>.Net</category>
      <category>TDD</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=812432d9-2af4-447b-8ef0-388f825eaba5</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,812432d9-2af4-447b-8ef0-388f825eaba5.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,812432d9-2af4-447b-8ef0-388f825eaba5.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=812432d9-2af4-447b-8ef0-388f825eaba5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <img height="151" src="http://www.drrandom.org/blog_images/GenuineAdvantageNotificationWTF_681E/PistolPirateBust8.jpg" width="131" align="right" />
        <p>
This morning I was greeted by a friendly message from Windows Update saying I had
updates ready to install.  Because I'm the curious sort who likes to see how
many issues MS has to deal with regularly, I decided to use "Advanced" mode to see
what the updates were (By "Advanced" of course it means anyone who is concerned about
what is getting installed on their machines...I've seen I Robot, I know that one day
the great machine can decide the only way to save us from our selves is to format
our hard drives).
</p>
        <p>
What greeted me was the "Genuine Advantage Notification" update.  Apparently
this is a little guy that sits in memory and periodically checks to make sure my version
of Windows does not suddenly become pirated.  WTF?  Is this really a problem? 
Sure I can maybe see if someone decides to upgrade to a pirated version of Vista,
instead of paving their machine like normal people do, this might come in handy....that's
assuming though that the tool gets picked up by the upgrade process, and that someone
who purchases a pirated copy of Vista is the sort of person who would leave a gem
such as this one installed on their machine.
</p>
        <p>
Okay, okay, I know that there are probably cases of normal users going to Thailand
and thinking to themselves "Well, here is a booth with Windows Vista DVDs, and they
are only wanting $30 for it...that's way cheaper than in the US...must be the currency
conversion rate", and so they accidentally get themselves a pirated copy of Windows. 
I would think that most people who are grabbing pirated copies of their OS are doing
it because they don't want to pay for the full version, and they are under no false
pretenses about the "Genuineness" of the product.
</p>
        <p>
The best part of this utility is the fact that once it figures out that your OS has
become pirated, it will "help you obtain a licensed copy".  That makes me feel
really confident about having this thing running all the time. 
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=812432d9-2af4-447b-8ef0-388f825eaba5" />
      </body>
      <title>Genuine Advantage Notification - WTF?</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,812432d9-2af4-447b-8ef0-388f825eaba5.aspx</guid>
      <link>http://www.drrandom.org/2007/04/04/GenuineAdvantageNotificationWTF.aspx</link>
      <pubDate>Wed, 04 Apr 2007 11:30:11 GMT</pubDate>
      <description>&lt;img height="151" src="http://www.drrandom.org/blog_images/GenuineAdvantageNotificationWTF_681E/PistolPirateBust8.jpg" width="131" align="right"&gt; 
&lt;p&gt;
This morning I was greeted by a friendly message from Windows Update saying I had
updates ready to install.&amp;nbsp; Because I'm the curious sort who likes to see how
many issues MS has to deal with regularly, I decided to use "Advanced" mode to see
what the updates were (By "Advanced" of course it means anyone who is concerned about
what is getting installed on their machines...I've seen I Robot, I know that one day
the great machine can decide the only way to save us from our selves is to format
our hard drives).
&lt;/p&gt;
&lt;p&gt;
What greeted me was the "Genuine Advantage Notification" update.&amp;nbsp; Apparently
this is a little guy that sits in memory and periodically checks to make sure my version
of Windows does not suddenly become pirated.&amp;nbsp; WTF?&amp;nbsp; Is this really a problem?&amp;nbsp;
Sure I can maybe see if someone decides to upgrade to a pirated version of Vista,
instead of paving their machine like normal people do, this might come in handy....that's
assuming though that the tool gets picked up by the upgrade process, and that someone
who purchases a pirated copy of Vista is the sort of person who would leave a gem
such as this one installed on their machine.
&lt;/p&gt;
&lt;p&gt;
Okay, okay, I know that there are probably cases of normal users going to Thailand
and thinking to themselves "Well, here is a booth with Windows Vista DVDs, and they
are only wanting $30 for it...that's way cheaper than in the US...must be the currency
conversion rate", and so they accidentally get themselves a pirated copy of Windows.&amp;nbsp;
I would think that most people who are grabbing pirated copies of their OS are doing
it because they don't want to pay for the full version, and they are under no false
pretenses about the "Genuineness" of the product.
&lt;/p&gt;
&lt;p&gt;
The best part of this utility is the fact that once it figures out that your OS has
become pirated, it will "help you obtain a licensed copy".&amp;nbsp; That makes me feel
really confident about having this thing running all the time. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=812432d9-2af4-447b-8ef0-388f825eaba5" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,812432d9-2af4-447b-8ef0-388f825eaba5.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=4996b338-f8f5-4f47-a5d6-fee272b14a69</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,4996b338-f8f5-4f47-a5d6-fee272b14a69.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,4996b338-f8f5-4f47-a5d6-fee272b14a69.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=4996b338-f8f5-4f47-a5d6-fee272b14a69</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A little background:  I've been working with a SQL 2000 Reporting Server for
about 4 months now, trying to do some integration into an intranet app, and some reporting
conversion.  For the last 3 months or so, the web services API, and the ability
to publish from within Visual Studio have been gone.  Needless to say this has
put a serious damper on my ability to integrate RS into the client's intranet. 
I did some looking out on the web, and the newsgroups, and could never find anything
that quite worked.  The real interesting thing was that if IIS was refreshed,
I could use the Web Service API once, and only once.  If I attempted to connect
again, I would loose my connection, and not be able to connect again until IIS was
bounced.  What was really strange was that it looked like some data was being
sent, but eventually it would just give up.  Also strange was that this did not
seem to effect the Report Manager app that MS uses as the front-end for the report
server.
</p>
        <p>
Well, as you may guess, I wouldn't be writing this if I didn't have a solution (at
lest not with "Solved!" in the title), so here it is:  HTTP Keep-Alives. 
I disabled HTTP Keep-Alives on the "Default Web Site" and life was groovy again. 
I still need to check publishing from Visual Studio, but I can connect to the web
service API, which is a good first start.
</p>
        <p>
Its the little things in life that bring such joy.....
</p>
        <p>
          <strong>UPDATE:<br /></strong>So after moving right along for a little while with my HTTP Keep-Alive disabled,
I attempted to go to the ReportManager page to change the data source of a report. 
When I arrived, I was greeted by a 401 error.  WTF?  So for some unknown reason
the Keep-Alive is required by the Report Manager.  Since you can't enable or
disable the Keep-Alive at the Virutal Directory level, I was SOL. After trying some
stupid things that did not work (set the Connection: Keep-Alive header on the ReportManager
virtual dir), I finally found <a title="ASP.Net Bug" href="http://p2p.wrox.com/topic.asp?TOPIC_ID=4858">this
little gem on Google</a>. It seems that there is a bug in ASP.Net that will cause
it to suddenly drop the connection, even though there is still data.  The fix
is to grab your HttpWebRequest object, and set the Keep-Alive to false, and the ProtocolVersion
to HttpVersion10.  After doing this, life seems to be okay again.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=4996b338-f8f5-4f47-a5d6-fee272b14a69" />
      </body>
      <title>SQL Reporting Services Problems Finally Solved!</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,4996b338-f8f5-4f47-a5d6-fee272b14a69.aspx</guid>
      <link>http://www.drrandom.org/2007/03/09/SQLReportingServicesProblemsFinallySolved.aspx</link>
      <pubDate>Fri, 09 Mar 2007 16:04:35 GMT</pubDate>
      <description>&lt;p&gt;
A little background:&amp;nbsp; I've been working with a SQL 2000 Reporting Server for
about 4 months now, trying to do some integration into an intranet app, and some reporting
conversion.&amp;nbsp; For the last 3 months or so, the web services API, and the ability
to publish from within Visual Studio have been gone.&amp;nbsp; Needless to say this has
put a serious damper on my ability to integrate RS into the client's intranet.&amp;nbsp;
I did some looking out on the web, and the newsgroups, and could never find anything
that quite worked.&amp;nbsp; The real interesting thing was that if IIS was refreshed,
I could use the Web Service API once, and only once.&amp;nbsp; If I attempted to connect
again, I would loose my connection, and not be able to connect again until IIS was
bounced.&amp;nbsp; What was really strange was that it looked like some data was being
sent, but eventually it would just give up.&amp;nbsp; Also strange was that this did not
seem to effect the Report Manager app that MS uses as the front-end for the report
server.
&lt;/p&gt;
&lt;p&gt;
Well, as you may guess, I wouldn't be writing this if I didn't have a solution (at
lest not with "Solved!" in the title), so here it is:&amp;nbsp; HTTP Keep-Alives.&amp;nbsp;
I disabled HTTP Keep-Alives on the "Default Web Site" and life was groovy again.&amp;nbsp;
I still need to check publishing from Visual Studio, but I can connect to the web
service API, which is a good first start.
&lt;/p&gt;
&lt;p&gt;
Its the little things in life that bring such joy.....
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;UPDATE:&lt;br&gt;
&lt;/strong&gt;So after moving right along for a little while with my HTTP Keep-Alive disabled,
I attempted to go to the ReportManager page to change the data source of a report.&amp;nbsp;
When I arrived, I was greeted by a 401 error.&amp;nbsp; WTF?&amp;nbsp; So for some unknown&amp;nbsp;reason
the Keep-Alive is required by the Report Manager.&amp;nbsp; Since you can't enable or
disable the Keep-Alive at the Virutal Directory level, I was SOL. After trying some
stupid things that did not work (set the Connection: Keep-Alive header on the ReportManager
virtual dir), I finally found &lt;a title="ASP.Net Bug" href="http://p2p.wrox.com/topic.asp?TOPIC_ID=4858"&gt;this
little gem on Google&lt;/a&gt;. It seems that there is a bug in ASP.Net that will cause
it to suddenly drop the connection, even though there is still data.&amp;nbsp; The fix
is to grab your HttpWebRequest object, and set the Keep-Alive to false, and the ProtocolVersion
to HttpVersion10.&amp;nbsp; After doing this, life seems to be okay again.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=4996b338-f8f5-4f47-a5d6-fee272b14a69" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,4996b338-f8f5-4f47-a5d6-fee272b14a69.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=c06e0a30-50db-4166-b0d8-39f5f7c10f95</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,c06e0a30-50db-4166-b0d8-39f5f7c10f95.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,c06e0a30-50db-4166-b0d8-39f5f7c10f95.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=c06e0a30-50db-4166-b0d8-39f5f7c10f95</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
My wife and I have decided to try and put together a PVR box to make life a little
easier.  With Lana getting old enough to pay attention to grown-up TV, and the
fact that there are 4 shows we like to watch that happen at the same time, it seems
appropriate (not to mention being able to record Sesame Street for the baby).
</p>
        <p>
So here is what I’ve figured out so far:
</p>
        <p>
Linux-Based PVR using <a title="MythTV" href="http://www.mythtv.org">MythTV</a>.
</p>
        <p>
Pretty good eh?  So now for the hard part: Hardware.  So far I’m looking
at the <a title="Hauppauge WinTV" href="http://www.hauppauge.com/">WinTV</a> cards
with the hardware encoding/decoding.  They are fairly reasonably priced, and
fairly well supported.
</p>
        <p>
I’m also looking at the rather sharp <a title="Silverstone LC03V" href="http://www.silverstonetek.com/products-lc03.htm">SilverStone
LC03V</a> home theater component case.
</p>
        <p>
Not much info yet, but I’ll be keeping notes here as I go along and decide what will
work best.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=c06e0a30-50db-4166-b0d8-39f5f7c10f95" />
      </body>
      <title>Linux PVR - Part 1 (Prolouge)</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,c06e0a30-50db-4166-b0d8-39f5f7c10f95.aspx</guid>
      <link>http://www.drrandom.org/2007/02/24/LinuxPVRPart1Prolouge.aspx</link>
      <pubDate>Sat, 24 Feb 2007 20:23:11 GMT</pubDate>
      <description>&lt;p&gt;
My wife and I have decided to try and put together a PVR box to make life a little
easier.&amp;nbsp; With Lana getting old enough to pay attention to grown-up TV, and the
fact that there are 4 shows we like to watch that happen at the same time, it seems
appropriate (not to mention being able to record Sesame Street for the baby).
&lt;/p&gt;
&lt;p&gt;
So here is what I’ve figured out so far:
&lt;/p&gt;
&lt;p&gt;
Linux-Based PVR using &lt;a title="MythTV" href="http://www.mythtv.org"&gt;MythTV&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Pretty good eh?&amp;nbsp; So now for the hard part: Hardware.&amp;nbsp; So far I’m looking
at the &lt;a title="Hauppauge WinTV" href="http://www.hauppauge.com/"&gt;WinTV&lt;/a&gt; cards
with the hardware encoding/decoding.&amp;nbsp; They are fairly reasonably priced, and
fairly well supported.
&lt;/p&gt;
&lt;p&gt;
I’m also looking at the rather sharp &lt;a title="Silverstone LC03V" href="http://www.silverstonetek.com/products-lc03.htm"&gt;SilverStone
LC03V&lt;/a&gt; home theater component case.
&lt;/p&gt;
&lt;p&gt;
Not much info yet, but I’ll be keeping notes here as I go along and decide what will
work best.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=c06e0a30-50db-4166-b0d8-39f5f7c10f95" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,c06e0a30-50db-4166-b0d8-39f5f7c10f95.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=cb13d58e-e633-4206-b1ed-13f0193fae0d</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,cb13d58e-e633-4206-b1ed-13f0193fae0d.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,cb13d58e-e633-4206-b1ed-13f0193fae0d.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=cb13d58e-e633-4206-b1ed-13f0193fae0d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I've been reading the <span class="sans">"Framework
Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries</span><span class="sans">"
book recently, and I came across a section discussing interface design, which had
direct bearing on one of my earlier posts regarding programmer intent.  They
basically state flat out that you should never use marker interfaces in .Net. 
Instead, you should favor custom attributes, and then test the type for that attribute. 
This was interesting to me, since I have been trying to determine what, if any, value
marker interfaces would have in .Net.  In the Java example I cited, one of the
benefits was that the JavaDoc information associated with the interface would then
be attached to the class, so you would have clear intent from the developer when the
interfaces were used.  .Net documentation comments don't carry that same direct
association...granted, when the documentation is generated, most of the time there
will be a link to the interface definition..but it's not quite the same.  On
the other hand, generally a custom attribute will not even provide that link, so from
a doc standpoint there is less information available.  
<br /><br />
I think, though, that it is a bit more important to have the information about developer
intent available while reviewing the source code, which makes the custom attribute
concept a really good option.  You could even conceivably create a utility which
would grab the attribute information from the assembly meta-data and generate a report
containing which classes were marked with which interfaces, and therefore, which classes
were part of which patterns.  There would also be the ability to associate other
information with the attribute, such as a description, so you could have an attribute
which stated a class was part of a specific patter (say, Chain of Responsibility),
and then give a description of the component.  With that you could see specific
instances of Chain of Responsibility patterns within the code.  Attributes also
follow inheritance hierarchy, so that could make things more confusing, depending
on how the attribute was used on the more top-level classes.<br /></span><br /><br /><p class="poweredbyperformancing">
powered by <a href="http://performancing.com/firefox">performancing firefox</a></p><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=cb13d58e-e633-4206-b1ed-13f0193fae0d" /></body>
      <title>More on Marker Interfaces</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,cb13d58e-e633-4206-b1ed-13f0193fae0d.aspx</guid>
      <link>http://www.drrandom.org/2007/01/16/MoreOnMarkerInterfaces.aspx</link>
      <pubDate>Tue, 16 Jan 2007 17:15:01 GMT</pubDate>
      <description>I've been reading the &lt;span class="sans"&gt;"Framework Design Guidelines: Conventions,
Idioms, and Patterns for Reusable .NET Libraries&lt;/span&gt;&lt;span class="sans"&gt;" book recently,
and I came across a section discussing interface design, which had direct bearing
on one of my earlier posts regarding programmer intent.&amp;nbsp; They basically state
flat out that you should never use marker interfaces in .Net.&amp;nbsp; Instead, you should
favor custom attributes, and then test the type for that attribute.&amp;nbsp; This was
interesting to me, since I have been trying to determine what, if any, value marker
interfaces would have in .Net.&amp;nbsp; In the Java example I cited, one of the benefits
was that the JavaDoc information associated with the interface would then be attached
to the class, so you would have clear intent from the developer when the interfaces
were used.&amp;nbsp; .Net documentation comments don't carry that same direct association...granted,
when the documentation is generated, most of the time there will be a link to the
interface definition..but it's not quite the same.&amp;nbsp; On the other hand, generally
a custom attribute will not even provide that link, so from a doc standpoint there
is less information available.&amp;nbsp; 
&lt;br /&gt;
&lt;br /&gt;
I think, though, that it is a bit more important to have the information about developer
intent available while reviewing the source code, which makes the custom attribute
concept a really good option.&amp;nbsp; You could even conceivably create a utility which
would grab the attribute information from the assembly meta-data and generate a report
containing which classes were marked with which interfaces, and therefore, which classes
were part of which patterns.&amp;nbsp; There would also be the ability to associate other
information with the attribute, such as a description, so you could have an attribute
which stated a class was part of a specific patter (say, Chain of Responsibility),
and then give a description of the component.&amp;nbsp; With that you could see specific
instances of Chain of Responsibility patterns within the code.&amp;nbsp; Attributes also
follow inheritance hierarchy, so that could make things more confusing, depending
on how the attribute was used on the more top-level classes.&lt;br /&gt;
&lt;/span&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;p class="poweredbyperformancing"&gt;
powered by &lt;a href="http://performancing.com/firefox"&gt;performancing firefox&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=cb13d58e-e633-4206-b1ed-13f0193fae0d" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,cb13d58e-e633-4206-b1ed-13f0193fae0d.aspx</comments>
      <category>.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=b9218a06-498e-4522-8051-eec7bae30730</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,b9218a06-498e-4522-8051-eec7bae30730.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,b9218a06-498e-4522-8051-eec7bae30730.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=b9218a06-498e-4522-8051-eec7bae30730</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I recently ran across an intranet reporting
app which required IE6 (or, I should say, would not work with IE7 or FireFox 2). 
I upgraded to IE7 originally after numerous javascript errors, and a desire to check
out CardSpace, and thus far had not had too many problems.  This was a potential
issue, however.<br /><br />
Fortunately there is a ready made solution: Multiple IE's.  This little gem is
a single installer, which will allow you to install any version of IE from 3 through
6 in it's own folder so it does not interfere with the default install.  You
can pick it up at <a href="http://tredosoft.com/Multiple_IE">http://tredosoft.com/Multiple_IE</a><br /><br /><br /><p class="poweredbyperformancing">
powered by <a href="http://performancing.com/firefox">performancing firefox</a></p><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=b9218a06-498e-4522-8051-eec7bae30730" /></body>
      <title>Multiple IEs</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,b9218a06-498e-4522-8051-eec7bae30730.aspx</guid>
      <link>http://www.drrandom.org/2007/01/08/MultipleIEs.aspx</link>
      <pubDate>Mon, 08 Jan 2007 16:23:33 GMT</pubDate>
      <description>I recently ran across an intranet reporting app which required IE6 (or, I should say, would not work with IE7 or FireFox 2).&amp;nbsp; I upgraded to IE7 originally after numerous javascript errors, and a desire to check out CardSpace, and thus far had not had too many problems.&amp;nbsp; This was a potential issue, however.&lt;br&gt;
&lt;br&gt;
Fortunately there is a ready made solution: Multiple IE's.&amp;nbsp; This little gem is
a single installer, which will allow you to install any version of IE from 3 through
6 in it's own folder so it does not interfere with the default install.&amp;nbsp; You
can pick it up at &lt;a href="http://tredosoft.com/Multiple_IE"&gt;http://tredosoft.com/Multiple_IE&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p class="poweredbyperformancing"&gt;
powered by &lt;a href="http://performancing.com/firefox"&gt;performancing firefox&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=b9218a06-498e-4522-8051-eec7bae30730" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,b9218a06-498e-4522-8051-eec7bae30730.aspx</comments>
      <category>tips</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=701d85fe-aeaa-4f36-8e87-ae6173f9eb69</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,701d85fe-aeaa-4f36-8e87-ae6173f9eb69.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,701d85fe-aeaa-4f36-8e87-ae6173f9eb69.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=701d85fe-aeaa-4f36-8e87-ae6173f9eb69</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I was listening to the <a href="http://www.skyscrapr.net/blogs/arcasts/default.aspx">ArCast</a><a href="http://www.skyscrapr.net/blogs/arcasts/default.aspx?ID=595">recorded</a> with <a href="http://www.hanselman.com/blog/default.aspx">Scott
Hanselman</a> earlier today, and he was talking about the idea that <a href="http://www.hanselman.com/blog/ARCastnetInterviewedByRonJacobsAtTechEd2006.aspx">Non-Software
artifacts should approach zero</a>.  If you've seen some of his posts, or listened
to some <a href="http://www.hanselminutes.com">Hanselminutes</a> podcasts, you have
no doubt come across this idea before.  I like this particular phrasing mostly
because it gets to the heart of what I think one of the most often overlooked aspect
of the programming process is; Namely, the intent of the programmer.<br /><br />
I think this is one of the most important things to take into consideration when looking
at someone else's code (or even your code, more that about a week after you wrote
it).  There are a lot of subtleties about a design which go away after the code
is written and starts to gather dust.  If the developer had a particular design
pattern in mind when they built a class structure, this information exists only in
the mind of the developer, and maybe some technical spec doc which is lost in source
control, or share point somewhere.  Someone else comming along may look at that
class structure, and not see the scaffolding the original developer put there to support
that pattern, and will most likely simplify the design, removing the pattern in the
process.<br /><br />
One proposed solution to this, which I saw in a <a href="http://www.developer.com/tech/article.php/2106271">posting
from a java developer</a> was to use marker interfaces to communicate this sort of
intent.  That is, an interface which actually has no method declarations, but
exists only to mark a specific class as being part of a pattern.  One additional
advantage that the Java-Doc system allowed was the addition of the documentation around
that interface into the docs generated for the implementing class.  This is not
a bad idea, though it is terribly hard to enforce.<br /><br />
I think <a href="http://wf.netfx3.com/">Windows Workflow</a> will be a major contributor
in this arena, allowing very explicit declarative syntax for creating code. 
There may even be some potential to building WF activities around design patterns
(hmmm...maybe I have a project).  This idea ties into all sorts of other areas
of development, though. When designing web services the contract is what is used to
communicate the developer intent, and therefore creating super methods that take DataSets
or XML Blobs makes the contract basically useless.  .Net attribute-oriented programming
also allows for this sort of thing, though I can't see it being flexible enough to
serve as a declarative language extension (yet).  
<br /><br />
Once again I think we have no choice but to look at Unit Tests as the single most
effective way to communicate developer intent.  If the tests are named properly,
and test coverage is high enough, we should be able to see all of the requirements,
how the various components interact, and generally what the developer was thinking. 
I've even written tests which assert a particular class implements an interface simply
because I though that was a critical part of the design.<br /><br />
What is my point?  Well, I guess its really just the beginning of a though process
around how to better capture programmer intent.  What tools should there be? 
We all know documentation doesn't work.  Unless your doing Model Driven Development,
UML is usually as out of whack with the software as the documentation (or worse). 
And I think everyone agrees that putting this information in a word document is the
best way to ensure it does not end up in the final product.<br /><br /><br /><p class="poweredbyperformancing">
powered by <a href="http://performancing.com/firefox">performancing firefox</a></p><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=701d85fe-aeaa-4f36-8e87-ae6173f9eb69" /></body>
      <title>Capturing Programmer Intent</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,701d85fe-aeaa-4f36-8e87-ae6173f9eb69.aspx</guid>
      <link>http://www.drrandom.org/2007/01/02/CapturingProgrammerIntent.aspx</link>
      <pubDate>Tue, 02 Jan 2007 16:48:24 GMT</pubDate>
      <description>I was listening to the &lt;a href="http://www.skyscrapr.net/blogs/arcasts/default.aspx"&gt;ArCast&lt;/a&gt; &lt;a href="http://www.skyscrapr.net/blogs/arcasts/default.aspx?ID=595"&gt;recorded&lt;/a&gt; with &lt;a href="http://www.hanselman.com/blog/default.aspx"&gt;Scott
Hanselman&lt;/a&gt; earlier today, and he was talking about the idea that &lt;a href="http://www.hanselman.com/blog/ARCastnetInterviewedByRonJacobsAtTechEd2006.aspx"&gt;Non-Software
artifacts should approach zero&lt;/a&gt;.&amp;nbsp; If you've seen some of his posts, or listened
to some &lt;a href="http://www.hanselminutes.com"&gt;Hanselminutes&lt;/a&gt; podcasts, you have
no doubt come across this idea before.&amp;nbsp; I like this particular phrasing mostly
because it gets to the heart of what I think one of the most often overlooked aspect
of the programming process is; Namely, the intent of the programmer.&lt;br /&gt;
&lt;br /&gt;
I think this is one of the most important things to take into consideration when looking
at someone else's code (or even your code, more that about a week after you wrote
it).&amp;nbsp; There are a lot of subtleties about a design which go away after the code
is written and starts to gather dust.&amp;nbsp; If the developer had a particular design
pattern in mind when they built a class structure, this information exists only in
the mind of the developer, and maybe some technical spec doc which is lost in source
control, or share point somewhere.&amp;nbsp; Someone else comming along may look at that
class structure, and not see the scaffolding the original developer put there to support
that pattern, and will most likely simplify the design, removing the pattern in the
process.&lt;br /&gt;
&lt;br /&gt;
One proposed solution to this, which I saw in a &lt;a href="http://www.developer.com/tech/article.php/2106271"&gt;posting
from a java developer&lt;/a&gt; was to use marker interfaces to communicate this sort of
intent.&amp;nbsp; That is, an interface which actually has no method declarations, but
exists only to mark a specific class as being part of a pattern.&amp;nbsp; One additional
advantage that the Java-Doc system allowed was the addition of the documentation around
that interface into the docs generated for the implementing class.&amp;nbsp; This is not
a bad idea, though it is terribly hard to enforce.&lt;br /&gt;
&lt;br /&gt;
I think &lt;a href="http://wf.netfx3.com/"&gt;Windows Workflow&lt;/a&gt; will be a major contributor
in this arena, allowing very explicit declarative syntax for creating code.&amp;nbsp;
There may even be some potential to building WF activities around design patterns
(hmmm...maybe I have a project).&amp;nbsp; This idea ties into all sorts of other areas
of development, though. When designing web services the contract is what is used to
communicate the developer intent, and therefore creating super methods that take DataSets
or XML Blobs makes the contract basically useless.&amp;nbsp; .Net attribute-oriented programming
also allows for this sort of thing, though I can't see it being flexible enough to
serve as a declarative language extension (yet).&amp;nbsp; 
&lt;br /&gt;
&lt;br /&gt;
Once again I think we have no choice but to look at Unit Tests as the single most
effective way to communicate developer intent.&amp;nbsp; If the tests are named properly,
and test coverage is high enough, we should be able to see all of the requirements,
how the various components interact, and generally what the developer was thinking.&amp;nbsp;
I've even written tests which assert a particular class implements an interface simply
because I though that was a critical part of the design.&lt;br /&gt;
&lt;br /&gt;
What is my point?&amp;nbsp; Well, I guess its really just the beginning of a though process
around how to better capture programmer intent.&amp;nbsp; What tools should there be?&amp;nbsp;
We all know documentation doesn't work.&amp;nbsp; Unless your doing Model Driven Development,
UML is usually as out of whack with the software as the documentation (or worse).&amp;nbsp;
And I think everyone agrees that putting this information in a word document is the
best way to ensure it does not end up in the final product.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;p class="poweredbyperformancing"&gt;
powered by &lt;a href="http://performancing.com/firefox"&gt;performancing firefox&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=701d85fe-aeaa-4f36-8e87-ae6173f9eb69" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,701d85fe-aeaa-4f36-8e87-ae6173f9eb69.aspx</comments>
      <category>.Net</category>
      <category>TDD</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=4f726c1a-6f47-43fe-b7e8-46cffe3f70ea</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,4f726c1a-6f47-43fe-b7e8-46cffe3f70ea.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,4f726c1a-6f47-43fe-b7e8-46cffe3f70ea.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=4f726c1a-6f47-43fe-b7e8-46cffe3f70ea</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">Here are my results of the Superhero Personality
Test...Does it surprise anyone, really?<br /><br /><br /><p></p>
Your results:<br /><b>You are <font size="6">Spider-Man</font></b><table><tbody><tr><td><table><tbody><tr><td>
Spider-Man</td><td><hr align="left" noshade="noshade" size="4" width="80" /></td><td>
80%</td></tr><tr><td>
Green Lantern</td><td><hr align="left" noshade="noshade" size="4" width="65" /></td><td>
65%</td></tr><tr><td>
Iron Man</td><td><hr align="left" noshade="noshade" size="4" width="55" /></td><td>
55%</td></tr><tr><td>
Catwoman</td><td><hr align="left" noshade="noshade" size="4" width="55" /></td><td>
55%</td></tr><tr><td>
The Flash</td><td><hr align="left" noshade="noshade" size="4" width="50" /></td><td>
50%</td></tr><tr><td>
Hulk</td><td><hr align="left" noshade="noshade" size="4" width="50" /></td><td>
50%</td></tr><tr><td>
Superman</td><td><hr align="left" noshade="noshade" size="4" width="45" /></td><td>
45%</td></tr><tr><td>
Supergirl</td><td><hr align="left" noshade="noshade" size="4" width="40" /></td><td>
40%</td></tr><tr><td>
Robin</td><td><hr align="left" noshade="noshade" size="4" width="35" /></td><td>
35%</td></tr><tr><td>
Batman</td><td><hr align="left" noshade="noshade" size="4" width="35" /></td><td>
35%</td></tr><tr><td>
Wonder Woman</td><td><hr align="left" noshade="noshade" size="4" width="30" /></td><td>
30%</td></tr></tbody></table></td><td>
You are intelligent, witty, 
<br />
a bit geeky and have great<br />
power and responsibility.<br /><img src="http://www.thesuperheroquiz.com/pics/spidy.gif" /></td></tr></tbody></table><a href="http://www.thesuperheroquiz.com/"> Click here to take the "Which Superhero
am I?" quiz...<br /></a><br />
On a similar note...here are my supervillan results...I personally think I tend more
towards the joker, personally:<br /><br /><br /><br />
Your results:<br /><b>You are <font size="6">Dr. Doom</font></b><table><tbody><tr><td><table><tbody><tr><td>
Dr. Doom</td><td><hr align="left" noshade="noshade" size="4" width="60" /></td><td>
60%</td></tr><tr><td>
The Joker</td><td><hr align="left" noshade="noshade" size="4" width="60" /></td><td>
60%</td></tr><tr><td>
Lex Luthor</td><td><hr align="left" noshade="noshade" size="4" width="58" /></td><td>
58%</td></tr><tr><td>
Mr. Freeze</td><td><hr align="left" noshade="noshade" size="4" width="57" /></td><td>
57%</td></tr><tr><td>
Magneto</td><td><hr align="left" noshade="noshade" size="4" width="53" /></td><td>
53%</td></tr><tr><td>
Apocalypse</td><td><hr align="left" noshade="noshade" size="4" width="48" /></td><td>
48%</td></tr><tr><td>
Poison Ivy</td><td><hr align="left" noshade="noshade" size="4" width="44" /></td><td>
44%</td></tr><tr><td>
Green Goblin</td><td><hr align="left" noshade="noshade" size="4" width="44" /></td><td>
44%</td></tr><tr><td>
Riddler</td><td><hr align="left" noshade="noshade" size="4" width="40" /></td><td>
40%</td></tr><tr><td>
Dark Phoenix</td><td><hr align="left" noshade="noshade" size="4" width="39" /></td><td>
39%</td></tr><tr><td>
Juggernaut</td><td><hr align="left" noshade="noshade" size="4" width="36" /></td><td>
36%</td></tr><tr><td>
Kingpin</td><td><hr align="left" noshade="noshade" size="4" width="36" /></td><td>
36%</td></tr><tr><td>
Catwoman</td><td><hr align="left" noshade="noshade" size="4" width="34" /></td><td>
34%</td></tr><tr><td>
Venom</td><td><hr align="left" noshade="noshade" size="4" width="33" /></td><td>
33%</td></tr><tr><td>
Two-Face</td><td><hr align="left" noshade="noshade" size="4" width="28" /></td><td>
28%</td></tr><tr><td>
Mystique</td><td><hr align="left" noshade="noshade" size="4" width="24" /></td><td>
24%</td></tr></tbody></table></td><td width="250">
Blessed with smarts and power but burdened by vanity.<br /><img src="http://www.thesuperheroquiz.com/villain/pics/dr_doom.jpg" /></td></tr></tbody></table><a href="http://www.thesuperheroquiz.com/villain"> Click here to take the Super Villain
Personality Test</a><br /><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=4f726c1a-6f47-43fe-b7e8-46cffe3f70ea" /></body>
      <title>I figured as much</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,4f726c1a-6f47-43fe-b7e8-46cffe3f70ea.aspx</guid>
      <link>http://www.drrandom.org/2007/01/02/IFiguredAsMuch.aspx</link>
      <pubDate>Tue, 02 Jan 2007 15:34:33 GMT</pubDate>
      <description>Here are my results of the Superhero Personality Test...Does it surprise anyone, really?&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
Your results:&lt;br&gt;
&lt;b&gt;You are &lt;font size="6"&gt;Spider-Man&lt;/font&gt;&lt;/b&gt; 
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
Spider-Man&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="80"&gt;
&lt;/td&gt;
&lt;td&gt;
80%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Green Lantern&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="65"&gt;
&lt;/td&gt;
&lt;td&gt;
65%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Iron Man&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="55"&gt;
&lt;/td&gt;
&lt;td&gt;
55%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Catwoman&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="55"&gt;
&lt;/td&gt;
&lt;td&gt;
55%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
The Flash&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="50"&gt;
&lt;/td&gt;
&lt;td&gt;
50%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Hulk&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="50"&gt;
&lt;/td&gt;
&lt;td&gt;
50%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Superman&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="45"&gt;
&lt;/td&gt;
&lt;td&gt;
45%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Supergirl&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="40"&gt;
&lt;/td&gt;
&lt;td&gt;
40%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Robin&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="35"&gt;
&lt;/td&gt;
&lt;td&gt;
35%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Batman&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="35"&gt;
&lt;/td&gt;
&lt;td&gt;
35%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Wonder Woman&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="30"&gt;
&lt;/td&gt;
&lt;td&gt;
30%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td&gt;
You are intelligent, witty, 
&lt;br&gt;
a bit geeky and have great&lt;br&gt;
power and responsibility.&lt;br&gt;
&lt;img src="http://www.thesuperheroquiz.com/pics/spidy.gif"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;a href="http://www.thesuperheroquiz.com/"&gt; Click here to take the "Which Superhero
am I?" quiz...&lt;br&gt;
&lt;/a&gt;
&lt;br&gt;
On a similar note...here are my supervillan results...I personally think I tend more
towards the joker, personally:&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Your results:&lt;br&gt;
&lt;b&gt;You are &lt;font size="6"&gt;Dr. Doom&lt;/font&gt;&lt;/b&gt; 
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
Dr. Doom&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="60"&gt;
&lt;/td&gt;
&lt;td&gt;
60%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
The Joker&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="60"&gt;
&lt;/td&gt;
&lt;td&gt;
60%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Lex Luthor&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="58"&gt;
&lt;/td&gt;
&lt;td&gt;
58%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Mr. Freeze&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="57"&gt;
&lt;/td&gt;
&lt;td&gt;
57%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Magneto&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="53"&gt;
&lt;/td&gt;
&lt;td&gt;
53%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Apocalypse&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="48"&gt;
&lt;/td&gt;
&lt;td&gt;
48%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Poison Ivy&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="44"&gt;
&lt;/td&gt;
&lt;td&gt;
44%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Green Goblin&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="44"&gt;
&lt;/td&gt;
&lt;td&gt;
44%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Riddler&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="40"&gt;
&lt;/td&gt;
&lt;td&gt;
40%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Dark Phoenix&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="39"&gt;
&lt;/td&gt;
&lt;td&gt;
39%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Juggernaut&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="36"&gt;
&lt;/td&gt;
&lt;td&gt;
36%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Kingpin&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="36"&gt;
&lt;/td&gt;
&lt;td&gt;
36%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Catwoman&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="34"&gt;
&lt;/td&gt;
&lt;td&gt;
34%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Venom&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="33"&gt;
&lt;/td&gt;
&lt;td&gt;
33%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Two-Face&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="28"&gt;
&lt;/td&gt;
&lt;td&gt;
28%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
Mystique&lt;/td&gt;
&lt;td&gt;
&lt;hr align="left" noshade="noshade" size="4" width="24"&gt;
&lt;/td&gt;
&lt;td&gt;
24%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td width="250"&gt;
Blessed with smarts and power but burdened by vanity.&lt;br&gt;
&lt;img src="http://www.thesuperheroquiz.com/villain/pics/dr_doom.jpg"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;a href="http://www.thesuperheroquiz.com/villain"&gt; Click here to take the Super Villain
Personality Test&lt;/a&gt;
&lt;br&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=4f726c1a-6f47-43fe-b7e8-46cffe3f70ea" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,4f726c1a-6f47-43fe-b7e8-46cffe3f70ea.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=f2d3c686-bc60-4c6a-a133-4d765d89056d</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,f2d3c686-bc60-4c6a-a133-4d765d89056d.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,f2d3c686-bc60-4c6a-a133-4d765d89056d.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=f2d3c686-bc60-4c6a-a133-4d765d89056d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Okay, I admit it, this is a rant....But
I promised myself I would post more, so you have to take what you can...<br /><br />
So here's the deal, I've been peripherally involved in a project at my current client,
to the point that I know generally where things are going, but I haven't done any
code review or anything like that.  The good news is that the developer working
on it is fairly sharp, so I had no major worries....The fun comes when this developer
(who is a contractor like myself), decides to take a offer for another gig (for way
more $$, so who can really blame him).  Left in his wake is a new developer,
who is trying to figure out the business as well as the code, which is not a fun thing
to do, a stack of code, and deadlines which are not moving.  What is not left
is any sort of design artifact on the code side.  There were some data changes,
which have detailed ERDs, but nothing on the code side.  In looking at the code,
it seems reasonably well put-together, though there is way more tight-coupling than
I generally like to see, and a much deeper object hierarchy than I generally like
to work with.<br /><br />
Now allow me to wonder into dream-land for a bit...This is a situation where TDD would
pay off big-time.  For starters, it would be more likely that the code that was
left would be leaner than it currently is had this project been a TDD project. 
Also there would be the wealth of code artifacts that the tests provide.  At
a glance I could see which components are supposed to do what, and (assuming the test
writer thought this way) why certain components where there.  Then there is the
safety net for the massive refactoring that every developer does when they inherit
new code (you know, the guy who wrote it originally was an idiot...I never would have
done it this way...that doesn't make any sense...).<br /><br />
This is making me start thinking about mandating a TDD approach, or at least if not
mandating, fostering.  What is the best way to do that, though?  Everybody
knows that developers don't take kindly to being forced to do anything, particularly
when they see it as making their jobs more difficult.  And lets face it, the
sorts of tests that you get from someone who doesn't "get" TDD are things like "Test1",
"Test2"..."Test132".  What use is that?  So my challenge is to try to figure
out how to introduce a concept like TDD into an organization which really has no other
standards (there hasn't even been a decision regarding C# vs VB.Net), and where developers
have not used TDD before.  The biggest problem with TDD initially, is that developers
feel stifled.  Everyone is taught to think ahead, and try to create something
that is resilient to change.  TDD throws that idea out the window, and it is
damn hard to break that sort of thinking.  Particularly when your trying to baby-step
your way through functionality like properties, that have to be put together in a
particular way, and <i>should</i> have tests associated with them.  Why would
any rational developer spend the extra 10 minutes to write CanSetCustomerName CanGetCustomerName
tests when they can implement the properties and move on?  I think the only way
to do it is to figure out some way of showing first-hand where the benefits lie. 
Yes, I find writing tests for my accessors a bit redundant, but I take a great deal
of satisfaction at the end in the <i>information</i> that I have managed to communicate
about the code once it is done.  If I have a get test and a set test for a property,
then it is pretty obvious I wanted both.  If I only have a get test, but a I
defined a setter, then I know I can get rid of it.  There is also the knowledge
that those small things are what the larger body of the tests are built on, and I
think they provide a good way to ease into creating a new class in a TDD style. 
While your writing those get and set tests you have time to think about the classes
public API, and you can start to alter it a lot easier.<br /><br />
But back to the thoughts around introducing TDD....It is hard to show the added agility,
unless you are actively changing an existing project.  The Code Artifacts are
apparent, but a bit muddled and confusing.  The confidence that a full test suite
provides is also a bit hard to communicate, particularly to a skeptical audience. 
This is not an easy problem.  I think on one level it is easy to talk to developers
and tell them why this is a good thing (Scott Hanselman did an excellent job on his
TDD <a href="http://www.hanselminutes.com/default.aspx?showID=42">podcast</a>), but
experience shows that when the pressure to deliver starts cranking up, most developers
return to their old habits to "deliver the project on time", regardless of the amount
of time that may be lost down the road because it was not possible to do ruthless
refactoring.  It is also dangerous to try to introduce TDD on a critical project....if
for some reason it fails, or is delayed, there is likely to be some serious push-back
from management to TDD adoption.<br /><br />
It's not an easy problem....but I think I need to figure it out.  I think there
would be serious benefits to adopting TDD, especially in my current situation with
developers coming and going.  I'll just need to figure out how to share the enthusiasm,
and convince others that there really is no other way to develop software.<br /><br /><br /><p class="poweredbyperformancing">
powered by <a href="http://performancing.com/firefox">performancing firefox</a></p><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=f2d3c686-bc60-4c6a-a133-4d765d89056d" /></body>
      <title>Oh to live in a TDD world</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,f2d3c686-bc60-4c6a-a133-4d765d89056d.aspx</guid>
      <link>http://www.drrandom.org/2006/12/27/OhToLiveInATDDWorld.aspx</link>
      <pubDate>Wed, 27 Dec 2006 16:25:37 GMT</pubDate>
      <description>Okay, I admit it, this is a rant....But I promised myself I would post more, so you have to take what you can...&lt;br&gt;
&lt;br&gt;
So here's the deal, I've been peripherally involved in a project at my current client,
to the point that I know generally where things are going, but I haven't done any
code review or anything like that.&amp;nbsp; The good news is that the developer working
on it is fairly sharp, so I had no major worries....The fun comes when this developer
(who is a contractor like myself), decides to take a offer for another gig (for way
more $$, so who can really blame him).&amp;nbsp; Left in his wake is a new developer,
who is trying to figure out the business as well as the code, which is not a fun thing
to do, a stack of code, and deadlines which are not moving.&amp;nbsp; What is not left
is any sort of design artifact on the code side.&amp;nbsp; There were some data changes,
which have detailed ERDs, but nothing on the code side.&amp;nbsp; In looking at the code,
it seems reasonably well put-together, though there is way more tight-coupling than
I generally like to see, and a much deeper object hierarchy than I generally like
to work with.&lt;br&gt;
&lt;br&gt;
Now allow me to wonder into dream-land for a bit...This is a situation where TDD would
pay off big-time.&amp;nbsp; For starters, it would be more likely that the code that was
left would be leaner than it currently is had this project been a TDD project.&amp;nbsp;
Also there would be the wealth of code artifacts that the tests provide.&amp;nbsp; At
a glance I could see which components are supposed to do what, and (assuming the test
writer thought this way) why certain components where there.&amp;nbsp; Then there is the
safety net for the massive refactoring that every developer does when they inherit
new code (you know, the guy who wrote it originally was an idiot...I never would have
done it this way...that doesn't make any sense...).&lt;br&gt;
&lt;br&gt;
This is making me start thinking about mandating a TDD approach, or at least if not
mandating, fostering.&amp;nbsp; What is the best way to do that, though?&amp;nbsp; Everybody
knows that developers don't take kindly to being forced to do anything, particularly
when they see it as making their jobs more difficult.&amp;nbsp; And lets face it, the
sorts of tests that you get from someone who doesn't "get" TDD are things like "Test1",
"Test2"..."Test132".&amp;nbsp; What use is that?&amp;nbsp; So my challenge is to try to figure
out how to introduce a concept like TDD into an organization which really has no other
standards (there hasn't even been a decision regarding C# vs VB.Net), and where developers
have not used TDD before.&amp;nbsp; The biggest problem with TDD initially, is that developers
feel stifled.&amp;nbsp; Everyone is taught to think ahead, and try to create something
that is resilient to change.&amp;nbsp; TDD throws that idea out the window, and it is
damn hard to break that sort of thinking.&amp;nbsp; Particularly when your trying to baby-step
your way through functionality like properties, that have to be put together in a
particular way, and &lt;i&gt;should&lt;/i&gt; have tests associated with them.&amp;nbsp; Why would
any rational developer spend the extra 10 minutes to write CanSetCustomerName CanGetCustomerName
tests when they can implement the properties and move on?&amp;nbsp; I think the only way
to do it is to figure out some way of showing first-hand where the benefits lie.&amp;nbsp;
Yes, I find writing tests for my accessors a bit redundant, but I take a great deal
of satisfaction at the end in the &lt;i&gt;information&lt;/i&gt; that I have managed to communicate
about the code once it is done.&amp;nbsp; If I have a get test and a set test for a property,
then it is pretty obvious I wanted both.&amp;nbsp; If I only have a get test, but a I
defined a setter, then I know I can get rid of it.&amp;nbsp; There is also the knowledge
that those small things are what the larger body of the tests are built on, and I
think they provide a good way to ease into creating a new class in a TDD style.&amp;nbsp;
While your writing those get and set tests you have time to think about the classes
public API, and you can start to alter it a lot easier.&lt;br&gt;
&lt;br&gt;
But back to the thoughts around introducing TDD....It is hard to show the added agility,
unless you are actively changing an existing project.&amp;nbsp; The Code Artifacts are
apparent, but a bit muddled and confusing.&amp;nbsp; The confidence that a full test suite
provides is also a bit hard to communicate, particularly to a skeptical audience.&amp;nbsp;
This is not an easy problem.&amp;nbsp; I think on one level it is easy to talk to developers
and tell them why this is a good thing (Scott Hanselman did an excellent job on his
TDD &lt;a href="http://www.hanselminutes.com/default.aspx?showID=42"&gt;podcast&lt;/a&gt;), but
experience shows that when the pressure to deliver starts cranking up, most developers
return to their old habits to "deliver the project on time", regardless of the amount
of time that may be lost down the road because it was not possible to do ruthless
refactoring.&amp;nbsp; It is also dangerous to try to introduce TDD on a critical project....if
for some reason it fails, or is delayed, there is likely to be some serious push-back
from management to TDD adoption.&lt;br&gt;
&lt;br&gt;
It's not an easy problem....but I think I need to figure it out.&amp;nbsp; I think there
would be serious benefits to adopting TDD, especially in my current situation with
developers coming and going.&amp;nbsp; I'll just need to figure out how to share the enthusiasm,
and convince others that there really is no other way to develop software.&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p class="poweredbyperformancing"&gt;
powered by &lt;a href="http://performancing.com/firefox"&gt;performancing firefox&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=f2d3c686-bc60-4c6a-a133-4d765d89056d" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,f2d3c686-bc60-4c6a-a133-4d765d89056d.aspx</comments>
      <category>.Net</category>
      <category>TDD</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=353045b4-fcbc-4131-a88b-b0f471c6b0b5</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,353045b4-fcbc-4131-a88b-b0f471c6b0b5.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,353045b4-fcbc-4131-a88b-b0f471c6b0b5.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=353045b4-fcbc-4131-a88b-b0f471c6b0b5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
   It looks like, to help avoid confusion, and questions from developers,
Microsoft is renaming WinFx to the .Net Framework 3.0.  Evedently people were
under the impression that WinFX was a seperate entity.
</p>
        <p>
Here's the post:<br /><a href="http://blogs.msdn.com/somasegar/archive/2006/06/09/624300.aspx">http://blogs.msdn.com/somasegar/archive/2006/06/09/624300.aspx</a></p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=353045b4-fcbc-4131-a88b-b0f471c6b0b5" />
      </body>
      <title>WinFX By Any Other Name....</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,353045b4-fcbc-4131-a88b-b0f471c6b0b5.aspx</guid>
      <link>http://www.drrandom.org/2006/06/15/WinFXByAnyOtherName.aspx</link>
      <pubDate>Thu, 15 Jun 2006 17:11:21 GMT</pubDate>
      <description>&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;It looks like, to help avoid confusion, and questions from developers,
Microsoft is renaming WinFx to the .Net Framework 3.0.&amp;nbsp; Evedently people were
under the impression that WinFX was a seperate entity.
&lt;/p&gt;
&lt;p&gt;
Here's&amp;nbsp;the post:&lt;br&gt;
&lt;a href="http://blogs.msdn.com/somasegar/archive/2006/06/09/624300.aspx"&gt;http://blogs.msdn.com/somasegar/archive/2006/06/09/624300.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=353045b4-fcbc-4131-a88b-b0f471c6b0b5" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,353045b4-fcbc-4131-a88b-b0f471c6b0b5.aspx</comments>
      <category>.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=0ea53baa-6de8-4167-9857-783b8f6214b1</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,0ea53baa-6de8-4167-9857-783b8f6214b1.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,0ea53baa-6de8-4167-9857-783b8f6214b1.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=0ea53baa-6de8-4167-9857-783b8f6214b1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I just learned that Microsoft changed the
way unhandled exceptions in Threads are propogated in .Net 2.0 vs the way they worked
in 1.1.  With 2.0 any unhandled exceptions in a thread will not only cause that
thread to exit, but will also be bubbled up to the thread that started the offending
thread.  Overall, I think this is a good thing, since not only will it force
people to handle exceptions within their thread code, but it will also eliminate the
problem of processes mysteriously stopping if there is an unhandled exception on a
thread.  It will, however, cause some serious grief for any developers not expecting
that sort of behavior.  I'm sure I'm not the only one who has seen less than
steller multi-threaded programming tactics in applications which should be better
behaived (heck, I've done my share of shoddy thread handling in the past).<br /><br />
The one exception to this, of course, is the ThreadAbortException, which understandably,
only effects the thread it is raised on.  Granted using Thread.Abort, or raising
a ThreadAbortException is considered a brute-force approach, so it <i>shouldn't</i> be
happening anyway....<br /><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=0ea53baa-6de8-4167-9857-783b8f6214b1" /></body>
      <title>Thread Exception Change in .Net 2.0</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,0ea53baa-6de8-4167-9857-783b8f6214b1.aspx</guid>
      <link>http://www.drrandom.org/2006/05/31/ThreadExceptionChangeInNet20.aspx</link>
      <pubDate>Wed, 31 May 2006 15:47:26 GMT</pubDate>
      <description>I just learned that Microsoft changed the way unhandled exceptions in Threads are propogated in .Net 2.0 vs the way they worked in 1.1.&amp;nbsp; With 2.0 any unhandled exceptions in a thread will not only cause that thread to exit, but will also be bubbled up to the thread that started the offending thread.&amp;nbsp; Overall, I think this is a good thing, since not only will it force people to handle exceptions within their thread code, but it will also eliminate the problem of processes mysteriously stopping if there is an unhandled exception on a thread.&amp;nbsp; It will, however, cause some serious grief for any developers not expecting that sort of behavior.&amp;nbsp; I'm sure I'm not the only one who has seen less than steller multi-threaded programming tactics in applications which should be better behaived (heck, I've done my share of shoddy thread handling in the past).&lt;br /&gt;
&lt;br /&gt;
The one exception to this, of course, is the ThreadAbortException, which understandably,
only effects the thread it is raised on.&amp;nbsp; Granted using Thread.Abort, or raising
a ThreadAbortException is considered a brute-force approach, so it &lt;i&gt;shouldn't&lt;/i&gt; be
happening anyway....&lt;br /&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=0ea53baa-6de8-4167-9857-783b8f6214b1" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,0ea53baa-6de8-4167-9857-783b8f6214b1.aspx</comments>
      <category>.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=904d6399-33dd-42f4-b8b7-9aa7970ff203</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,904d6399-33dd-42f4-b8b7-9aa7970ff203.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,904d6399-33dd-42f4-b8b7-9aa7970ff203.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=904d6399-33dd-42f4-b8b7-9aa7970ff203</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Testing publishing directly from FireFox
with Performancing<br /><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=904d6399-33dd-42f4-b8b7-9aa7970ff203" /></body>
      <title>Quick Test</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,904d6399-33dd-42f4-b8b7-9aa7970ff203.aspx</guid>
      <link>http://www.drrandom.org/2006/05/24/QuickTest.aspx</link>
      <pubDate>Wed, 24 May 2006 17:34:36 GMT</pubDate>
      <description>Testing publishing directly from FireFox with Performancing&lt;br /&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=904d6399-33dd-42f4-b8b7-9aa7970ff203" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,904d6399-33dd-42f4-b8b7-9aa7970ff203.aspx</comments>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=026db1d7-1b92-4f24-a1e7-bc9f64f6bd5b</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,026db1d7-1b92-4f24-a1e7-bc9f64f6bd5b.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,026db1d7-1b92-4f24-a1e7-bc9f64f6bd5b.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=026db1d7-1b92-4f24-a1e7-bc9f64f6bd5b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">It just goes to show that there are always
little surprises waiting around the corner.  I've been looking at least casually
at .Net 2.0 since Beta 2, and I even read through the "What's New" for C# 2.0 to see
if I missed anything.  Somehow I managed not to notice Implicit Delegate Assignment
(or at least that's what I'm calling it).<br /><br />
It is now possible to assign a delegate using just the Class and Method name...you
no longer have to create a new instance of the delegate type.  Not a huge thing,
I know, but for those of us who are easily impressed it's, well, impressive.<br /><br />
Here's the skinny in code language:<br /><br /><pre class="brush: csharp">
public class SomeClass
{
    public event EventHandler MyEvent;
}

public class SomeOtherClass
{
    SomeClass _class; 
    public SomeOtherClass()
    {
        _class = new SomeClass();   
        // Old Way
        _class.MyEvent += new EventHandler(this.MyHandler);
        
       // New Way
       _class.MyEvent += this.MyHandler;
    }

    public void EventHandler(object sender, EventArgs args)
    {
        // Handler Code
    }
}
</pre><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=026db1d7-1b92-4f24-a1e7-bc9f64f6bd5b" /></body>
      <title>Learn something new every....</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,026db1d7-1b92-4f24-a1e7-bc9f64f6bd5b.aspx</guid>
      <link>http://www.drrandom.org/2006/05/24/LearnSomethingNewEvery.aspx</link>
      <pubDate>Wed, 24 May 2006 16:30:23 GMT</pubDate>
      <description>It just goes to show that there are always little surprises waiting around the corner.&amp;nbsp; I've been looking at least casually at .Net 2.0 since Beta 2, and I even read through the "What's New" for C# 2.0 to see if I missed anything.&amp;nbsp; Somehow I managed not to notice Implicit Delegate Assignment (or at least that's what I'm calling it).&lt;br&gt;
&lt;br&gt;
It is now possible to assign a delegate using just the Class and Method name...you
no longer have to create a new instance of the delegate type.&amp;nbsp; Not a huge thing,
I know, but for those of us who are easily impressed it's, well, impressive.&lt;br&gt;
&lt;br&gt;
Here's the skinny in code language:&lt;br&gt;
&lt;br&gt;
&lt;pre class="brush: csharp"&gt;
public class SomeClass
{
    public event EventHandler MyEvent;
}

public class SomeOtherClass
{
    SomeClass _class; 
    public SomeOtherClass()
    {
        _class = new SomeClass();   
        // Old Way
        _class.MyEvent += new EventHandler(this.MyHandler);
        
       // New Way
       _class.MyEvent += this.MyHandler;
    }

    public void EventHandler(object sender, EventArgs args)
    {
        // Handler Code
    }
}
&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=026db1d7-1b92-4f24-a1e7-bc9f64f6bd5b" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,026db1d7-1b92-4f24-a1e7-bc9f64f6bd5b.aspx</comments>
      <category>.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=55381b3d-ced0-41d5-b68f-90918369a400</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,55381b3d-ced0-41d5-b68f-90918369a400.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,55381b3d-ced0-41d5-b68f-90918369a400.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=55381b3d-ced0-41d5-b68f-90918369a400</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">The Dr. is back....after a few years away,
I've now decided to make DrRandom.org a blog...come back for more.<br /><p></p><img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=55381b3d-ced0-41d5-b68f-90918369a400" /></body>
      <title>Up and Running!</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,55381b3d-ced0-41d5-b68f-90918369a400.aspx</guid>
      <link>http://www.drrandom.org/2006/05/10/UpAndRunning.aspx</link>
      <pubDate>Wed, 10 May 2006 17:32:08 GMT</pubDate>
      <description>The Dr. is back....after a few years away, I've now decided to make DrRandom.org a blog...come back for more.&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=55381b3d-ced0-41d5-b68f-90918369a400" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,55381b3d-ced0-41d5-b68f-90918369a400.aspx</comments>
    </item>
  </channel>
</rss>