I'm using a third party library class Foo
that has several public methods and properties that my class uses as a dependency.
I want to test my class and mock the Foo
object, but it does not have an interface. So I was thinking, I could inherit the class in a class of my own, extract an interface, and voila! I would have an injectable interface.
...but of course there are complications. Foo
has a bunch of public fields. These can't go into an interface, so I'd have to write property wrappers for the fields. It's annoying.
Is there an automated way to do this? I have ReSharper, but there doesn't seem to be a way to automagically do this, which means I'm writing a lot of tedious code.
virtual
? If so, you can use something like Rhino Mocks'PartialMock
. You'd be able to override/stub/mock the methods and have access to the public fields. – Ituvirtual
and then usePartialMock
! What mocking framework are you using? – Itucallbase
property. #4770428 So you can create a wrapper, expose methods asvirtual
and then use a a partial. – Itu