Skip to main content


Showing posts from January, 2013

JavaScript Inheritance In 6 Basic Steps

// Define Base Class
function BaseClass() { }

// Define a Function
BaseClass.prototype.SomeFunction = function () { alert("Base Class SomeFunction"); }

// Define Child Class
function ChildClass() {; // Call the Parent Constructor

// Specify that the ChildClass Inherits from the base class
ChildClass.prototype = new BaseClass();

// Ensure that the Child Class constructor points to itself & not the Base Class
ChildClass.prototype.constructor = ChildClass;

// Override the "SomeFunction" from the Base Class
ChildClass.prototype.SomeFunction = function () { alert("Child Class SomeFunction"); }
Now we can create an instance of the Child class like so ..
// Create an instance of the ChildClass
var object = new ChildClass();
And now, a call to the "SomeFunction" returns the overriden implementation.
// Call the "SomeFunction" method.
object.SomeFunction(); // This returns an alert containing: "Child Class SomeFunction&…

Unit Testing HttpContext.Current.Session in MVC3 .NET

We recently changed some functionality where during the "CREATE" process, we go through a wizard to save application data. This data is saved only to the session in the final step when the user clicks the final submit.

This was easy enough to implement but when I started writing unit tests for my static methods that Add, Update, Delete or Modify the contents of our application data in the session, I got the following error:
System.NullReferenceException: Object reference not set to an instance of an object.

Turns out I had forgotten to setup the HttpContext.
The following "TestInitialise" method fixed my problem :)

public void TestSetup()
// We need to setup the Current HTTP Context as follows:

// Step 1: Setup the HTTP Request
var httpRequest = new HttpRequest("", "http://localhost/", "");

// Step 2: Setup the HTTP Response
var httpResponce = new HttpResponse(new StringWriter());

// Step 3: Se…