Unit Testing Castle Monorail Filters
Dusty Candland |
|
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.
[TestFixture]
public class AdminAuthorizationFilterTest : BaseControllerTest
{
private Controller _controller;
[SetUp]
public void Setup()
{
_controller = new TestController();
PrepareController(_controller);
}
[Test]
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.
Webmentions
These are webmentions via the IndieWeb and webmention.io. Mention this post from your site: