FluentFTP icon indicating copy to clipboard operation
FluentFTP copied to clipboard

Any suggestions for how to include FluentFTP in unit test mocks?

Open nathanjwtx opened this issue 10 months ago • 3 comments

I am attempting to add some unit tests for out application and I would like to mock either .Connect(); or .IsConnected however neither of these are mockable due to non-overrideable members. I was wondering if you had any suggestions to get around this?

nathanjwtx avatar Mar 14 '25 13:03 nathanjwtx

I'd like @robinrodricks to chime in on this one. But I think that something could be done to make this possible.

FanDjango avatar Mar 14 '25 20:03 FanDjango

Can you provide the members that you need overridable for your mockery?

FanDjango avatar Mar 24 '25 10:03 FanDjango

Hi. If possible, .Connect(), .DisConnect(), and .IsConnected. However I could probably achieve what I need to without .DisConnect() as I could use .IsConnected instead.

nathanjwtx avatar Mar 25 '25 13:03 nathanjwtx

@nathanjwtx I have committed some fake FTP clients suitable for mocking. Please check it and get back if it fulfills your use case

https://www.nuget.org/packages/FluentFTP/53.0.1

robinrodricks avatar Jul 17 '25 10:07 robinrodricks

Sorry for the delayed response. Going to take a look at this today.

nathanjwtx avatar Aug 01 '25 14:08 nathanjwtx

Not sure if perhaps I'm dong something incorrectly but the following code responds with the same error regarding non-overridable members not allowed in setup.

var mockFtp = new Mock<FakeAsyncFtpClient>();
mockFtp.Setup(x => x.IsAuthenticated).Returns(true);
mockFtp.Setup(x => x.IsConnected).Returns(true);

nathanjwtx avatar Aug 04 '25 21:08 nathanjwtx

I don't understand. What's the error and how do you expect us to fix it? Pls take a look at the class code and suggest a fix.

https://github.com/robinrodricks/FluentFTP/tree/master/FluentFTP/Client/FakeClient

robinrodricks avatar Aug 05 '25 04:08 robinrodricks

Thank you for your time and updates. I think this issue can be closed now as I have been able to achieve what I was looking to do.

nathanjwtx avatar Aug 13 '25 16:08 nathanjwtx