How do I check if Create was not called without using the Rhino Mocks AssertWasNotCalled method.
Here is the test:
[Test]
public void When_try_to_create_directory_that_already_exits_return_false()
{
var directoryInfoMock = MockRepository.GenerateMock<IDirectoryInfoWrap>();
directoryInfoMock.Stub(x => x.Exists).Return(true);
directoryInfoMock.Expect(x => x.Create());
Assert.AreEqual(false, new DirectoryInfoSample().TryToCreateDirectory(directoryInfoMock));
directoryInfoMock.VerifyAllExpectations();
}
Also, can someone clarify what Stub does.
ensures that any call to the property
directoryInfoMock.Existswill returntrue. But if the property is never call or called many times, it will not cause the test to fail. The purpose of the stub is to provide some meal to your code under test so that it can run normally.expects that the method
directoryInfoMock.Createbe called at least once. If not, an exception will be thrown by Rhino.Mocks during the execution ofdirectoryInfoMock.VerifyAllExpectations().So basically, your unit test should work as expected. What is the output of the test?
UPDATE:
You might want to specify an explicit number of times the method should be called as well. This can be done by using
Repeat.xwithxisOnce(),Twice(),Never(), orTimes(N).This expects that
Createis never called. And of course your test will fail if it is actually called.