授权属性的模拟presence [英] Mock presence of Authorize attribute

查看:212
本文介绍了授权属性的模拟presence的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道你怎么能嘲笑一个控制器,饰有MVC3的[授权]属性?我使用的是自定义的成员提供。我想测试控制器被装饰的属性,您被授权,当你不是会发生什么。我使用的起订量。对此有何好的建议?!

I was wondering how you could mock that a controller is decorated with the [Authorize] attribute in MVC3? I am using a custom membership provider. I would like to test that a controller been decorated with the attribute and you are authorized and what happens when you are not. I'm using Moq. Any good suggestions on this?!

更新:
目前,我得到一个的NullReferenceException说:对象引用不设置到对象的实例。这是相同的错误$ P $在这个岗位<一pviously提到href=\"http://stackoverflow.com/questions/7159791/nullreferenceexception-while-using-authorize-attribute\">NullReferenceException同时采用授权属性

这是有关授权属性。我在IIS下运行,并且不使用卡西尼。有谁知道这是某种联系的一个应用池和用户权限。我有在授权测试属性不会工作,直到这个是固定的。

This is related to the Authorize attribute. I'm running under iis and not using cassini. Does anyone know if this is somehow related to applicaton pool and user rights. The tests that I have for the authorize attribute wont work until this is fixed.

也许有测试授权属性的一些其他的方式?非常感谢在前进。

Maybe there is some other way of testing the Authorize attribute? Big thanks in advance.

UPDATE2
所以经过从同事的一些广泛的研究和调试的帮助下,我提到与[授权]属性解决问题。看来好像这条线在web.config中失踪:

UPDATE2 So after some extensive research and debugging help from a colleague I mentioned to fix the problem with the [Authorize] attribute. It appears as though this line in the web.config was missing:

<modules runAllManagedModulesForAllRequests="true">

奇怪的是这并没有为另一名同事被共享行李箱内或测试环境引起的问题。它只引起的问题,我在本地。这可能已涉及到在GAC东西。总之一切工作了。

Strangely enough this did not cause problem for another colleague that was sharing the trunk or in beta environment. It only caused problems for me locally. This might have been related to something in the GAC. Anyhow all works now.

感谢。

推荐答案

我写了一篇博客文章究竟是一两个月前:

I wrote a blog post about exactly that a couple of months ago:

http://thomasardal.com/unit-testing-attribute-decorations/

这篇关于授权属性的模拟presence的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆