I have an object that takes in a parameter of the same type in the constructor:
public class Person {
private Person theParent;
private string theName;
public Person(string aName, Person aParent)
{
if(aParent == null)
{
thrown new ArgumentNullException("aParent");
}
theParent = aParent;
theName = aName;
}
}
In my unit test I have to create a new Person object but the constructor requires another Person object to be passed in. I overcome this problem in my application by getting the Person object to pass in from the database (using NHibernate and all its magic)*. I don’t want to tie database access into this test as it is not testing any database functionality. Should I just mock the parent object (I’m using Rhino Mocks in some of my other tests) or is there a better way to approach this?
*There is guaranteed to always be one record in the databse that I can retrieve to make the parent object.
I assume that at some point you are expected to reach a top node? What is the correct value for
aParentthen?My guess would be
null, and that would mean thisPersonis the very first in it’s line (whatever that means for your application, perhaps Adam or something?).