I have a difficulty unit testing my class which contain a list of object.
Here is what I have
public class A
{
List<B> _list;
public A()
{
_list = new List<B>();
}
public void AddNewB(DateTime time)
{
_list.Add(new B(time));
}
public List<B> GetAllBs()
{
return _list;
}
}
I want to have a test that prove that adding a new B doesn't clear my list. But since the list is private, I can't setup an existing list whitout going through the code I want to test. Since class A is responsible of creating all new B's and adding them to it's list and that all new A's should have an empty list of B's, adding a parameter in the constructor for the sake of testing feels weird.
Edit: I fixed GetAllBs since it was a copy-paste error of AddNewBs.