Skip to content

SftpFile constructor for testing #1667

Closed

Description

@balestrinc

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

Activity

  1. bronumski commented on Jul 11, 2025

    @bronumski

    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.

  2. Rob-Hague commented on Jul 12, 2025

    @Rob-Hague
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions