开发者

Code generation tool, to create C# adapter classes for unit testing?

I know I 开发者_如何学Gowouldn'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)


"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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜