Using IFtp for testing

0 votes
asked Dec 19, 2012 by CJM3407 (150 points)
edited Dec 20, 2012

I am using Unity for dependency injection and want to write unit tests for my FtpConnection class. For this to happen, I have to use IFtp in my actual code, so I can register a mock ftp class in a unit test. The problem is certain methods and properties not in the IFtp definition. Specifically, for my code I am seeing htere is no Connect(), Passive, or EnabledExtensions. I can see some of the properties not being represented, but why isn't Connect, when there is a Disconnect?

I just want to know if there is plan to have IFtp fully complete for the purposes of unit testing?

Thank you

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered Dec 20, 2012 by Lukas Pokorny (124,570 points)
edited Dec 20, 2012
 
Best answer

The main purpose of IFtp was to make it possible to easily write code that works with both Ftp (part of Rebex FTP/SSL) and Sftp (part of Rebex SFTP) objects and only the feaures supported by both protocols were included. Unit testing was not one of the design goals.

For the purpose of unit testing, I would recommend extending the IFtp interface and Ftp object by inheriting from them, like this:

    public interface IFtp2 : IFtp
    {
        string Connect(string serverName, int serverPort, SslMode security);
        bool Passive { get; set; }
        FtpExtensions EnabledExtensions { get; set; }
    }

    public class Ftp2 : Ftp, IFtp2
    {
        string IFtp2.Connect(string serverName, int serverPort, SslMode security)
        {
            return Connect(serverName, serverPort, security);
        }

        bool IFtp2.Passive
        {
            get { return Passive; }
            set { Passive = value; }
        }

        FtpExtensions IFtp2.EnabledExtensions
        {
            get { return EnabledExtensions; }
            set { EnabledExtensions = value; }
        }
    }

This way, it's quite simple to add the missing functionality without the need to re-implement the whole IFtp interface.

commented Dec 20, 2012 by CJM3407 (150 points)
edited Dec 20, 2012

Thank you for the suggestion

...