Some options, based on what you showed, would be :
- mock the two methods which set these values,
- break
_settings
and config
or even the two methods which provide the results into a separate class ( like a configuration kind of thing ) and inject the interface of that class as a dependency at whatever level it makes sense. You can then mock those values.
I would pursue one of these options.
In regards to the View values, I would try to separate that. There are number of issues with this code.
- you have a
OnFileNameChanged
metho and you probably can't change its signature and doesn't return anything. So, I would separate the code even more. Take the code out of it and create another method that you control. Do not add any View setting in that one. The purpose ifs to cover the logic and return an object with some calculated values.
Then, in the OnFileNameChanged
you assign what you need for the view stuff. In short, take the logic part out and deal with it somewhere else and test that.
You have 3 values that you are assigning to the View object, so make your new method return either one value, or an object with three values, covering each possibility.
public void OnFileNameChanged(string fileName)
{
var calculatedValues = CalculateValues(//might need some params here)
_view.A = calculatedValues.A;
_view.B = calculatedValues.B;
_view.C = calculatedValues.C;
}
public MyReturnType CalculateValues()
{
var result = new MyReturnType();
var config = FirstPrivateOperation();
if ( config == null ) { return result; }
//etc etc
}
public MyReturnType
{
public Whatever A { get;set }
public Whatever B { get;set }
public Whatever C { get;set }
}
you can go even further and deal with the private methods in a different way. you might want to add a separate class to replace them and then that makes theme easier to test / mock as well.