internalsvisibleto

Using “friend”-declarations for unit testing. Bad idea?

不打扰是莪最后的温柔 提交于 2019-11-29 06:16:47
问题 [ Of course, the question is not restricted to a specific "friend" implementation, feel free though to point out implementation specifics if relevant ] Reading through the unanswered questions, I stumbled upon the InternalsVisibleTo attribute: Specifies that types that are ordinarily visible only within the current assembly are visible to another assembly. The C# Programming Guide on MSDN has a section Friend Assemblies describing how to use the attribute to allow the use of internal methods

When should [assembly: InternalsVisibleTo()] be used?

不问归期 提交于 2019-11-28 10:55:53
I understand that the InternalVisibleTo attribute is used to expose types and methods with the internal access modifier to a specified assembly. I have only ever used this for exposing internal methods to a separate assembly containing a suite of unit tests. I am struggling to think of another scenario when this should be used. Was this attribute introduced specifically to aid unit testing or was there another reason? A scenario can be that you have separation of logic between assemblies (like internal data objects and the logic layer). You don't want to expose the classes to your users, but

When should [assembly: InternalsVisibleTo()] be used?

帅比萌擦擦* 提交于 2019-11-27 05:57:01
问题 I understand that the InternalVisibleTo attribute is used to expose types and methods with the internal access modifier to a specified assembly. I have only ever used this for exposing internal methods to a separate assembly containing a suite of unit tests. I am struggling to think of another scenario when this should be used. Was this attribute introduced specifically to aid unit testing or was there another reason? 回答1: A scenario can be that you have separation of logic between assemblies

InternalsVisibleTo attribute isn't working

可紊 提交于 2019-11-26 19:44:41
I am trying to use the InternalsVisibleTo assembly attribute to make my internal classes in a .NET class library visible to my unit test project. For some reason, I keep getting an error message that says: 'MyClassName' is inaccessible due to its protection level Both assemblies are signed and I have the correct key listed in the attribute declaration. Any ideas? Joe Are you absolutely sure you have the correct public key specified in the attribute? Note that you need to specify the full public key, not just the public key token. It looks something like: [assembly: InternalsVisibleTo(

InternalsVisibleTo attribute isn't working

走远了吗. 提交于 2019-11-26 07:25:55
问题 I am trying to use the InternalsVisibleTo assembly attribute to make my internal classes in a .NET class library visible to my unit test project. For some reason, I keep getting an error message that says: \'MyClassName\' is inaccessible due to its protection level Both assemblies are signed and I have the correct key listed in the attribute declaration. Any ideas? 回答1: Are you absolutely sure you have the correct public key specified in the attribute? Note that you need to specify the full