Get Visual Studio 2005 and SQL Server 2005 for free at a launch event – level 000

That’s right.  Attend a launch event, and you’ll get the standard
version of that software for free.  That’s very valuable if your
company doesn’t provide copies for your personal use.  SQL Server
standard is plenty capable for most database requirements as
well.  These are full versions, not Express version. 

The Austin MSDN Event launch is sold out, but the Houston event on Dec
6th is still accepting registration, so go reserve your spot now.

GotDotNet.com is DOWN. Has been down all day – level 000

I’m almost completely fed up with GotDotNet.  I’ve been using them
to host my EZWeb workspace:
http://www.gotdotnet.com/workspaces/workspace.aspx?id=949a0c93-38f2-4bd2-9f69-a49bb3c7938d

I’m sorry you can’t get to the download right now.  I’m going to
have to pull my workspace and host it myself.  I need something
reliable.  They have been down all day, and when the site _is_ up,
it’s very slow.

Simple dependency injection to get you started with unit testing – level 200

More and more people are talking about unit testing, and I’m glad.  There is confusion, however, with unit testing and integration testing, and some folks don’t know there is a difference.  Unit testing is testing code in isolation without exercising code not under test.  Simply put, if I have a class that handles data that is stored in a file, I want to test my custom class without actually exercising the file system.  How do I do that?  Why do I want to do that.  I’ll tackle the why first.  If a test requires that an actual file exists, then you have a pretty significant dependency in your code.  Your code can never run (can never be tested) except by working with the actual file on a file system configured with the correct permissions.  This is fraught with environmental headaches.  Unit tests should be simple and fast.  The unit tests should pass everywhere, not just on one magic environment where everything is painstakingly set up.

Here’s how:  Consider the following code with a test:


    1 using NUnit.Framework;


    2 


    3 namespace DIPSample


    4 {


    5     [TestFixture]


    6     public class DataManagerTester


    7     {


    8         [Test]


    9         public void SaveDate()


   10         {


   11             DataManager manager = new DataManager();


   12             manager.AddData(“Some string data”);


   13             manager.SaveData();


   14         }


   15     }


   16 }




    1 using System;


    2 using System.IO;


    3 


    4 namespace DIPSample


    5 {


    6     class DataManager


    7     {


    8         private string _data;


    9 


   10         public void AddData(string data)


   11         {


   12             _data = data;


   13         }


   14 


   15         public void SaveData()


   16         {


   17             string path = @”C:dataFile.dat”;


   18             if(!File.Exists(path))


   19                 throw new InvalidOperationException(“Data storage isn’t ready.”);


   20 


   21             //Do something to maintain this data file. . .


   22             //Add info to file, replace data in file, etc.  Use your imagination.


   23         }


   24     }


   25 }


This test seeks to verify that SaveData() does what is is supposed to do.  The problem is that if our file isn’t available the code will fail.  I’m not in a position to configure the environment so that the file is available.  I don’t want to mess with the actual file at this point either.  I’ll need to modify the code so that it’s testable by itself.  The following is the same code modified to be more flexible so that the unit test _is actually a unit test_.  The above test is actually an integration test because its running requires the file system to be on the testing stack.

I define an interface to separate my file system dependency:


    1 namespace DIPSample


    2 {


    3     public interface IDataFileStore


    4     {


    5         void SaveData(string data);


    6     }


    7 }


I make my concrete implementation that calls the file system.  This will be my class for integration and acceptance tests.


    1 using System;


    2 using System.IO;


    3 


    4 namespace DIPSample


    5 {


    6     public class FileStore : IDataFileStore


    7     {


    8         public void SaveData(string data)


    9         {


   10             string path = @”C:dataFile.dat”;


   11             if(!File.Exists(path))


   12                 throw new InvalidOperationException(“Data storage isn’t ready.”);


   13 


   14             //Do something to maintain this data file. . .


   15             //Add info to file, replace data in file, etc.  Use your imagination.


   16         }


   17     }


   18 }


Here is how my DataManager class changes.  Notice the default constructor and a special constructor specifically for testing:


    1 namespace DIPSample


    2 {


    3     class DataManager


    4     {


    5         private string _data;


    6         private IDataFileStore _fileStore;


    7 


    8         public DataManager()


    9         {


   10             _fileStore = new FileStore();


   11         }


   12 


   13         public DataManager(IDataFileStore _store)


   14         {


   15             _fileStore = _store;


   16         }


   17 


   18         public void AddData(string data)


   19         {


   20             _data = data;


   21         }


   22 


   23         public void SaveData()


   24         {


   25             _fileStore.SaveData(_data);


   26         }


   27     }


   28 }


And in my test below, I use NMock to mock the interface.  It also allows me to verify that the proper method is called with the right data on my interface:


    1 using NUnit.Framework;


    2 using NMock;


    3 


    4 namespace DIPSample


    5 {


    6     [TestFixture]


    7     public class DataManagerTester


    8     {


    9         [Test]


   10         public void SaveDate()


   11         {


   12             IMock mock = new DynamicMock(typeof(IDataFileStore));


   13             mock.Expect(“SaveData”, “Some string data”);


   14 


   15             DataManager manager = new DataManager((IDataFileStore)mock.MockInstance);


   16             manager.AddData(“Some string data”);


   17             manager.SaveData();


   18 


   19             //Verifies SaveData method in the mock is actually called with the right input.


   20             mock.Verify();


   21         }


   22     }


   23 }


This is called Dependency Injection.  You are injecting a dependency to facilitate unit testing.  This decouples your code, and it is now more flexible.  The above is very important because if you can’t do this, then it will be VERY difficult, nay, impossible to do unit testing on a system that uses: files, a database, queues, web services, remoting, {shudder} DCOM, ASP.NET.

The Monday’s show comes to Austin – level -999


Carl Franklin and the crew are recording the Monday’s show.  There is a live audience (not shown) here at Dave & Buster’s.  They’re staying in town all weekend, so they’ll have some time to relax and catch up on sleep.  We’re also going to see some Austin live music and grill some rib-eye steaks tomorrow.

Mark Miller has found several more people dumber than him, and a new character comes to the show.  And, of course, Richard has some cool new toys to talk about.
I wonder how long it will take Geoff to edit _this_ episode.

EZWeb 2.0 released – ready for your ASP.NET 2.0 host – level 100

ASP.NET 2.0 is here, and so is my version of EZWeb to go along with it.  It makes it super easy to take advantage of master pages and themes with your own website without having to code it yourself.  Use EZWeb to run a website of any size.


For my 1.x releases, I used my custom Theming and master-page-like controls, but now with the release of the .Net Framework 2.0, I’ve refactored these features to use the built-in features of ASP.NET 2.0.  You can build a standard master page as a template for your EZWeb website, and you can use Themes (.skin and .css files) to modify the look of your website.  This release comes with a few templates, but you can easily customize your site with your own master page.  Download it now and give it a shot on any ASP.NET 2.0 host.


Download EZWeb 2.0 here.



Visual Studio 2005 Pro install very trouble-free – level 100

I pulled down the VS 2005 bits from MSDN overnight, and installed today.  I had the Beta 2 bits on my machine along with VS 2003.  I uninstalled manually everything that Beta 2 put on my machine and ran the VS 2005 installer.  It terminated with a message that I missed MSXML 6.0.  I got rid of that, and reran setup.  It completed successfully in under an hour!  Beta 1 and Beta 2 all took several hours (I had them installed on my workstation as well).  Kudos to Microsoft for the improved install time.  I installed everything except Crystal Reports.  I even do a little J# dabbling every once in a while.  Java was my first OO language.


Now I can banish my Release Candidate and get to work with the real thing.  I already have a running list of workarounds for things that I did a little differently in VS 2003.  My use cases are definitely not typical MSDN demo fodder, and I often have to banish the IDE in order to take advantage of a runtime-only feature, so I’m trodding off the “happy path”. 


DiscountASP will be one of the first to offer ASP.NET 2.0 hosting.  I’ll be trying them out.

How to solve the ever-common “Parser Error Message: Access is denied: ‘mydll’.” – level 200

We’ve all been halted in ASP.NET development when we seemingly do a normal compile, and then our website won’t work.  It won’t even start up.  Here’s a rough error you may see:
————————————————————————


Server Error in ‘/MyWebApp’ Application


Configuration Error


Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: Access is denied: ‘mydll’.
Source Error:

Line 169:   <add assembly=<System.Drawing, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>/>
Line 170: <add assembly=<System.EnterpriseServices, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a>/>
Line 171: <add assembly=<*>/>
Line 172: </assemblies>
Line 173:

Source File: c:winntmicrosoft.netframeworkv1.0.3705Configmachine.config Line: 171
Version Information: Microsoft .NET Framework Version:1.0.3705.0; ASP.NET Version:1.0.3705.0
———————————————————-


Most of the time, your website worked just fine.  It has happened to me when I’ve just made an update to the web.config file.  What causes this is that the website AppDomain tries to load, and it can’t.  A change to the web.config causes a recycle of the AppDomain and a reload of the website.  When the website loads, a copy of every assembly is loaded into the Temporary ASP.NET Files directory.  If that directory is locked, or files in the directory are locked, this process can’t complete, and we’ll see this error.


The most common cause is the Windows Indexing Service.  I don’t really need this service, so I’ve disabled it.  I don’t get this error anymore.  Technically speaking, any process that may lock files in that directory may cause this error, so technically virus scanners, Google Desktop search, etc may lock those files and cause this error, but I’ve only connected this with the Windows Indexing Service.


Microsoft, in this Knowledge Base (KB) article, recommends exactly that: disabling the Indexing Service.

ASP.NET Rendered Controls vs. Composite Controls – I prefer to avoid rendered controls – level 200

Here, I’ll present a simple example of the same control using the rendered method and the composite method.  For those new to custom web controls, a rendered control is a class inherited from “Control” or “WebControl” that overrides the “Render” method in order to sned custom markup to the browser.  A composite control uses other controls in a hierarchy and leaves the rendering to each control. 


Here is a simple rendered control:



    6     public class RenderedControl : Control


    7     {


    8         protected override void Render(HtmlTextWriter writer)


    9         {


   10             writer.AddAttribute(HtmlTextWriterAttribute.Id, “myID”);


   11             writer.RenderBeginTag(HtmlTextWriterTag.Div);


   12             writer.AddAttribute(HtmlTextWriterAttribute.Id, “innerID”);


   13             writer.RenderBeginTag(HtmlTextWriterTag.Span);


   14             writer.Write(“This text is the meat of this control.”);


   15             writer.RenderEndTag();


   16             writer.RenderEndTag();


   17         }


   18     }


It’s pretty straight-forward, and the output will always be this: 



   18 <div id=”myID”>


   19     <span id=”innerID”>This text is the meat of this control.</span>


   20 </div>


Here is the same thing using the composite method:



    6     public class CompositeControl : Panel


    7     {


    8         protected override void CreateChildControls()


    9         {


   10             base.CreateChildControls ();


   11 


   12             this.ID = “myID”;


 


   13             Label lbl = new Label();


   14             lbl.ID = “innerID”;


   15             lbl.Text = “This text is the meat of this control.”;


 


   16             this.Controls.Add(lbl);


   17         }


   18     }


With the composite method, the developer doesn’t have to worry about the low level markup being rendered, and he can depend on the richer object-oriented contract of each child control.  With this method, the developer overrides the CreateChildControls() method and adds child controls.  All these child controls will render themselves.  The exact same markup renders.


In my opinion, using the composite control method optimizes development time, and that is the most expensive more often than not.  I don’t give weight to the performance argument because the difference in performance is on the millisecond scale.  The moment you call out-of-process to a database or the file system, you accept a performance hit of much more magnitude; therefore, the performance difference of these two methods is negligible.  The composite control method is more maintainable, and maintenance of an application always costs more.