An approach I've used very successfully is to roll my own proxy classes for unmockable third party types. E.g. I want to take a dependency on a type ThirdParty.Foo
which is sealed/static/has no interface/etc. Instead, I create a library called ThirdParty.Proxies
and add a concrete type Foo
and an interface IFoo
to this new library. The interface IFoo
exposes members equivalent to all those which I require from the underlying ThirdParty.Foo
type and the concrete type ThirdParty.Proxies.Foo
implements those members by doing nothing other than forwarding method calls to the underlying third party library. ThirdParty.Proxies
is excluded from unit testing and code coverage. In my consuming assembly, I take a dependeny only on ThirdParty.Proxies
and, specifically, I only take a dependency on IFoo
. This way I can mock this dependency easily and attain 100% code coverage for my consuming assembly.
This is a little more work, and it's similar to what Moles does for you dynamically, but once done it can be re-used everywhere and your unit tests will be faster by not incurring the overhead of Moles.