One of the great things about ALT.NET is the variety of choices it affords.  However, this can also become an albatross around your neck when trying to choose a particular unit testing framework, mocking framework, IoC container, etc.  I mean, if you haven't tried most if not all of the choices, then you don't know what you're missing.  Of course you can read about the different options out there, but that's no substitute for trying them out for yourself.  Having said that, there's still a lot of utility in reading about them to exploit them to your advantage.  Thus, I recently moved out of my normal comfort-zone, (NUnit, Rhino.Mocks, Windsor Container) and tried some other technologies. 

What follows is a short description of my impression of a couple of Unit Testing frameworks that I've played with in the past couple of weeks.  Note that this is not intended to be an complete portrayal of each tool, but rather how I felt when attempting to use them.

NUnit

This is the old standby, but there's a 2.5 alpha that I hadn't tried.  I liked a lot of the changes that have gone into it, but found that too many things that I depend on for integrating with NUnit don't work with 2.5 yet.

XUnit

I like XUnit.  It's simple.  ALT.NET takes a bad rap for being hard to adopt, so one thing I try to emphasize is simplicity.  This is XUnit's strength.  If I were starting someone off in Unit Testing, I'd tell them to look at XUnit.  I have to admit that I do like the Constraint model in NUnit, however.  It just reads more naturally.  Also, pretty much everything works with NUnit, but not necessarily with XUnit (like TeamCity, currently).  So eventually, I went back to NUnit 2.4.8.  It worked fine with TestDriven.NET, however.

So the moral of the story is that software (including OSS) has momentum.  Once you get used to a certain way of development, it feels painful to switch, even if the other applications have some nice new features.

Conspicuously missing here is MbUnit, which I've tried in the past but again went back to NUnit eventually.  I'll have to try it out again soon.


 
July 29, 2008
@ 01:28 PM

The type name that you need to use in config files, such as for IoC containers, can be quite complex. For me, it's easier just to spike them than to try to remember the format gobbledy-gook.

public class GenericsTypeSpikes
{
    [Fact]
    public void The_name_of_a_complex_type_can_be_found_in_Type_AssemblyQualifiedName()
    {
        Type t = typeof(IList<ISource>);

        Assert.Equal("System.Collections.Generic.IList`1[[Blah.Core.ISource, Blah.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", t.AssemblyQualifiedName);
    }
}

 
Kick it! Digg it!  Categories: .NET Framework | IoC

Active Directory is funny.

Or should I say "permissions in Active Directory are funny."

I find that whenever I'm "stuck" on a problem for a good chunk of the day (AD or not) , about 80% of the time it's a permissions issue.  A couple of days ago I was stuck on an issue that I knew was a permissions issue, but I couldn't figure out why.  I mean, here I was, supposedly something of an development expert in directory services, but I couldn't get my DirectoryServices code to delete a simple AD object.  I could create objects, but I couldn't delete them.

Now, at this particular client they've tightened down the screws in their environment substantially, so simply increasing my permissions willy-nilly was out of the question.  No domain admin privileges here.  I'm not even sure any of the developers on this project even use Active Directory Users & Computers, they seem to only use home-grown LDAP tools for examining AD.  They are able to delete items with one particular home-grown tool, but it was written in VB - in all it's COM, late-binding, who-knows-what's-really-lurking-under-this-IUnknown-interface glory.

Has anyone ever tried to peer into the ObjectSecurity class?  It's not for the faint of heart.  And it wasn't something that I was going to be able to decipher in an afternoon.  So I downloaded the old Windows 2003 admin pack, installed it on my XP development box, and went into all the gory details that are AD ACLs.

The question was, why could the old VB code delete the object when my DirectoryServices code not do it?  According to AD Users & Computers, the credentials I was using did not have "delete" permission on the object.  I knew that.  That's what "access denied" usually means.  How could I explain this to the fellow who was successfully deleting with the VB code and expected me to do the same?  DirectoryEntry.DeleteTree() simply would not work. 

However, upon further examination, I could see that the OU that I was dealing with did allow my credentials to create and delete child objects.  Hmm...  One more quick test confirmed it.  Although DirectoryEntry.DeleteTree() failed, with the OU I could do DirectoryEntry.Children.Remove(objectInQuestion).  That's just crazy.  Boggles the mind.  But it works.

Of course, if the AD admins want to save another developer further grief (and there's no reason to believe they would - I know some sadistic infrastructure folks), then they'll just add the delete permission and avoid further confusion.


 
June 4, 2008
@ 11:42 PM

It's incredible how fast things can change if you turn off your developer technology radar for a few months.  I was pretty comfortable with my knowledge of what was out there around fall of '07.  I'd explored pretty much all the different tools and technologies that had tickled my fancy and even though I wasn't an expert in all of them, I knew that I could pick any one of them up pretty quickly if need be.  So down went my radar for awhile.

Holy cow.

Apparently not everyone has been as idle as I have been.  Here is a list that I compiled in a single afternoon of some things (I'm sure there are plenty more) that I'd like to try out in the not-too-distant-future to see if they can assist me in my daily chores.  What follows is not anything near a full review (basically I've pretty much only heard of them at this point), so my descriptions of what they are may be WAY off:

Gallio Unit testing framework agnostic unit test runner
Git Successor to Subversion???
Team City Continuous Integration competitor to CruiseControl.Net from the makers of ReSharper.  And, yes, it's free.
XUnit The "opinionated" unit testing framework
Pex Continuous testing
Spec# C# with built-in specifications - gives the user of a framework a better idea about how a class/method will behave.
ASP.NET 3.5 Dynamic Data Automatic CRUD that may actually work beyond simple scenarios

How about you?  What kind of technologies have you excited right now?


 
February 21, 2008
@ 10:10 PM

STSDEV is a code generation tool on CodePlex for SharePoint, kind of like my PoShGen, except much more polished.  It generates a starting project for several different kinds of scenarios - SharePoint Solutions, Features, & Web Parts.  I tried to bring it up on a box with Visual Studio 2008, however, and the app crashed.  It was trying to use the Microsoft.Build.BuildEngine.Engine object and fails.  I noticed that MsBuild.exe seems to work fine, so I posted a patch on CodePlex that replaces the routine that attempts to build the project with code that shells out to console (it's already a console app, so it uses the same window).  With that it works fine in 2008 and should work fine for VS2005, too.

You can get the patch for STSDEV here.


 

Wow, that was a lot of work.  I always hate when a screencast of demo starts with this big huge installation of a bunch of different technologies, but doesn't tell you how to get the same environment, so I started from scratch and show you how to go from a generic W2K3 base image to a fully functional TFS 2008 box and THEN show the Continuous Integration sample.  Due to the fact that we're going soup to nuts it's a pretty big screencast for me 34+ minutes - a new record for me.  I only wish complete installations like this REALLY only took 30-40 minutes.

Screencast: Continuous Integration and TFS 2008


 
January 25, 2008
@ 01:53 PM

My current project has me working on an Outlook 2003 Add-In (funny how clients aren't always up with the latest-and-greatest, huh?).  With it, I should be able to do just about anything in Outlook... if I only knew how.  The problem is that this project has a really short duration (2 wks.) and I've got to figure out how to do some things that I've never done before.  Usually I can find out all I need to know after a few sessions with Google, but info on Outlook Add-Ins (beyond the simple "Hello, World" style, which I can already do - there's a wizard, for heaven's sake) is pretty rare.  Most searches bring back references to Sue Mosher's Outlook books, but after looking at the contents, there's nothing in there about Add-Ins so far as I can tell.  The one book specifically about VSTO Add-Ins doesn't have any Outlook examples that I could find.  Sheesh.  I'm still installing VS 2008 on a box that has Office 2003 installed, which was another pain.  I tossed my copy of Office 2003 awhile back and had to go the the company software download area to get a copy.  So once 2008 is installed, with both support for Outlook 2003 & 2007, I'm hoping that they have some stellar documentation.

Anyone have any great tips for Outlook Add-In development?


 

I'm beginning to feel like Ayende @ Rahien with all my posts today.

I'm slowly coming to the realization that one of my favorite patterns, namely Presenter-First, just won't work well in the new ASP.NET MVC Framework.  Perhaps I should have expected trouble (and maybe I did just a little), since the MVC (Model-View-Controller) pattern is the antecedent of MVP (Model-View-Presenter) pattern.

In fact, Presenter-First may actually work better in the old ASP.NET WebForms than it does in MVC, though in a slightly kludgy way.  This is due to the fact that at least in WebForms events are supported through the "postback" mechanism, whereas the MVC Framework does not support postbacks (nor events from what I can tell).  Presenter-First  relies on events to connect the Presenter to both the View and the Model, and... well... there just is no capability for events from the View to the Presenter/Controller. 

Presenter-First simply acts as glue, abstracting the interface between the Model and the View.  The Model knows nothing of the View, and the View knows nothing of the Model, and neither cares.

Another point at which MVC collides with Presenter First is in the concept of an "MVP Triad" in Presenter-First.  The Triad is a logical connection between a specific Model, View, and Presenter.  The Presenter is more or less associated with a single view from what I've been able to tell, but in the MVC Framework, a controller (presenter) is capable of rendering many views.  Oy vey.  Things just get worse.

I still think I like the idea that the Presenter/Controller is as thin as possible, and that the View is even thinner (if possible).  The Model should handle all the grunt-work, as I advocate a Model which is more of an "application model" rather than a "data model." 

No matter how you go about it, you're going to lose the cool capability to use the same Model between both a web-based client and a smart client like WinForms or WPF.

Another problem that I see with the plain vanilla MVC is that you still have that old code-behind class (the web-pages are still .ASPX files after all, just without view state or postback), and it is ever so easy to stuff functionality in there where it does not belong in the code-behind.  Put your custom code in the application model, not in your view, and to a lesser extent not in your controller.  I do realize, however, that it is possible to forget WebForms altogether in the MVC Framework and to roll-your-own view engine or use one from Monorail.

Now, if I can just figure out how AJAX works with the MVC pattern... hmm.


 
January 7, 2008
@ 05:40 PM

I'm currently "in-between" projects here at the EMC Microsoft Practice, and partially through guilt that I'm not "producing" anything right now, I'm going to use this blog to assuage my guilt, somewhat.  I'll be using it (for the time-being) as what "blogs" were originally meant for, more or less.  That is, a diary of "stuff I do".  I'll try to continue to make it interesting, but it probably won't be as in-depth and as focused as in the past.  No, I'm not going to Twitter, since you don't need to know how many diapers I change a day (plenty today, let me tell you), etc., but I'll talk about each thing I work on for as long as my Attention Deficit Disorder allows.

Today I began by downloading code and watching/listening to some screen casts coming out of Microsoft for ASP.NET, namely the ASP.NET 3.5 "Extensions", which are really more like ASP.NET 3.6.  Pretty much the only thing I was originally interested in was the ASP.NET MVC Framework, which helps make TDD for web-sites easier to do, and that is always cool.  But there are other interesting things in these extensions as well, like "Dynamic Data", which appears to bring the Web to a point where VB6 was years and years ago, Point to some tables and "voila!", you've got a completely workable solution for instant CRUD.


I almost forgot, I have to do a phone-screen today.  In the past I've used the FizzBuzz test via Live Meeting, but I should probably come up with something a little more original.  How about:

Write a method for a console application that:

Performs a loop that goes from 3 - 99 by threes, prints the current time when the index is divisible by 4 and prints yesterday's date/time when the index ends in the digit 7.

That's a little harder (but only slightly) than Fizz Buzz, but still lets you gauge a candidate's basic coding ability, which is really all it needs to do.  The point isn't that there's one BEST solution, but rather it's illuminating to watch a simple problem like this be solved on the spot.  What if someone reads my blog and figures it out beforehand?  Well, if you read my blog, then you gotta be pretty good anyway, right?  You're hired!  How did it go?  You guys aren't the HR department, so I'm not gonna tell.


I've just spent more time than I'd like to admit finding a decent tool with which to write to my blog.  Back when I was using WSS 3.0 as my "blog engine" I used Word 2007 as my blog entry tool, but I've discovered today that it doesn't work so hot with dasBlog.  With dasBlog, I'd been either using the built-in web-based blogging functionality to dasBlog or BlogJet.  The trial for BlogJet has expired and I just can't bring myself to fork over about $47 US for the thing.  I just didn't get enough bang for that amount of buck.  So I'm back to using another free tool, "Windows Live Writer," which so far seems to work like a breeze, even with dasBlog.


Well, that's pretty much been my day today so far (after 5:30 PM here). Not that it's over. I'll probably be sitting here doing more or less the same thing until about bed time - or past.

Technorati Tags: ,,,

 
Kick it! Digg it!  Categories: .NET Framework | Agile | blogging | MVC

Well, not really.  From what I could tell the guys who were maintaining NCover and NCoverExplorer as OSS projects, have formed their own company, Gnoso.  Despite the title of this post, I’m not upset or anything.  I code for both fun and profit, why should I begrudge these guys their mortgage payment? 

Other OSS maintainers have also profited from their OSS efforts.  DotNetNukeCorporation & Interface21 (the folks behind Spring & Spring.NET) both offer support/consulting services for their respective OSS products.  The difference, however, is that both DotNetNuke and Spring.NET remain OSS, whereas NCover is now licensed software.  But it’s not like the price they’re charging is egregious – the Enterprise version is only $299, a drop in the bucket of any software development project.  And if that still causes you to choke, there’s the “Pro” version that’s only $149, not to mention that the older versions (< v 2.0) of NCover are still free.  So rock on Gnoso.  You’ll get my $299 sooner or later – as long as my boss or client lets me expense it!


 
October 28, 2007
@ 07:58 PM

As an experiment, I'd love to iterate via Reflection throughout the .NET Framework and see what percentage of classes are "sealed". I'd bet it's somewhere between 80-90%. Why? Will we hurt ourselves? It just frustrates me to no end when I see sealed classes. Why take away the power of polymorphism? Maybe I want to inherit from one of these fine classes.

It's like the feedback I gave back during the Visual Studio 2005 beta. I asked, "Why are the class and interface templates (like when adding a new class file) not public by default?" 99% of the classes I create are meant to be used by other assemblies. The answer I received was basically, "It's a security thing. This will not change." Yet here we are almost three years later and lo and behold, in Orcas they are public again. It seems kind of arbitrary.

I guess I shouldn't expect guidance from Microsoft to be either divinely inspired nor inerrant. I just wish they'd listen to me every once in awhile. It could have saved them from the "non-public" flip-flop at least. Maybe if we all shout loud enough they'll hear us on the "sealed" thing as well.


 
October 26, 2007
@ 08:58 PM

You might be saying to yourself, wouldn't this be your first big idea? Well, no. I just haven't talked about a lot of them before. I need something "enterprisey" (and I don't mean that in a bad way) to occupy my learning time, which is generally about 10pm to 2am. I've tried a few things – checking out http://rentacoder.com or http://topcoder.com, or thought of a few ideas, like writing a text based game or a utility, working on an open-source project, or starting an open-source project. They seem to last for a couple days and then I become disinterested.

I think I've found something that I may be able to sink my digital teeth into for awhile. Membership/Role Providers & Portals. Except for the default SQL provider, and there's nothing wrong with that, the others are over bloated and too tightly coupled. The AD Membership & Role providers, for instance, are a big pile of… well, you get the idea. And the documentation is lousy. I mean, none of the code for one ever works the way I expect, and the configurations are incomprehensible. There's no separation of concerns, and you can't even TEST one outside of ASP.NET. What about the ASP.NET MVC Framework? We'll need something that's testable, and we'll need Models, Views, and Controllers/Presenters since the idea of "web-controls" may largely go out the window. Same for Monorail right now. Perhaps with NHibernate as a data-access scheme you could do something interesting. log4net could be used to capture instrumentation statistics in a DB or ADAM.

Here's one – Do you hate to extend AD just to accommodate the AD Membership Provider? Me too. I've messed up AD on more than one occasion doing that. How about we "extend" AD into a SQL Server DB, but keep the other authentication mechanisms elsewhere? How about allowing people to use multiple unique values in a directory (AD, SQL, ADAM, etc.) as login name, such as username, UPN, email address, customer number, etc.

And how come there aren't any "starter portals" out there where you can go out and do all the good things that put a face on these providers to the public. Single Sign On? It's a chore, but doable right now. Let's make it easy. I'm committing myself to it! <tongueInCheek>at least until I get bored with it and move on</tongueInCheek>


 

(Wow - I'm 2 for 2 on PoShGen, links are fixed on this post, too.  I need unit tests for my blog!)

OK, I admit it, what was available in 0.0.1 was possible using Enterprise Templates (if those things are still around – haven't looked at them in YEARS), though PoShGen is MUCH faster at it. And now in PoShGen 0.0.2 you can add multiple files after the initial solution is created – a Model View Presenter (MVP) "triad" a-la the Presenter-First flavor of MVP (and their respective test classes into a different project, at the same time).

Right now PoShGen is only a set of PowerShell functions, not a true PowerShell script – so you have to either "run" the script to put the functions in memory or what I do – copy and paste the script (via a simple right-click in the PowerShell console window), which works pretty well for me currently. I'm sure eventually things will get to be too big to copy & paste comfortably, but by then I'll probably be further along in Windows PowerShell in Action and can write a decent script.

Look at the last lines of the PoShGen.ps1 file to get an idea about how to call the two main PoShGen functions, NewApp and AddMvp.

Future plans for PoShGen include:

  • Adding an individual Model->Presenter->View event sequence to an existing MVP triad
  • Adding new Class/TestClass pairs to the solution
  • Other things as I run into them, in an attempt to remain DRY
  • Features requested by YOU, dear reader! Let me know what you think by either commenting below or send me an email at dseelinger@gmail.com

Don't forget to download your copy of PoShGen 0.0.2 here.


 
October 3, 2007
@ 08:54 PM

I'm really excited about the new functionality in C# 3.0. With all the great extensions to the C# language, writing DSL-like code is going to be easier than ever. And writing DSL is the key to writing intentional code that your customer (whoever that may be) will more likely understand, appreciate, and use as the excuse to keep you on for the next project.

However, there are some issues with Orcas that are preventing me from going all out with it as my personal environment. Lack of proper ReSharper 3.0 support for Orcas is a big barrier for me. Sure, they say they have Orcas support, but only when working with non .NET 3.5 features. Place some C# 3.0 specific code in your class and ReSharper lights up Orcas like a Christmas Tree – errors detected everywhere, though you can compile just fine. ReSharper's parser just can't handle C# 3.0 yet. I'm sure it will eventually. So why can't I live without ReSharper? I'm sure I could, but it would be like the rest of the MS developer world going back to the pre-Intellisense days. There are simply too many modern conveniences built into ReSharper. I could turn off ReSharper syntax highlighting, but that disables about half of the useful features of ReSharper (in addition to simply syntax highlighting).

Besides weak ReSharper support in Orcas, another problem I have is that my ISP does not yet support .NET 3.5. Granted, not many do, but this limits me to posting source code. I can't write anything cool and run it on my site. If anyone knows of any FREE .NET 3.5 sites out there, let me know. I've already pushed the WAF (Wife Acceptance Factor) on my current ISP spending. Hmm… Note to self: maybe it's time to start accepting donations.

So there you have it – yes, I will continue to "play" with Orcas, but serious work, either professionally or in my own spare time, will remain in the .NET 2.0 world. Maybe I can keep "upgrade" in mind as I write my "donation site" code in .NET 2.0.


 
September 7, 2007
@ 08:50 PM

Have you ever had a moment while working with the .NET Framework when you thought, "Hey, they forgot a method in this class!"  For me, that was in the beta for 1.0 when I was working with a lot of delimited text.  The String class had a nice Split() method, but the method only accepted a single character as the delimiter.  Why in the world would anyone ever use more than a single character to delimit text?  Oh, wait.  What about quoted strings?  There are other possibilities as well.  So I was forced to explore the possibility of extending the String class.  Should be simple enough, just inherit from String and off we go.  Then I discovered the sealed keyword.  If I wanted to extend string now, I would have to wrap every string method and property in another class and add my own Split method to that.  On second thought... nah.  Too painful.

I sure wish C# 3.0 had been around in those days - or is that an oxymoron.  Maybe, kind of.  But it sure would have been good to have Extension Methods back then.  I've read about extension methods in C# 3.0 more than once, but it never really dawned on me how something like this could be used until the other day, and then I realized a few ways it could be useful.  So how do you add the functionality into a sealed class that MS forgot?  Like so:

namespace TestProject1
{
    public static class Extension1
    {
        public static string[] Split(this string theString, string theDelimiter)
        {
            //...functionality goes here.
        } 
    }

    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void SplitTest()
        {
            Assert.AreEqual(3, "My--three--words".Split("--").Length);
        }
    }
}

Simple enough.  I know, MS fixed it in a later framework, but it was a pain at the time.  And before you say, "You could have fixed this with a utility class Utility.Split(myString, myDelimiter)."  Yes, that's what I ended up doing in those situations, but it sure isn't as clean as saying String.Split()String should have control over its own fate, not be imposed upon by utility classes - at least it should look that way.  "Looking the way it should" has something to do with Domain Specific Languages.  Essentially with Extension Methods you could code something that is immensely more readable and closer to your target domain than the general language or framework.  For example, if your particular target domain often needs to calculate a certain amount of time-lapsed, then it could be done like: 20.Minutes().Ago().  That's very intentional and much more readable than DateTimeUtil.CalculateTimeInPast(TimeSpanUtil.ToMinutes(20));

namespace TestProject1
{
    public static class Extension2
    {
        public static TimeSpan Minutes(this int numMinutes)
        {
            return new TimeSpan(0, numMinutes, 0);
        }

        public static DateTime Ago(this TimeSpan duration)
        {
            return DateTime.Now.Add(-(duration));
        }
    }

    [TestClass]
    public class UnitTest2
    {
        [TestMethod]
        public void DomainSpecificLanguageTest()
        {
            Assert.IsTrue(20.Minutes().Ago() < DateTime.Now);
        }
    }
}

Full disclosure: I didn't come up with the 20.Minutes().Ago() example, I think I heard it from Scott Hanselman, though I didn't grok it at the time, not until I saw Extension Methods one more time. I'm going to start looking at problems like this with a fresh set of eyes now.


 

I've done a couple more experiments with a simple "Hello World" version of a Presenter First style app.

With the first one, I've gotten rid of the manual mock objects (less code to maintain) and replaced it with dynamic mock objects from Rhino Mocks. I do believe that Oren Eini has thought of everything when he made Rhino: source code here

And with the second one, I've utilized not only the dynamic mocks, but also Windsor Container for the Windows Forms app, and an auto-mocking container developed by the folks at Eleutian for the TDD test. I must say, however, that it was a little tricky getting the Presenter object in the right state for auto-mocking + testing. At first I couldn't "auto-mock" the Presenter object before I'd obtained the View mock. The Presenter constructor was setting up the event subscription to the view, but I couldn't get to the Auto-Mocked view until the Presenter constructor was already called, which messed up my mock recording/playback sequence. Therefore, I had to add an "Initialize" method to the Presenter object. Again, it's a little more code in the short run, but if this were an extensive application, there would be a heck of a lot less monotonous configuration code for all the dependency injection stuff. I love the fact that the Windows Forms app has absolutely no idea what objects are being created for its use. That's all up to the configuration file: source code here


 

As mentioned in my last post, my first "Tech TODO" was to wrap my head around the "Presenter First" pattern. There are several videos (part 1, part 2, & part 3) from Ron Jacobs on the concept, and he spoke about it at Tech Ed 2007 in Orlando as well. The guys at Atomic Object also have several papers and what they consider a pretty simple example of Presenter First in action. Now, I'm not an agile newbie. I've written a couple apps that use the "Humble Dialog" approach to separating the GUI from the business objects in a testable way, but I could not for the life of me figure out how to "do" Presenter First from any of the available stuff online. Well, I did figure it out, but it took way-longer than I thought, based on how everyone was saying it was such an easy concept. Frankly, if you're not used to using events and delegates, it takes awhile to grok.

So in the spirit of sharing, I'm posting my first go-around with Presenter first. This is by far the simplest version of a Presenter First style app I've seen to date. Granted, it's useless for anything except to help you understand Presenter First, but then again, that's its purpose.

There are only about 50 lines of code, and honestly, Mort would have done this in about one line of code after double clicking the form's only button in the designer, but the thing is, he could never have automated tests for it! This is a case where the outcome (testable GUI) is worth a little extra work.

There following files are the interesting bits – first for the testable part:

  • IModel.cs & IView.cs – the interfaces for the model and view (duh)
  • MockModel.cs & MockView.cs – these are "manual mocks" (I wanted to keep it simple) for testing, and since I don't yet understand how to mock events and delegates in Rhino Mocks, yet.
  • Presenter.cs – the glue that ties things together, and more or less the main character in this exercise.
  • Test.cs – contains the Unit Tests for… testing

…and finally for the "live" windows form app:

  • Model.cs – the "real" model, and a very simple one, indeed (Prints "Hello world")
  • View.cs – a Windows Form, and the "real" view
  • Program.cs – the app runner, for any normal windows forms app

So there you go. You can get the source code here. Enjoy!


 
June 22, 2007
@ 08:17 PM

I'm almost afraid to post this because the list will be so long. Anyway, here are some technologies in which I'd like to be proficient in the not too distant future:

Presenter First pattern

Unit testing for GUIs (a TDD technique)

MbUnit

Unit testing tool. From now on, I'll only use NUnit when it's the client's choice. I hear that the "Mb" stands for "much better".

Rhino Mocks

The best mock object tool out there.

log4net

A tool to help output log statements to a variety of output targets

Castle: MicroKernel & Windsor Container

My current "Dependency Injection Container"

Castle: ActiveRecord

Data access later from the Castle project based on the ActiveRecord pattern. Built on top of NHibernate

Aspect#

An Aspect Oriented Programming framework for the .NET framework

MonoRail

Basically, Ruby on Rails for .NET

Dynamic Proxy

For creating lightweight proxy objects on the fly in .NET

NVelocity

Kind of like ASP.NET's <% %> functionality, but with better MVC semantics (useful for MonoRail, I think)

MS Windows Communications Foundation

Next-gen web services from MS

MS Windows Workflow Foundation

Create "resumable" applications

MS patterns & practices Application Blocks

  • Caching
  • Composite UI
  • Cryptography
  • Data Access
  • Exception Handling
  • Logging
  • Policy Injection
  • Security
  • Validation

MS patterns & practices software factories

Something for Mort (I'm not Mort, though. I'm more like Hugo). Sometimes you gotta suck it up and take one for the team, though.

  • Mobile Client
  • Smart Client
  • Web Client
  • Web Service

ASP.NET AJAX

I guess I've dodged this bullet long enough.

 

My current competency in these technologies ranges anywhere from semi-competent, to inept, to "all I know is that it sounds cool".


 

Last night's "Birds of a Feather" Session on "Creating Flexible Software: TDD, Mocking, and Dependency Injection" was the best session yet here at Tech Ed 2007. Some of the best minds using Microsoft technologies were on hand to hear James Kovacs (http://jameskovacs.com/) lead the discussion on all of the above. There were several skeptics in the audience who questioned the viability of not only mock objects, but also unit testing in general. Really understanding the "Separation of Concerns" argument is pretty much all anyone needs to understand in order to "see the light"… I'm still searching for a good Separation of Concerns article on the web for a needed link. Anyway, using Mocks, you can achieve a good SOC model. Now, I don't know if there were any that were converted last night, but I could tell that some definitely wanted to believe that such techniques could help them build better software.

I look forward in the near future to start applying these principles to my current and future projects.


 
June 4, 2007
@ 07:07 PM

I'm sitting in my first Tech Ed breakout session.  It's titled "Ron Jacobs on the Architecture Landscape".  If you don't know Ron Jacobs, he's a member of member of the Microsoft Architecture Evangelism team.  The title was pretty vague, but since I listen to ARCast (http://channel9.msdn.com/shows/ARCast.TV) I decided to attend.  So far (and we're only about 1/2-way through) he's discussed TDD, MVC, MVP, NMock, RhinoMock, and even the "Humble Dialog"!

 He's really doing a great job.  It may be more information than those without at least a basic understanding or agile development can absorb.  I'm even learning some things!  I just learned that the way I'm naming my Humble Dialog views methods/properties is wrong.  I'm going to listen more now.

Later…

The talk is long over now, and the "content" here at Tech Ed regarding Agile development methodologies is significant and deep. Not once from any of the presenters have I heard the words "generating tests" and that's good news. In Ron's talk, he had a video segment featuring Peter Provost. Peter seems to be the "Tour de Force" for some agile principals and practices at Microsoft. I got a chance to talk to both Peter and Ron after their talk down at the Architecture booth in the "blue" area at Tech Ed (the yellow, green and blue areas are where mostly MS folks hang out to chat about their "stuff"). It's great interaction with the "blue shirts" (Microsoft staff) and they're eager to talk. The thing that I found significant was that it seems that a lot (if not most) of the talk around the Architecture blue shirts is around Agile. Now, I'm sure there are plenty of SOA talks going on as well, but I can almost fill my schedule with agile stuff around here.

Anyways, I asked both Peter and Ron what their experience was within Microsoft regarding the spreading of Agile practices. It sounds like Peter is telling anyone who will listen about the TDD gospel. And that's great – I hope people listen.


 

So you're a .NET developer and you want to know what all this "Agile" garbage is? How do I do TDD? How do I test, effectively? I found myself asking these questions a few years ago, and I had no one to guide me. In my organization there was no one who was practicing agile… practices. First I found http://www.extremeprogramming.org/ - but it was hard for me to follow. Then I found (what I assume is) the original XP Wiki http://c2.com/cgi/wiki?ExtremeProgrammingRoadmap. That contained a wealth of information. It also led me to a couple of Yahoo groups "Extreme Programming" and "Test Driven Development". Most of the info was pretty non-MS specific, though .NET developers are now more accepted than ever among the ranks of agile practitioners. I noticed that one of more knowledgeable posters on the group was named Ron Jeffries. I saw that he had a site. I checked it out at www.xprogramming.com.

And there I found it. Ron had written a book. He'd written more than one actually, but this one was of particular interest to me: "Extreme Programming Adventures in C#." C#! Now that was something I could use. I ordered it immediately from Amazon. I knew very little about NUnit, etc. at the time, so this was great. I'd had some theory, but this book put it into practice. In this book Ron goes from concept to finished product for an XML editor written in C# using agile development practices. He, along with his faithful sidekick, Chet, were my mentors, though they'd never met me. I recently contacted Ron to ask permission to use one of the examples in his book in an upcoming screen cast (keep posted for sometime in June I hope) and he is graciously allowing me to do so. I mentioned the book as well and he says that it hasn't done well in sales. I can't believe it! I've touted this book to anyone who would listen (and have an interest, I'm not weird… well, not very).

So the moral of the story is, if you're a C# developer and want to know how to "do agile", then order this book today! If you don't like it, then send it to me!! I lent mine to a friend at Microsoft and he moved away to Redmond and took it with him!


 

Note to self, "If you ever see an error that says 'Cannot get IIS pickup directory' then you can bet that the account trying to send mail doesn't have access to the appropriate path in the IIS Metabase."

Sending mail via SMTP

Sending mail in the old ASP.NET 1.1 days sure was easy. Create a message, send a message. Not so in .NET 2.0. I can send mail, but only after pain that I usually feel after a dental visit. Take the following scenario:

Impersonation

For various reasons, we don't want to run a particular ASP.NET application as NETWORK SERVICE. Elsewhere, outside of ASP.NET, we have an account that acts as a service account in a couple of different scenarios regarding our overall application. It seemed like the perfect candidate for an "impersonation" (after all, I couldn't keep on impersonating as my domain admin account forever – security? What's security?). So it was pretty easy to switch out the old impersonation (the admin account) for the new (the service account).

Well, you guessed it. Nothing worked anymore. I had to track down each and every area that this account needed new permissions:

  • The virtual directory
  • ASP.NET Temporary Files
  • Active Directory
  • …and finally, and by far the biggest pain… SMTP

Local SMTP and the "Pickup Directory"

We're using the local virtual SMTP server to send individual emails to users, like when they reset their password, for example. It took the better part of an afternoon, but I finally figured out the problem and solved it. You have to use the IIS 6.0 Resource Kit Tools – Metabase Explorer in order to grant the impersonated user the proper access to the area that stores the "Local IIS Pickup Directory" entry. You're supposed to be able to run run aspnet_regiis.exe –ga [username], but it was ineffective as far as SMTP was concerned. What's an even bigger pain is that none of the permissions within the IIS Metabase path to the IIS Pickup Directory entry were "inheritable" so for each node in MachineName( local )/LM/SmtpSvc/1 you have to grant permission before the impersonated user is able to send SMTP mail. I was surprised that Google was of so little help. I can't imagine that sending mail via localhost during impersonation is a unique situation.


 
Kick it! Digg it!  Categories: SMTP | .NET Framework