Testing ActionFilterAttributes with MSpec
        Posted  
        
            by Tomas Lycken
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Tomas Lycken
        
        
        
        Published on 2010-05-20T08:02:07Z
        Indexed on 
            2010/05/22
            9:10 UTC
        
        
        Read the original article
        Hit count: 337
        
I'm currently trying to grasp MSpec, mainly to learn new ways of (T/B)DD to be able to make an educated decision on which technology to use. Previously, I've mostly (read: only) used the built-in MSTest framework with Moq, so BDD is quite new for me.
I'm writing an ASP.NET MVC app, and I want to implement PRG. Last time I did this, I used action filters to export and import ModelState via TempData, so that I could return a RedirectResult and the validation errors would still be there when the user got the view. I tested that scenario by verifying two things:
a) That the ExportModelStateAttribute I had written was applied (among tests for my controller)
b) That the attribute worked (among tests for action filter attributes)
However, in BDD I've understood I should be even more concerned with behavior, and even less with implementation. This means I should probably just verify that the model state is in tempdata when the action has finished executing - not necessarily that it's done via an attribute.
To further complicate things, attributes are not run when calling the action directly in the test, so I can't just call the action and see if the job's been done.
How should I spec/test this in MSpec?
© Stack Overflow or respective owner