views:

498

answers:

5
+2  A: 

Try doing a

mockRepository.ReplayAll()

after the line where you set your Expect.

womp
+1  A: 

I'm not super familiar with RhinoMocks (I've been using Moq), but couldn't:

FakePersonRepository.Expect(action => action.Get(1)).IgnoreArguments().Return(expectedPerson);

be

FakePersonRepository.Expect(action => action.Get(1)).Return(expectedPerson);

I also think you need a Replay() with RM.

rball
Yeah the IgnoreArguments is superfluous. Its the replay I was missing.
Dav Evans
+1  A: 

As others have said, I believe you will need a Replay somewhere with the style of tests you are using; As an alternative, you could use the newer AAA Syntax along with the static MockRepository.GenerateMock<>()/MockRepository.GenerateStub<>() methods which would not require a Replay.

Chris Shaffer
A: 

Chris is on the money here. The AAA syntax and using GenerateStub for this senario is best.

var FakePersonRepository = MockRepository.GenerateStub<<IRepository<Person>>();
FakePersonRepository.Stub(x => x.Get(1)).Returns(expectedPerson);

PersonService PersonService = new PersonService(FakePersonRepository);
Person returnedPerson = PersonService.Get(1);
Dav Evans
A: 

With the AAA syntax and GenerateMock you can also verify that PersonRepository is called with the correct parameter and correct number of times:

Person expectedPerson = new Person() { Id = 1, Name="Jon"}; 

MockRepository MockRepository = new MockRepository(); 
var FakePersonRepository = MockRepository.GenerateMock<IRepository<Person>>(); 

FakePersonRepository.Expect(action => action.Get(1)).Return(expectedPerson).Repeat.Once(); 
PersonService PersonService = new PersonService(FakePersonRepository); 
Person returnedPerson = PersonService.Get(1); 

Assert.IsNotNull(returnedPerson); 
FakePersonRepository.VerifyAllExpectations();
Marcus