我见过很多人都在谈论IQueryable,我还没有完全了解所有的嗡嗡声.我总是使用泛型List,并发现它们非常丰富,你可以"查询"它们并使用它们,甚至对它们运行LINQ查询.
我想知道是否有充分的理由开始在我的项目中考虑不同的默认集合.
我正在尝试从满足一系列标准的一组用户中保护我的MVC路由.由于MVC似乎使用了很多属性而Steven Sanderson在他的专业MVC书中使用了一个安全可扩展性,因此我开始沿着这条路线前进,但我想根据我应用它的动作来定义规则.
有些行为仅适用于员工,有些则不适用.
有些行为仅适用于company1,有些则不适用.
所以我在想这种用法......
[DisableAccess(BlockUsersWhere = u => u.Company != "Acme")]
public ActionResult AcmeOnlyAction()
{
...
}
[DisableAccess(BlockUsersWhere = u => u.IsEmployee == false)]
public ActionResult EmployeeOnlyAction()
{
...
}
Run Code Online (Sandbox Code Playgroud)
看起来很干净,我真的很容易实现,但我得到以下编译器错误:
'BlockUsersWhere'不是有效的命名属性参数,因为它不是有效的属性参数类型
显然你不能使用Func作为属性参数.有什么其他建议来解决这个问题或其他提供我们在MVC项目中喜欢的简单用法的建议吗?
我是测试和模拟的新手,我正在尝试编写一个测试,以确保我的验证逻辑正确设置ModelState错误.
我看到的是controller.ControllerContext.HttpContext.Request在我第一次检查时设置但是每次在此之后Request都为null.
这导致MVC源中*ValueProviderDictionary*类的PopulateDictionary方法中出现空引用异常,因为在该方法中多次访问请求对象而不确保请求不为null.
我正在研究如何克服我到目前为止遇到的一些问题时找到的几种技术和助手,所以在这一点上我有点不确定我可能在哪里引入了这个问题.
我在这里错误地使用模拟对象吗?
失败的测试
//Test
public void Test_FooController_OnActionExecuting_ShouldMapStateToAFooModel()
{
//Arrange
DataAccessFactoryMocks.MockAllDaos();
var controller = new FooController();
var testFormCollection = new NameValueCollection();
testFormCollection.Add("foo.CustomerID", "3");
testFormCollection.Add("_fooForm", SerializationUtils.Serialize(new FooModel()));
var mockHttpContext = new MockHttpContext(controller, "POST", testFormCollection, null);
//Accessor used to run the protected OnActionExecuting method in my controller
var accessor = new FooControllerAccessor(controller);
//Request is set, assertion passes
Assert.IsNotNull(controller.ControllerContext.HttpContext.Request.Form);
//Request is null when accessing the property a second time, assertion fails
Assert.IsNotNull(controller.ControllerContext.HttpContext.Request.QueryString);
//Act
accessor.OnActionExecuting(new ActionExecutingContext(controller.ControllerContext, …Run Code Online (Sandbox Code Playgroud) asp.net-mvc ×2
architecture ×1
asp.net ×1
attributes ×1
c# ×1
collections ×1
linq ×1
rhino-mocks ×1
unit-testing ×1