I am currently testing code that implements a custom configuration section handler. All validation takes place when the configuration node is read, so my tests will incorporate many different values for attributes on the XmlNode (this node is usually supplied by the .NET Framework in a call to IConfigurationSectionHandler.Create())
I would like to mock an instance of XmlNode to return the wide array of values that I will test. I tried
MockObject configXmlMock = MockManager.MockObject(typeof(XmlNode));
but I received this exception:
TestCase 'MyTestHarness.Load' failed: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
----> System.MethodAccessException : System.Xml.XmlNode..ctor()
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at TypeMock.s.b(Type A_0)
at TypeMock.MockManager.MockObject(Type type, Constructor mockConstructors, Object[] args)
at TypeMock.MockManager.MockObject(Type type, Object[] args)
MyTestHarness.Load()
--TargetInvocationException
at MockXmlNode..ctor()
Using
Reflector, I opened up System.Xml.dll and noticed that the XmlNode constructor is marked internal. I'm guessing that I cannot even access the constructor, and this is my problem.
Am I SOL?