The Situation
Suppose I have a class with an internal method:
class MyClass : IMyClass
{
public void PublicMethod() { ... }
internal void InternalMethod() { ... }
}
that implements an interface:
interface IMyClass
{
void PublicMethod() { ... }
}
And a container class that holds an instance of MyClass
and other concrete classes:
class ContainerClass
{
public MyClass myClass;
...
}
ContainerClass
is used by various assemblies. When used within the same assembly as MyClass
the calling method can invoke containerClass.myClass.InternalMethod()
The Problem
In an effort to make things more easily mockable for testing, I am now trying to replace the ContainerClass
's properties with interfaces rather than concrete classes, e.g.:
class ContainerClass
{
public IMyClass myClass;
...
}
But, if I do that, InternalMethod
can no longer be invoked using containerClass.myClass.InternalMethod()
because the method doesn't exist on the interface... nor can it, because it is internal
. However, I cannot make the interface internal because ContainerClass
is used by other assemblies as well.
Let's assume that I cannot change the internal
access to that method. Is there another way?
EDIT: This is different from How to Mock the Internal Method of a class? because I am not trying to mock the internal method, I am trying to keep it exposed when replacing a concrete class (MyClass
) with an interface (IMyClass
).