Starting with unit testing, I wonder how to test our old code, that looks something like that:
public Player DetermineWinner(Player a, Player b)
{
if(a.Age>b.Age)
....
///few more conditions checking properties of both players
}
class Player
{
public Player (DBConnection c, world w, DateTime logTime)
{} //not easy to mock...
}
How to mock that? I understand that if the Player implemented an interface, I could simply create a mock and pass it in the unit test with desired values, but that is not the case here. The Player class is instantiated using various parameters so I cannot simply create an instance during the unit test and pass it - it depends on various external objects. I would need to mock the Player object and set its properties at the same time so that the tests are deterministic. What is the best approach to start with?
Should I next time use interfaces to decouple that?