0

I have simple asp.net mvc application which uses custom membership and role provider. After setting all in place I use [Authorize]inside controller actions to allow/deny access to certain user groups. Now I want to move further and try to unit test every controller which uses [Authorize] attribute.

I was thinking to use Unity Ioc and Moq. Any good suggestion from where to start, basic steps with some code examples or tutorials to share?

Thanks

user2783193
  • 992
  • 1
  • 12
  • 37
  • Possible duplicate : http://stackoverflow.com/questions/1877225/how-do-i-unit-test-a-controller-method-that-has-the-authorize-attribute-applie – Jason Evans Oct 14 '13 at 08:15

2 Answers2

0

I would suggest the below approach. Basically you can write a Unit test to ensure your action is decorated with the [Authorize] attribute.

See my blog post for more information. This approach should work nicely with your Unit Test.

http://blog.rajsoftware.com/post/2012/12/04/Simple-test-helper-MVC-Action-has-decorated-with-a-certain-attribute.aspx

Spock
  • 7,009
  • 1
  • 41
  • 60
0

I answered this in another thread - the blog post link above is "ok", but I wanted to test the actual attribute on the actual controller I was testing:

Answer: How to test custom MVC attribute

Community
  • 1
  • 1
ProVega
  • 5,864
  • 2
  • 36
  • 34