我正在使用 MVC 4 (beta),并且在尝试测试我编写的 auth 属性时遇到了一些问题。
为了更深入地了解这一点,我正在尝试将调试用于 .net 框架源调试选项,以查看到底出了什么问题。我已按照此处的设置说明进行操作:http ://weblogs.asp.net/gunnarpeipman/archive/2010/07/04/stepping-into-asp-net-mvc-source-code-with-visual-studio-debugger .aspx
完成所有这些之后,当我调试我的测试以查看发生了什么时,当我进入调用 .net fw 的代码行时,测试只是终止并给了我正在尝试的异常调试。为了完整起见,这是我的代码:
var controller = new MyController();
controller.SetFakeAuthenticatedControllerContext("foo"); // Set up a fake http context for the user
var actionDescriptor = new Mock<ActionDescriptor>();
actionDescriptor.SetupGet(x => x.ActionName).Returns("AddedForTest");
var context = new AuthorizationContext(controller.ControllerContext, actionDescriptor.Object);
var auth = new SamCommandAuthenticationAttribute();
auth.OnAuthorization(context); // On this line the test will just terminate
Assert.Pass(); // This line would never be called.
有谁知道为什么我无法调试到 .net 源代码?