internalsvisibleto

UnityContainer and internal constructor

旧城冷巷雨未停 提交于 2019-12-10 02:19:08
问题 I have a class with internal constructor and want to Resolve it from Unity (2.0). public class MyClass { internal MyClass(IService service) { } } then I'm doing _container.Resolve<MyClass>(); when I do so I have an exception Exception is: InvalidOperationException - The type MyClass cannot be constructed. IService is registered and the only problem is that constructor is internal. I really want this class to be public, but I want it to be creatable only via a factory (in which I'm actually

InternalsVisibleTo does not work

六眼飞鱼酱① 提交于 2019-12-08 23:00:19
问题 I insert the line: [assembly: InternalsVisibleTo("MyTests")] inside my project under test( Properties/AssemblyInfo.cs ) where MyTests is the name of the Unit Test project. But for some reason I still cannot access the internal methods from the unit test project. Any ideas about what I am doing wrong ? 回答1: If your assembly is signed with a strong name look at this answer. Otherwise check that the name of your test assembly really is "MyTests.dll" (it doesn't have to match the project name,

Non-code-generated forwarding shim for testing private methods

烂漫一生 提交于 2019-12-06 11:50:20
问题 In general, I design classes in such a manner as to not require access to privates for testing purposes. An InternalsVisibleTo can also assist. However, I'm currently dealing with a codebase that has a few area which have become reliant on the [private accessors mechanism in VSTS](http://msdn.microsoft.com/en-us/library/ms184807(VS.80).aspx) (i.e., using VSCodeGenAccessors to generate *_Accessor classes which have forwarding that use reflection to invoke private members (and optionally

UnityContainer and internal constructor

喜欢而已 提交于 2019-12-05 01:29:10
I have a class with internal constructor and want to Resolve it from Unity (2.0). public class MyClass { internal MyClass(IService service) { } } then I'm doing _container.Resolve<MyClass>(); when I do so I have an exception Exception is: InvalidOperationException - The type MyClass cannot be constructed. IService is registered and the only problem is that constructor is internal. I really want this class to be public, but I want it to be creatable only via a factory (in which I'm actually calling container.Resolve<MyClass>() ). Is there a way to make Unity see that internal constructor? Like

how can i access internals in asp.net 5

偶尔善良 提交于 2019-12-05 01:03:46
Before asp.net 5 I would add "internalsVisibleTo(some.namespace.name)" to AssemblyInfo.cs - But I no longer have assemblyInfo.cs in my WebApi project. How do I expose internals in a WebAPI project to my unitTest project? You can add your own AssemblyInfo.cs file. Just add a class file, name it AssemblyInfo.cs (or any name for that matter), and replace all of its code with the following line: [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("some.assembly.name")] You can see an example of the above answer in action in the asp open sourced MVC project available on github: https:/

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

巧了我就是萌 提交于 2019-12-04 02:45:33
So, the issue is that I have a bunch of internal classes in my assembly that are used by the class I want to test. Since accessors have been removed from VS2012, I'm fine with using [InternalsVisibleTo] and that works great... except when I try to shimify my internal classes, they are not visible to the Fakes framework. I should also note that the particular class I am dealing with is a static class with static methods, and I don't really want to refactor everything to use interfaces (and using stubs) because of resistance in the organization to that level of refactoring. Is there a way to

InternalsVisibleTo attribute isn't working

最后都变了- 提交于 2019-12-01 16:43:33
Before I go on I did go through this InternalsVisibleTo attribute ain’t workin'! Hence the title Okay so I had a working version of my project that was using something like the following. [assembly: InternalsVisibleTo("Stuff.Test.Support, PublicKey="0024000004800000940000000302000000240000525341310004000001000100d158cd56401c3d90b52ca1a5f273d608c3ce12aaa21385b0f4ad7dc1b747e45ee1f1771c104c52cb4da1b587ae38b6d36fa1d8e8f14003c42f700bc62ef2ec04b231c5d930e4bc3691aa1ef7b6713926316d4be1165ede086e94190b44edd4ad0d024230ae6eb9deb728b00d71d1d468b20a9bb78f242bd6c41e640c2e5c0cd5")] In the Properties

SGEN, InternalsVisibleTo and assembly signing

天大地大妈咪最大 提交于 2019-12-01 00:38:22
I'm trying to do something a bit unusual... I have this class Foo : public class Foo { public Foo(string name) { this.Name = name; } internal Foo() { } public string Name { get; internal set; } public int Age { get; set; } } Notice the internal setter for Name, and the internal default constructor. This would normally prevent the XML serialization, but I also marked the XML serialization assembly as "friend" with InternalsVisibleTo : [assembly: InternalsVisibleTo("TestXML2008.XmlSerializers")] And I added a MSBuild task to pre-generate the serialization assembly : <Target Name="AfterBuild"

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

拜拜、爱过 提交于 2019-11-30 06:36:45
[ 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 and types to another assembly. I'm wondering whether it would be a Good Idea to use this to create a

InternalsVisibleTo does not work

只谈情不闲聊 提交于 2019-11-30 02:39:01
I insert the line: [assembly: InternalsVisibleTo("MyTests")] inside my project under test( Properties/AssemblyInfo.cs ) where MyTests is the name of the Unit Test project. But for some reason I still cannot access the internal methods from the unit test project. Any ideas about what I am doing wrong ? Joe If your assembly is signed with a strong name look at this answer . Otherwise check that the name of your test assembly really is "MyTests.dll" (it doesn't have to match the project name, though it will by default). Lets break it down a bit as many of us has experienced this slight mix-up in