views:

136

answers:

1

I know I wouldn't need this with Typemock, however, with something like MoQ , I need to use the adapter pattern to enable the creation of mocks via interfaces for code I don't control.

For example, TcpClient is a .NET class, so I use adapter pattern to enable mocking of this object, b/c I need an interface of that class. I then produce interface ITcpClient, that can then be implemented via a TcpClientAdapter class, which is just plain vanilla adapter pattern implementation.

I am looking for a tool to do this automatically (creation of interface and adapter), I would think there is one out there somewhere? (or is everyone just hand coding these)

+2  A: 

"Replace any .NET method with your own delegate" - Moles

I hand code mine but check out Moles. It will allow you to mock anything, static methods, you name it. This is not a code generator though, you will have to write the code/return values for example, but you won't need to write adapter classes. Instead you simply state what you want overridden per test.

It's new and I've not personally used it but from the videos I've seen it seems promising. Especially for troublesome areas such as static API's or classes out of your control.

Finglas
This is definitely a good alternative to Typemock, as they both seem to have the same goals, isolation. MS research projects have given me hair pulling experiences, but I will try to get it working.
RyBolt