Let’s say I have a bunch of classes that look something like…
class Foo{
private Bar highlyCoupled = new highlyCoupled();
public bool DoTheThing(){
return highlyCoupled.doesTheThing();
}
}
Is it possible to use reflection to open up foo and inject (duck-punch may be a more correct term) some sort of mockHighlyCoupled in the place of highlyCoupled?
What about in this situation…
class DoubleFoo : Foo{
public bool DoTheOtherThing(){
return DoTheThing();
}
}
Can the inherited highlyCoupled have a mock inserted in it’s place?
Refactoring the code so as to not require reflection isn’t possible, unfortunately.
Since you can’t refactor using a mocking framework could make this a bit easier for you. For Example:
TypeMock:
Moq:
To be honest I haven’t actually tried this out with Moq but I think it will do what you need.