I am having trouble finding faked Thread.Sleep in mscorlib.fakes library. I am following direction at http://www.codewrecks.com/blog/index.php/2012/04/27/using-shims-in-visual-studio-11-to-test-untestable-code/

http://msdn.microsoft.com/en-us/library/d00bd51t(v=vs.100).aspx shows Thread.Sleep is in mscorlib so I added its fake but System.Threading.Fakes namespace doesn't contain ShimThread nor StubThread. Thread is a sealed class but VS fake framework should be able to fake static method in sealed class.

有帮助吗?

解决方案 2

This is because the Shim framework cannot fake all .Net BCL classes in mscrolib and System, see: MSDN.

Unfortunately I couldn't find a list of types that aren't supported. But it seems, primarily types that are not pure CLR classes or need OS functionality (Thread, FileSystemWatcher, ...) are not supported at this time.

其他提示

This is very much possible. By default Fakes framework doesn't generate shims for most types (including types in System.Threading namespace) of mscorlib because Fakes framework itself makes use of mscorlib. So only a few of the types are shimmed, However, you can configure this behavior by changing the mscorlib.fakes file added in your project.

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
    <Assembly Name="mscorlib" Version="4.0.0.0"/>
    <ShimGeneration>
        <Add Namespace="System.Threading!"/>
    </ShimGeneration>
</Fakes>

Now build the test project and you can see shims for types in the System.Threading namespace, including ShimThread.SleepInt32.

Read more about the .fakes xml file on this page

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top