我在 TDD Book for Test Authorize Controller 中看到了实践,但我不明白这意味着什么是代码
Assert.IsTrue(typeof (TodoController)
.GetCustomAttributes(true).ToList()
.Any(o=>o.GetType()==typeof(AuthorizeAttribute))
);
我在 TDD Book for Test Authorize Controller 中看到了实践,但我不明白这意味着什么是代码
Assert.IsTrue(typeof (TodoController)
.GetCustomAttributes(true).ToList()
.Any(o=>o.GetType()==typeof(AuthorizeAttribute))
);
他们正在检查是否已将[Authorize]属性添加到TodoController. 请注意,他们实际上并没有测试授权机制是否有效,只是AuthorizeAttribute装饰存在。
它检查是否TodoController有一个AuthorizeAttribute,即装饰有[Authorize]
[Authorize] // <-- if this is present the test will pass, if not it will fail.
public class TodoController {
// ...
}