Skip to content

Add Methods to ISftpClient to make Moq Testable #1015

Closed

Description

@Pieeer1

It would be great if there were more methods from SFTP client in ISftp Client (such as connect) so that in dependency injecting Moq unit tests, you can setup and verify the expressions.

Activity

  1. Pieeer1 commented on Oct 20, 2022

    @Pieeer1
    Author

    Found a couple posts related to this that are closed, however it is still an issue. Current workaround found was:

                    if (_sftpClient is SftpClient client)
                    {
                        client.Connect();
                    }
    

    Where _sftpClient is the interface and your dependency injection looks like:

     builder.Services.AddSingleton<ISftpClient,SftpClient>(
                        (s) => {
                            return new SftpClient("ip", "user", "password");
                        }
                    );
    

    Fix found here: #975

  2. Pieeer1 commented on Oct 20, 2022

    @Pieeer1
    Author

    Additionally, There needs to be an interface for SftpFile, or the class needs to have a more accessible constructor.

  3. WojciechNagorski commented on Aug 25, 2023

    @WojciechNagorski
    Collaborator

    ISftpClient has been implemented

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