MockRepository |
MockRepositoryThe MockRepository is the main interaction point with Rhino Mocks. Common usage pattern is to create the <Rhino.Mocks.MockRepository> on [SetUp] and then create mock objects using either <Rhino.Mocks.MockRepository.CreateMock> or <Rhino.Mocks.MockRepository.DynamicMock> and setup expectations on the mock object(s) by callling their methods. A call to <Rhino.Mocks.MockRepository.ReplayAll> would move the mock object(s) to replay state, a call to <Rhino.Mocks.MockRepository.VerifyAll> is made from the [TearDown] method. Thread SafetyMockRepository is capable of verifying in multiply threads, but recording in multiply threads is not recommended. If you need to do so you must use the <Rhino.Mocks.Expect.On> and <Rhino.Mocks.LastCall.On> methods and not <Rhino.Mocks.Expect.Call> and LastCall’s various methods. Code SampleMockRepository mocks; Class Responsbilities
See Also
Summary
OrderedMoves the entire MockRepository to use ordered recording. This call is only valid during the recording phase. This call affects all mock objects that were created from this repository. The orderring is ended when the returned IDisposable’s Dispose() method is called. [Test] UnorderedMoves the entire MockRepository to use unordered recording (the default). This call is only valid during the recording phase. This call affects all mock objects that were created from this repository. [Test] BackToRecordMoves the mocked object back to record state. This works on mock objects regardless of state. You can (and it’s recommended) to run Verify() before you use this method, but it’s not neccecary. NoteThis will remove all the current expectations from the mock repository. ReplayAllMoves all the mock objects in the repository to replay state. NoteThis method will skip any mock object that you’ve manually moved to replay state by calling Replay VerifyAllVerifies that all the expectations on all mock objects in the repository are met. NoteThis method skip any mock objects that you’ve manually verified using Verify Exception safetyIf an unexpected exception has been thrown (which would fail the test) and the Repository still have unsatisfied expectations, this method will cause another exception, that may mask the real cause. If this happens to you, you may need to avoid the using statement until you figure out what is wrong: The using statement: using(MockRepository mocks = new MockRepository()) The unrolled using statementMockRepository mocks = new MockRepository()) This way you can get the real exception from the unit testing framework. |