I think it would be easier to use the new AAA (Arrange/Act/Assert) syntax. Something like this:
var mockBoard = MockRepository.GenerateStub<IBoard>(); // arrange mockBoard.Stub(b => b.Position(6,6)).Returns(StoneColor.Black); mockBoard.Stub(b => b.Position(5,6)).Returns(StoneColor.White); mockBoard.Stub(b => b.Position(6,5)).Returns(StoneColor.White); mockBoard.Stub(b => b.Position(7,6)).Returns(StoneColor.White); // act Gameplay gameplay = new Gameplay(mockBoard, Player.White); gameplay.PlayerMove(Player.White, 6, 7); // assert mockBoard.AssertWasCalled(b => b.RemoveStone(6,6)); --- Patrick Steele http://weblogs.asp.net/psteele On Tue, Jun 12, 2012 at 2:34 AM, R8Lm <[email protected]> wrote: > Hello, I am trying to write a Go Game. I am new to Rhino Mocks and > trying to TDD with it. > > Here is a test I am trying to write (in nunit c#): > > public void Gameplay_PlayerMove_SurroundAnEnemyStoneShouldRemoveIt() > { > MockRepository mocks = new MockRepository(); > IBoard mockBoard = mocks.DynamicMock<IBoard>(); > > using (mocks.Record()) > { > mockBoard.Position(6, 6); > LastCall.Return<StoneColor>(StoneColor.Black); > > mockBoard.Position(5, 6); > LastCall.Return<StoneColor>(StoneColor.White); > > mockBoard.Position(6, 5); > LastCall.Return<StoneColor>(StoneColor.White); > > mockBoard.Position(7, 6); > LastCall.Return<StoneColor>(StoneColor.White); > > mockBoard.AddStone(StoneColor.White, 6, 7); > > mockBoard.RemoveStone(6, 6); > } > > Gameplay gameplay = new Gameplay(mockBoard, Player.White); > gameplay.PlayerMove(Player.White, 6, 7); > > mockBoard.VerifyAllExpectations(); > > } > > The problem I am having is I want the calls to mockBoard.Position(x,y) > to be optional. The only method I want to verify is > mockBoard.RemoveStone(x,y) > How can I get that behavior? > > So my mockBoard is kind of a mix of a stub and a mock. > > I heard though, that it is bad to combine stubs and mocks in one > object. If so, how would people prefer to write this test? Is there a > better way to implement my objects? > > > -- > You received this message because you are subscribed to the Google Groups > "Rhino.Mocks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rhinomocks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en.
