I am trying to make fun of a data repository object, but after setting the wait in my MockRepository, it returns null every time. My code is as follows:
[Test]
public void GetById_NotNull()
{
Person expectedPerson = new Person() { Id = 1, Name="Jon"};
MockRepository MockRepository = new MockRepository();
var FakePersonRepository = MockRepository.StrictMock<IRepository<Person>>();
FakePersonRepository.Expect(action => action.Get(1)).IgnoreArguments().Return(expectedPerson);
PersonService PersonService = new PersonService(FakePersonRepository);
Person returnedPerson = PersonService.Get(1);
Assert.IsNotNull(returnedPerson);
}
public class PersonService
{
private IRepository<Person> _PersonRepository;
public PersonService(IRepository<Person> PersonRepository)
{
this._PersonRepository = PersonRepository;
}
public Person Get(int Id)
{
Person p = _PersonRepository.Get(Id);
return p;
}
}
code> The statement at the bottom of the test fails, and the person returned is always zero. I know that I have to do something with my layout ideas?
source
share