You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please can you provide a public constructor or another way of instantiate a SftpFile for unit testing purpose?
I mean To be able to return data for example from the method SftpClient.ListDirectory where SftpClient is mocked
ListDirectory returns ISftpFile so it should be possible to mock that or create a dummy implementation for testing.
In general I would tend to agree with @bronumski. While it is already possible to mock some parts of the library, it is not really the library's responsibility to provide that capability. You have more control and flexibility if you can encapsulate your usage of the library into a component in your application that you can mock instead.
Activity
bronumski commentedon Jul 11, 2025
I have a similar issue with Open and Write which uses a memory stream. I want to create a mock implementation which can return pre canned responses.
Best option is to create a light wrapper around your client that exposes the methods you want and mock that out instead.
Rob-Hague commentedon Jul 12, 2025
ListDirectory returns ISftpFile so it should be possible to mock that or create a dummy implementation for testing.
In general I would tend to agree with @bronumski. While it is already possible to mock some parts of the library, it is not really the library's responsibility to provide that capability. You have more control and flexibility if you can encapsulate your usage of the library into a component in your application that you can mock instead.