Unit testing code which uses Umbraco v4 API

Posted by Jason Evans on Stack Overflow See other posts from Stack Overflow or by Jason Evans
Published on 2012-06-15T15:56:08Z Indexed on 2012/06/28 21:16 UTC
Read the original article Hit count: 249

Filed under:
|

I'm trying to write a suite of integration tests, where I have custom code which uses the Umbraco API. The Umbraco database lives in a SQL Server CE 4.0 database (*.sdf file) and I've managed to get that association working fine.

My problem looks to be dependancies in the Umbraco code. For example, I would like to create a new user for my tests, so I try:

var user = User.MakeNew("developer", "developer", "mypassword", "[email protected]", adminUserType);

Now as you can see, I have pass a user type which is an object. I've tried two separate ways to create the user type, both of which fail due to a null object exception:

var adminUserType = UserType.GetUserType(1);
var adminUserType2 = new UserType(1);

The problem is that in each case the UserType code calls it's Cache method which uses the HttpRuntime class, which naturally is null.

My question is this: Can someone suggest a way of writing integration tests against Umbraco code? Will I have to end up using a mocking framework such as TypeMock or JustMock?

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about umbraco