我有一个测试类,里面有一些 IDisposable 项目。这是我第一次尝试做这样的事情:
private MemoryStream toolExampleMs;
private MemoryStream issueClassExampleMs;
private MemoryStream issueTypeExampleMs;
private MemoryStream uniqueIdExampleMs;
private Check exampleCheck;
public SuppressionDatabaseTest()
{
this.toolExampleMs = new MemoryStream(Encoding.UTF8.GetBytes(toolExample));
this.issueClassExampleMs = new MemoryStream(Encoding.UTF8.GetBytes(toolExample));
this.issueTypeExampleMs = new MemoryStream(Encoding.UTF8.GetBytes(issueTypeExample));
this.uniqueIdExampleMs = new MemoryStream(Encoding.UTF8.GetBytes(uniqueIdExample));
this.exampleCheck = new Check();
this.exampleCheck.IssueClass = "FooBarClass";
this.exampleCheck.IssueType = "FooBarType";
this.exampleCheck.Key = "FooBarExactWith?Unicode";
}
[ClassCleanup]
public void CleanupAll() // Error: CleanupAll has the wrong signature
{
toolExampleMs.Dispose();
issueClassExampleMs.Dispose();
issueTypeExampleMs.Dispose();
uniqueIdExampleMs.Dispose();
}
[TestCleanup]
public void Cleanup()
{
this.toolExampleMs.Seek(0, SeekOrigin.Begin);
this.issueClassExampleMs.Seek(0, SeekOrigin.Begin);
this.issueTypeExampleMs.Seek(0, SeekOrigin.Begin);
this.uniqueIdExampleMs.Seek(0, SeekOrigin.Begin);
}
不幸的是,ClassCleanup 方法必须static
在 MSTest 中,这意味着没有地方可以挂钩要处置的调用。这是否意味着我需要在每次单独测试之前和之后重建这些流?