Hi there... after a long time, I'm back.

Let's talk a little about unit testing and commerce server... I've been helping one of our parters with a CS2007 website development and they were facing problems with unit testing and commerce server contexts created by the httpmodules.

As you probably know, test driven development and unit testing require a lot from the architecture. In order to do effective unit tests, the system need to be divided in units and those units need to be tested under a set of conditions that, ideally, allow near total code coverage.

The problem with unit testing and Commerce Server 2007 is that the Microsoft’s e-commerce framework is heavily reliant on HTTP modules to initialize some special contexts. For example, the CommerceContext (which is created by one web.config specified HTTP module) provides access to various subsystems needed for catalog, profiles and orders operations.

This tightly coupled HTTP dependency makes hard to deal with conventional out-of-process unit tests and Commerce Server 2007 applications running inside IIS and using http modules to create contexts.

The tricks is create a unit test configuration file and attaching the unit test manager process to the IIS, this procedure makes possible the access to all contexts created by Commerce Server 2007 HTTP modules.

This configuration can be done following the steps below:

1. Open Visual Studio .Net 2005. Right-click on the Solution Items folder and select Add, New Item…


2. On the “Add New Item” page, select “Test Run Configuration” and click Add.


3. Select Hosts, and change the “Host Type” to ASP.Net. In the “URL to test” text box, type the URL of your website and select “Run tests in IIS”. Click Apply and Close.


4. Ensure that the configuration that you just done is being used as the Active Test Run Configuration.


5. Now run the Unit Test. All unit tests which have dependency to CommerceContext will run.

As an additional note is the recommendation to run at least Visual Studio 2005 Service Pack 1. That is because StarterSite comes with some Unit Tests but the configuration file available together with the tests doesn’t work without the SP1 installed.

See you soon!


This posting is provided "AS IS" with no warranties, and confers no rights.