I’m really liking the unit test support in the Castle Monorail project. Here’s an example to create a simple test for testing filters.

public class AdminAuthorizationFilterTest : BaseControllerTest
private Controller _controller;

public void Setup()
_controller = new TestController();

public void Perform_No_User_Expect_False()
AdminAuthorizationFilter filter = new AdminAuthorizationFilter();
bool perform = filter.Perform(ExecuteEnum.BeforeAction, Context, _controller);
Assert.That(perform, Is.False);
Assert.That(Response.WasRedirected, Is.True);

internal class TestController : Controller {}


Setup is the same as testing a controller, but I needed to create an basic test controller. I attempted to use Rhino Mocks to partial mock the controller, but that disconnected the BaseControllerTest resulting in things like checking the Response object not working. Creating the class is one less line of code anyway.

More on test support here.
And Here.