Creating a self hosted ASP.NET Web Application to test BlogEngine.NET

9 April 2013

You can create a SelfHost of your ASP.NET web application by using Salient.CassiniDev.

My blog is currently (while writing this post) based on BlogEngine.NET and I decided I wanted to have a look at the source code. There are WatiN tests using InternetExplorer and these require you having a local web server (like IIS) running.
I wanted to see how easy it would be to create a SelfHost ASP.NET Web Application that would be accessible using the Selenium C# Web Driver.

Behaviour Driver Development (BDD)

I decided the use SpecFlow for a Business Readable DSL mapping to allow me to execute a scenarios like:

Feature: Login
    In order to use BlogEngine.NET
    As a user
    I want to be able to login

Scenario: Can visit login page
    Given I visit the home page
        When I click the 'Log in' hyperlink
        Then I should be at url ending with Account/login.aspx

Self Host

The starting and stopping of this webserver can be controlled by using a TestFixture in NUnit 2.6.

public class WebServer
    private Server _webServer;
    private string _serverUrl;

    public void Teardown()

    public void Setup()
        var appBasePath = new DirectoryInfo(

        var serverPhysicalPath = appBasePath.Parent.Parent.Parent.FullName + "\\BlogEngine.NET";
        const int webServerPort = 8090;
        const string virtualDirectory = "/";
        const string pathToAppToTest = "/";

            _webServer = new Server(webServerPort, virtualDirectory,
            _serverUrl = String.Format("http://localhost:{0}/{1}",
                    webServerPort, pathToAppToTest);


            Debug.WriteLine(String.Format("Started Port:{0} VD:{1} PD{2}",
                    webServerPort, virtualDirectory, serverPhysicalPath));
        catch (Exception ex)
            Debug.WriteLine(string.Format("Error starting web service {0}",

My work is available on a fork on Codeplex