Setting Sail with the Smuggling Pattern :: Part 1

Maybe because I’m often entertained by the geekiest of things, I’ve started usage of the Smuggling Pattern named after a fellow software architect Matt Davis’s terminology of smuggling data into and out of Excel.  It is something that I’ve lately needed to do on a regular basis, get data into and out of Excel without Excel, or at least the evil COM Interop Model, really knowing what is going on.  In other words, I want total programmatic control over data so I can trust it versus Excel mangling my poor data up.  This is what the Smuggling Pattern is going to do for me, and it is doing it well.

Now you might think, “WTF!”  But just to clarify, the Smuggling Pattern is really the Builder Pattern that we architects know and love with a cooler more fun more pirate like name!  So with that, here’s some of that code, and the TDD process I undertook to get this sucker built to set sail.

First I created a C# Class Project and created the following file folder structure and files.

Once I completed that I jumped right into testing.  Of course with ReSharper it makes life so much friggin simpler, in addition to TDD making life simpler.  I do still admit, that if you’re not practiced at TDD, then doing tests in whatever order you are comfortable with still keeps you at peak performance.  But eventually you should work toward TDD and toss in a great tool like ReSharper.  The difference in speed and quality is almost like getting 2 of the 3 engineering axioms instead of just 1 (i.e. speed, quality, & cost).

The first tests I started on where the individual builder tests, or in my case the Smuggler Object.  I always create a check for null just to make sure that I named the file correctly, kind of a double check, and it gives me the attribute, category, and other parts that I can copy to the other tests easily.

using Production.Smugglers.Builders;
using NUnit.Framework;

namespace Production.Tests
{
    [TestFixture]
    public class SmugglerTests
    {
        [Test, Category("Builder Tests")]
        public void TestsSmugglerIsNotNull()
        {
            var smuggler = new Smuggler();
            Assert.IsNotNull(smuggler);
        }
    }
}

This test I ran and it proved that the smuggler does instantiate appropriately, albeit not doing a single useful thing yet.  Next test…

[Test, Category("Builder Tests")]
public void TestsSmugglerOrderCompletionResult()
{
    var smuggler = new Smuggler();
    smuggler.CompleteOrder();
    SmuggledClassForTest smuggled = smuggler.GetSmuggledSwag();
    Assert.AreEqual(smuggled.StuffTestValue, Resources.ValueForTestingSmugglerSmuggled);
}

Now this test, if you view the picture, didn’t color code so well.  ReSharper points out that the instantiated class smuggler doesn’t have a CompleteOrder or GetSmuggledSwag method.

image 2

Move the curser (and new character marker over the red method) and hit Alt+Enter (IntelliJ Keymapping) and select the Create method ‘Smuggler.CompleteOrder’.

Now we have no more red, and the class Smuggler now has the method CompleteOrder.  The same code that is displayed in the image is directly below it so it can be copied and pasted easily.  Also note, I went ahead and added the IBuilder interface to the class since it will need to meet the contractual obligations of the builder interface.

namespace Production.Smugglers.Builders
{
    public class Smuggler : IBuilder
    {
        public void CompleteOrder()
        {
            throw new NotImplementedException();
        }
    }
}

I then wrote the following additional test, below is the additional test and the ones I already completed in total.

[TestFixture]
public class SmugglerTests
{
    [Test, Category("Builder Tests")]
    public void TestsSmugglerIsNotNull()
    {
        var smuggler = new Smuggler();
        Assert.IsNotNull(smuggler);
    }

    [Test, Category("Builder Tests")]
    public void TestsSmugglerSmuggledIsNotNull()
    {
        Smuggler smuggler = new Smuggler();
        smuggler.CompleteOrder();
        SmuggledClassForTest smuggled = smuggler.GetSmuggledSwag();
        Assert.IsNotNull(smuggled);
    }

    [Test, Category("Builder Tests")]
    public void TestsSmugglerOrderCompletionResult()
    {
        Smuggler smuggler = new Smuggler();
        smuggler.CompleteOrder();
        SmuggledClassForTest smuggled = smuggler.GetSmuggledSwag();
        Assert.AreEqual(smuggled.StuffTestValue, Properties.Resources.ValueForTestingSmugglerSmuggled);
    }
}

After that I went ahead and fleshed out the following classes to get the smuggler tests to green light.  First I stuck a resource variable in for my “test variable value”.  One could do this another million ways but I figured this quick n’ easy.

This resource file is located in the Properties of the project.

   
  Find the resources by clicking the tab…

Then finished the interface (for now of course).

namespace Production.Smugglers.Builders
{
    public interface IBuilder
    {
        void CompleteOrder();
        SmuggledClassForTest GetSmuggledSwag();
    }
}

Then finished the Smuggler Class (i.e. Builder).

namespace Production.Smugglers.Builders
{
    public class Smuggler : IBuilder
    {
        private readonly SmuggledClassForTest smuggledClassForTest = new SmuggledClassForTest();

        public void CompleteOrder()
        {
            smuggledClassForTest.StuffTestValue = Resources.ValueForTestingSmugglerSmuggled;
        }

        public SmuggledClassForTest GetSmuggledSwag()
        {
            return smuggledClassForTest;
        }
    }
}

Then the little SmuggledClassForTests class, which is basically the product of the builder.

namespace Production.Smugglers.Smuggled
{
    public class SmuggledClassForTest
    {
        public string StuffTestValue { get; set; }
    }
}

Note the namespaces, I make a point to follow the standard of maintaining folder and namespace integrity.  I promise keeping the integrity makes getting to and finding code way faster than getting those things out of sync.

I then ran the tests again…

…green lights!

kick it on DotNetKicks.com

Technorati Tags: Builder,Pattern,Design,Architecture,Resharper,Visual Studio,.NET,dotnet,unit Tests,testing,TDD

del.icio.us Tags: Builder,Pattern,Design,Architecture,Resharper,Visual Studio,.NET,dotnet,unit Tests,testing,TDD

Some Cool Infoz for Keeping Up

John Lam is working on IronRuby at Microsoft.  This video over on InfoQ was rather interesting.  If you are curious which direction Ruby is going in the Microsoft world, this discussion gives some good insight and idea.

Look, a railroad system for Dutch Railways, being presented via a case study.  The case study being specific to how SCRUM accomplished a project that previously had failed.  The final audit of the software concluded:

  • The maintainability of the system is very good.- The quality of the source code is very high.

How can one NOT want that for the accomplishment of a project?  Come on, Lean, SCRUM, whatever you want to call it, Agile methods work, USE THEM!  The amount of failure that comes form not utilizing strong team based agile style processes is too massive to even contemplate further use in this day and age…  but enough of me ranting about non-agile methods.

Windows Live Tools have been released via a July CTP specific to VS.NET 2008.  These are something that I might actually use in the near future for some projects.  I ponder how I could utilize them in a transportation or transit related realm.

That’s all I got for right now, gotta jump back into my MVC and finish mocking up some examples.

Put Those Assemblies There :: Tip O' The Day

A little post build event can help a lot when one has multiple assemblies that need to be utilized by an application.  Such as the entlib or composite library.  Just put the following script in the post build event and make sure to create a directory were the assemblies will go.  Boom – you got everything in one place were you want it!

copy /y “$(TargetDir)$(TargetName).*”  “$(SolutionDir)..\build\references\”

Technorati Tags: Build,Post Build,Assembly

del.icio.us Tags: Build,Post Build,Assembly

Social Networks OMG

Oh…

My…

God…

WTF?

I’m sitting here on the floor of the new apartment, Joleen working on a large scale multi-page poster type thing that will adorn the wall and I’m digging through various social medium online.  The nature of this social medium is rather overwhelming these days and really makes me ponder what we can achieve through increased social interaction via the computer.

As is obvious, with myspace, Facebook, and the others (I remember when Friendster was the only real site out there) people are socializing online as never before.  If I remember correctly at first, it was the fast wit, smart, or maybe just crazy people all over IRC (that’s Internet Relay Chat for you noobs).  Tons of people chatting at any hour in any of thousands of chat rooms.  Then there were other chat rooms, forums, and chat with icons and emoticons moved in.  Before one realized there was just a whole mess of people blathering back and forth across the Internet.

Then came along the new trendy label of social networks.  Social networks are kind of like Web 2.0, very superficial in difference but slightly more user friendly and sophisticated.  Functionally, it isn’t any different than that bunch of elite folk bantering away in IRC.  The difference now is the sophisticated part of metadata, conversation and person tagging, and the ensuing relational correlations that can be drawn.  People can find stats of stats of more stats all over the Internet now in relation to their social standing.  Mind you, there are still about 5.8 Billion people not involved with this social network of the Internet on this level, but there are about 200 Million that are.  Between Japan, China, India, Europe (and England), and the United States the surge of interaction is massive.

There are so many things out there that intend, contend, and are pushing to be THE social network medium of the future.  But it isn’t the Internet as a whole they’re going for but instead the Enterprise, the small businesses, the local community neighborhood, or some other niche community.  One of the sites, that I watch once in a while is Jive Software.  Jive is right here in Portland and has become one of those it places to work and talk about.  The other social medium network site that I’ve followed closely, especially the more I’ve used it is linkedin.

But I can’t help but continue to wonder.  OMG, WTF!  Does this have return on investment?  Does it bring us truly more connected to each other?  Does it allow us to push ourselves even further away from those that are different and align ourselves more closely with those like us?  Does it allow for us to cut off the world we don’t want and not have to deal with reality?  Were does the line stand, is there a line, what is the line in relation to all this?

Is social networking doomed to keep giving us more and more of these TLAs?  Emoticons of absurdity?  Surprise [:O]

Many questions, which only time can clarify.

Until then I’m going back to my MVC playground.