Sparky Mark (sparkymark) wrote in csharp,
Sparky Mark
sparkymark
csharp

NMock2 question



Is there a way to change what a mock returns from its faked methods or properies after it has been initialised?

For instance if I am testing myContainer to see if it supports repeated attempts to Add the same Foo instance regardless of the value of the Foo's boolean Bar property I want to do something like

myMockery = new Mockery();
myFoo = myMockery.NewMock();
Stub.On(myFoo).GetProperty("Bar").Will(Return.Value(false));
myCollection.Add( myFoo );
Stub.On(myFoo).GetProperty("Bar").Will(Return.Value(true));
myCollection.Add( myFoo );
Assert something about myCollection


But it seems that once you use "Stub.On" any subsequent Stub.On the same object has no effect?
  • Post a new comment

    Error

    default userpic
  • 2 comments