[英]unit test actions decorated with Authorize attribute
I have simple asp.net mvc application which uses custom membership
and role provider
. 我有一个简单的asp.net mvc应用程序,它使用自定义
membership
和role provider
。 After setting all in place I use [Authorize]
inside controller actions to allow/deny access to certain user groups. 将所有位置设置到位后,我在控制器操作中使用
[Authorize]
来允许/拒绝对某些用户组的访问。 Now I want to move further and try to unit test every controller which uses [Authorize]
attribute. 现在,我想更进一步,尝试对使用
[Authorize]
属性的每个控制器进行单元测试。
I was thinking to use Unity Ioc and Moq. 我当时正在考虑使用Unity Ioc和Moq。 Any good suggestion from where to start, basic steps with some code examples or tutorials to share?
从何处开始有什么好的建议,一些代码示例或教程的基本步骤可共享?
Thanks 谢谢
I would suggest the below approach. 我建议采用以下方法。 Basically you can write a Unit test to ensure your action is decorated with the [Authorize] attribute.
基本上,您可以编写单元测试,以确保您的操作使用[Authorize]属性进行修饰。
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 http://blog.rajsoftware.com/post/2012/12/04/Simple-test-helper-MVC-Action-has-decorated-with-a-certain-attribute.aspx
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: 我在另一个线程中回答了这个问题-上面的博客文章链接为“ ok”,但我想在我正在测试的实际控制器上测试实际属性:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.