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.
[SetUpFixture] public class WebServer { private Server _webServer; private string _serverUrl; [TearDown] public void Teardown() { _webServer.ShutDown(); _webServer.Dispose(); } [SetUp] public void Setup() { var appBasePath = new DirectoryInfo( AppDomain.CurrentDomain.BaseDirectory); var serverPhysicalPath = appBasePath.Parent.Parent.Parent.FullName + "\\BlogEngine.NET"; const int webServerPort = 8090; const string virtualDirectory = "/"; const string pathToAppToTest = "/"; try { _webServer = new Server(webServerPort, virtualDirectory, serverPhysicalPath); _serverUrl = String.Format("http://localhost:{0}/{1}", webServerPort, pathToAppToTest); _webServer.Start(); 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}", ex.Message)); throw; } } }
My work is available on a fork on Codeplex