Unit Testing, using properties to pass in an interface
===

Im reading "The art of unit testing" atm and im having some issues with using properties to pass in an interface. The book states the following: "If you want parameters to be optional, use property getters/setters, which is a better way of defining optional parameters than adding different constructors to the class for each dependency."

The code for the property example is as follows:


    public class LogAnalyzer
    {
        private IExtensionManager manager;
        public LogAnalyzer ()
        {
            manager = new FileExtensionManager();
        }

        public IExtensionManager ExtensionManager
        {
            get { return manager; }
            set { manager = value; }
        }

        public bool IsValidLogFileName(string fileName)
        {
            return manager.IsValid(fileName);
        }
    }

    [Test]
    Public void
    IsValidFileName_NameShorterThan6CharsButSupportedExtension_ReturnsFalse()
    {
        //set up the stub to use, make sure it returns true
        ...
        //create analyzer and inject stub
        LogAnalyzer log = new LogAnalyzer ();
        log.ExtensionManager=someFakeManagerCreatedEarlier;

        //Assert logic assuming extension is supported
        ...
    }

When/how would i use this feature?? The only scenario i can think of (This is probably wrong!) is if i had two methods in one class, 

Method1() retrieves the database connection string from the config file and contains some form of check on the retrieved string.

Method2() then connect to the database and returns some data. The check here could be that that returned data is not null? 

In this case, to test Method1() i could declare a stub that implements the IExtensionManager Interface, where the stub has a string which should pass any error checks i have in method1().

For Method2(), i declare a stub which implements the interface, and declare a datatable which contains some data, in the stub class. id then use the properties to assign this to the private manager variable and then call Method2?

**The above may be complete BS**, so if it is, id appreciate it if someone would let me know and ill remove it.

Thanks