如何在不使用Rhino Mocks AssertWasNotCalled方法的情況下檢查Create是否未被調用。如何在Rhino Mocks中檢查Create方法是否使用Expect調用而不是AssertWasNotCalled?
下面是測試:
[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();
}
此外,有人可以澄清存根做什麼。
這與您的問題無關,但您可以使用'Assert.IsFalse(x)'而不是'Assert.AreEqual(false,x)'來提高可讀性和測試的簡潔性。 – 2010-09-07 18:14:02
是的,我知道。我剛剛通過在線教程。我剛開始使用MbUnit,並注意到你是Gallio項目的一部分。非常好的工作。 – Xaisoft 2010-09-07 18:43:45