//class = Person
public string Name { get; internal set; }
I have an object with several different fields that are declared as shown above. I would like to use Moq so I can unit test the repository. The repository simply returns a list of names, so I would like to setup Moq to work with it like so:
var personRepositoryMock = new Mock<IPersonRepository>();
personRepositoryMock
.Setup(p => p.GetNames())
.Returns(new List<Person>
{
new Person{Name = "Hulk Hogan"}
});
Being new to mocking and unit testing in general, I have a couple of questions:
What are my options to stub out the Person class in my scenario?
What is the benefit of mocking in this situation? I read and read and read, but I can't seem to get my head around why I see examples like this, testing a repository. Mocks make sense to me when I have to unit test business logic, but not so much in the data layer. Any words of wisdom to clear this up for me?
Thanks.