FluentAssertions を使用して、NonActionAttribute で装飾されていないすべてのメソッドをテストしたいと考えています。(これにより、T4MVC によってプレースホルダーとして自動的に生成される一連のアクション メソッドが削減されます。)
私の特定の問題は、MethodInfoSelector メソッドを連鎖させることです。私はこのようなものを書きたいと思います:
public MethodInfoSelector AllActionMethods() {
return TestControllerType.Methods()
.ThatReturn<ActionResult>()
.ThatAreNotDecoratedWith<NonActionAttribute>();
}
public static MethodInfoSelector ThatAreNotDecoratedWith<TAttribute>(this IEnumerable<MethodInfo> selectedMethods) {
return (MethodInfoSelector)(selectedMethods.Where(method => !method.GetCustomAttributes(false).OfType<TAttribute>().Any())); // this cast fails
}
キャストが失敗するか、結果を IEnumberable に変換すると、追加の MethodInfoSelector メソッドをチェーンできません。
MethodInfoSelector を生成する方法、または特定の属性を持たないメソッドをリストするという根本的な問題に対する別のアプローチについて、助けていただければ幸いです。