I am wondering how to get around this. I am using nhibernate and fluent.
I have a domain class like this
public class User
{
public virtual int UserId {get; private set;}
}
this seems to be the convention when doing nhibernate as it stops people from setting and id as it is auto generated.
Now the problem comes when I am unit testing.
I have all my nhibernate code in a repo that I mock out so I am only testing my service layer. The problem comes when this happens.
User user = repo.GetUser(email);
this should return a user object.
So I want to use moq to do this
repo.Setup(x => x.GetUser(It.IsAny<string>())).Return(/* UserObject here */)
now here is the problem
I need to make that User object and put it in the Return part.
So I would do something like
User user = new User()
{
UserId = 10,
}
But this is where the problem lies I need to set the Id because I actually use it later on to do some linq on some collections(in the service layer as it is not hitting my db so it should not be in my repo) so I need to have it set but I can't set it because it is a private set.
So what should I do? Should I just remove the private or is there some other way?