I need your opinion on writing a constructor that's clean code and unit test friendly.
Option 1 :
var res1 = bigObject.GetResource1();
var res2 = bigObject.GetResource2();
var res3 = bigObject.GetResource3();
var myObject = new Foo(bigObject, res1, res2, res3);
//and the foo ctor just initializes its internal fields with given data
Option 2 :
var myObject = new Foo(bigObject);
[...]
public Foo(Bar bigObject)
{
_bigObject = bigObject;
_res1 = _bigObject.GetResource1();
_res2 = _bigObject.GetResource2();
_res3 = _bigObject.GetResource3();
}
Option 2 is cleaner (?) in the code (in option 1 I have the feeling I have to spoon-feed the Foo object because it is not smart enough to get what it needs by itself)), but requires helper methods in the tests to mock calls to Get*
and pass what we want.
Of course, I can also write both ctors, and use one in the tests and the other in the "real" code, but it'd looks a bit weird and bloated to someone discovering the class, and the simple constructor wouldn't be tested.
What would you advise ?
EDIT :
Resources are not especially linked to the big object (i.e. there is no "wrong" combination). Imagine for example that the big object is a College, and resources are a list of teachers, a list of courses and a list of rooms, and we want to build, say, a timetable.