none
Issue making class under test internals visible to the Fakes

    Question

  • I created a small dll in visual studio 2013 ultimate, with one class, the class is marked as internal and the methods are public. I added the internalsVisibleTo attribute to the project under test's AssemblyInfo.cs file (the assembly is called "Calculator"):

    [assembly: InternalsVisibleTo("Calculator.Fakes")]
    [assembly: InternalsVisibleTo("CalculatorUnitTests")]

    In the unit test project, a reference to the "Calculator" project was added, then a fakes of that reference was added.

    In the unit test itself, the internals of the class are visible, but the fakes assembly isn't showing any fakes for that class. If I change the class in Calculator to public it does show in the fakes.  

    I don't see the mechanism for making the internals of the class under test visible to the fakes so the class can be faked. Any suggestions?

    I looked at the info here: https://msdn.microsoft.com/en-us/library/hh708916.aspx#bkmk_internal_types

    but it doesn't seem to be working as advertised...

    Thanks


    • Edited by meansala Friday, May 27, 2016 1:08 PM
    Friday, May 27, 2016 1:05 PM

All replies

  • Hi meansala,

    Whether your assembly is signed with a strong name?

    Like this thread here:

    http://stackoverflow.com/questions/18845634/internalsvisibleto-does-not-work

    Maybe you could check that whether the assembly name doesn't match the project name so that you use the wrong name.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 30, 2016 11:14 AM
    Moderator
  • The assemblies are not signed, I triple checked the name of the assemblies even tried a suggestion of adding the .dll to the fakes reference, still no luck. 

    [assembly: InternalsVisibleTo("Calculator.Fakes.dll")]

    • Edited by meansala Wednesday, July 13, 2016 12:15 PM
    Wednesday, July 13, 2016 12:14 PM
  • Found the issue!  (well, my coworker did ).  Looks like for classes marked as internal, using the "internalsVisibleTo" attribute works as expected in the unit test code, the issue I ended up getting stuck on was that if you try to look at the newly generated fakes assembly with the object browser, the internal methods are not shown.

    In the unit tests though you can access the ShimMethods with no problem As I was troubleshooting I never tried just calling the shim, I was checking what showed in the object browser.  So looks like just a bug in the object browser.

    Wednesday, July 13, 2016 5:15 PM
  • Thanks for sharing your solution here, it would be helpful for other members who met the same issue as yours.

    Have a nice day,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, July 14, 2016 5:22 AM
    Moderator