rhino-mocks icon indicating copy to clipboard operation
rhino-mocks copied to clipboard

Enable the possibility of removing a determined expectation or give access to the rootRecorder

Open marcoslimagon opened this issue 8 years ago • 1 comments

I think that could be useful to remove an pre-defined expectation.

public void BackToRecord(object obj, BackToRecordOptions options) { this.IsMockObjectFromThisRepository(obj); if ((options & BackToRecordOptions.Expectations) == BackToRecordOptions.Expectations) { foreach (IExpectation allExpectationsForProxy in this.rootRecorder.GetAllExpectationsForProxy(obj)) { **this.rootRecorder.RemoveExpectation(allExpectationsForProxy);** } this.rootRecorder.RemoveAllRepeatableExpectationsForProxy(obj); } MockRepository.GetMockedObject(obj).ClearState(options); this.proxies[obj] = this.proxies[obj].BackToRecord(); foreach (IMockedObject dependentMock in MockRepository.GetMockedObject(obj).DependentMocks) { this.BackToRecord(dependentMock, options); } }

this.rootRecorder.RemoveExpectation(allExpectationsForProxy);

I would like to have access to the rootRecorder so I could be able to remove the expectations and set new ones.

The tests I run are "scenarios" so I don't care about how many times an method would be executed, I would like only to define the returning values and during my scenario execution the value changes. Also the system creates multiple threads during the execution so this make the testing infrastructure more complex.

marcoslimagon avatar Apr 20 '16 16:04 marcoslimagon

Why aren't you using the AAA model? https://ayende.com/blog/3318/rhino-mocks-arrange-act-assert-syntax

ayende avatar Apr 20 '16 17:04 ayende