如何使用 Resharper 9 设置文件布局以将 [ClassInitialize] 和 [ClassCleanup] 放在文件顶部?

How do you set the File Layout to put [ClassInitialize] and [ClassCleanup] at the top of the file using Resharper 9?

如何使用 Resharper 9 设置文件布局以将 MsTest [ClassInitialize][ClassCleanup] 方法置于文件顶部?

使用 R# 的默认设置,这些方法只是与其他测试方法一起进行 alpha 排序

我很感激我可以修改 "All other members" 从按名称排序,先按静态排序然后按名称排序,但这似乎是一个快速的 hack

您可以编辑 ReSharper 用于通过代码清理对文件内容重新排序的文件布局规则,方法是转到 ReSharper → 选项 → 代码编辑 → C# → 文件布局。

the web help, but the idea is to create a pattern very similar to the default "NUnit Test Fixtures" pattern, but for MSTest. In fact, this is a nice idea for a default pattern, so I've added a feature suggestion you can track or vote: RSRP-446275

中提供了完整的详细信息

本质上,您想执行默认的 NUnit 测试装置规则 does.Create 一个新的 "type pattern" 并将其添加到 "NUnit Test Fixtures" 和 "Default Pattern" 之间。双击以编辑模式,并通过单击右上角的齿轮切换到约束视图。在这里你可以说它必须是 Kind "Class" And "Has attribute" Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute.

切换回组合(规则)视图,并从工具箱中添加一个 "Entry"。为其命名,例如 "Setup/Teardown Methods",然后双击它。这应该设置为与 NUnit 相同 - And (Kind=Method, Or (Has attribute=Microsoft...ClassInitializeAttribute, Has attribute=Microsoft...ClassCleanup)).

NUnit 模式定义了另外一对条目 - "All other members" 的空条目和 "Test methods" 的空条目,它们是 kind=method 并且具有 attribute=Test。可以对 mutest 的 TestMethod 属性做类似的事情。