为什么这段代码在操作符中抛出ShimNotSupportedException?
ShimStreamReader.AllInstances.EndOfStreamGet = ((s)=>calls < 1);
[TestMethod]
public void GetAllLinesFromFile__()
{
int calls = 0;
using (ShimsContext.Create())
{
ShimStreamReader.AllInstances.EndOfStreamGet = ((s)=>calls < 1);
ShimStreamReader.AllInstances.ReadLine = (s) =>
{
calls++;
return ";;;;;;;;;;";
};
var streamFake = new ShimStreamReader();
var obj = new MyFile(streamFake, ';');
Assert.IsTrue(obj.GetAllLinesFromFile().Count() == 1);
}
}发布于 2012-09-13 19:28:12
会不会是你在从Resharper或其他测试者那里运行测试?
我写了一些与此相关的博客文章,这可能会有所帮助:
http://blog.degree.no/2012/09/visual-studio-2012-fakes-shimnotsupportedexception-when-debugging-tests/
http://blog.degree.no/2012/09/unit-testing-visual-studio-2012-fakes-in-team-city/
发布于 2012-06-17 17:00:22
我运行了你的代码,并且在VS2012RC中运行良好。当我在VS11Beta中打开一个在VS2010中创建的解决方案时,我确实遇到了类似的问题。我想出的唯一解决办法是在VS11Beta中创建一个新的解决方案。
发布于 2013-03-04 21:52:07
可能的原因之一是缺少本应与xxx.fakes.dll一起生成的fakesconfig文件。
我使用一个中心项目来生成假程序集,并使用其他依赖于中心项目的项目来使用生成的假程序集。
让我们将这个伪程序集称为消费项目FOO。
我确实遇到了ShimNotSupportedException。经过一些调查(几天!),我发现fakesconfig文件并没有和伪造的程序集一起复制到FOO.dll所在的文件夹中。在那里复制fakesconfig文件之后,我的测试通过了。
希望这能有所帮助。
https://stackoverflow.com/questions/11008100
复制相似问题