1
Vote

Mocking capabilities

description

Hello,

I am coding a project using Alex FTPS Client as a library to provide FTP capabilities.

I use MoQ to unit test my code, but i can't mock FTPSClient. The problem is most of mocking libraries need the mocked code to be an interface, an abstract or non-sealed class.

Would it be possible to make Alex FTPS Client mockable ?

Thanks

comments

alexp wrote May 9, 2013 at 3:56 PM

Sure.

As a workaround for the moment you can just remove "sealed" from:

public sealed class FTPSClient : IDisposable

and recompile the solution.

Jissai wrote May 10, 2013 at 7:59 AM

Hello,

I tried the workaround and removed "sealed".
I go one step further but apparently when mocking a class, MoQ needs the methods to be virtual.
I confirmed this by making "Connect" methods virtual.
The better approach would be to have interface though.

Thank you.