1

I have Windows Form App(assembly named "WindowsFormsApplication1") and I have Unit Test project(assembly named "UnitTestProject2").

I added InternalsVisibleTo attribute into "WindowsFormsApplication1\AssemblyInfo.cs" like

[assembly: InternalsVisibleTo("UnitTestProject2")] 

To access internal class from "WindowsFormsApplication1" into unit test app "UnitTestProject2" using Microsoft Fakes(VS 2012 Ultimate).

I can access internal class directly using namespace from unit test project. But I can not access Fakes - Shims and Stubs for that internal class. I tried different combinations for InternalsVisibleTo attribute:

[assembly: InternalsVisibleTo("UnitTestProject2.Fakes")], 
[assembly: InternalsVisibleTo("UnitTestProject2.Tests")]

etc. but none worked.

Anyone have idea what went wrong and how to resolve it?

FYI: Reference - Ref1, Ref2.

GMCS Pune
  • 83
  • 1
  • 14

1 Answers1

5

Suppose the assembly you are testing is 'WindowsFormsApplication1', then you have to add 2 InternalsVisibleTo attributes:

[assembly: InternalsVisibleTo("WindowsFormsApplication1.Fakes")]
[assembly: InternalsVisibleTo("UnitTestProject2")]

MSDN:

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.