How to mock/isolate internal classes in VS 2012 with Fakes Framework shims?

巧了我就是萌 提交于 2019-12-04 02:45:33
Oleg Sych

The following page describes how to make internal types visible to the generated fakes assembly. http://msdn.microsoft.com/en-us/library/hh708916.aspx#bkmk_internal_types

Which says:

The Fakes code generator will generate shim types and stub types for types that are visible to the generated Fakes assembly. To make internal types of a shimmed assembly visible to Fakes and your test assembly, add InternalsVisibleToAttribute attributes to the shimmed assembly code that gives visibility to the generated Fakes assembly and to the test assembly.

[assembly: InternalsVisibleTo("FileSystem.Fakes")]
[assembly: InternalsVisibleTo("FileSystem.Tests")]

You also need an InternalsVisibleToAttribute to allow your test assembly access the internal types from the target assembly. In other words, you need:

[assembly: InternalsVisibleTo("TargetAssembly.Fakes")]
[assembly: InternalsVisibleTo("TestAssembly")]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!