我的应用程序中有以下代码:
public class DirectoryCrawler
{
private IPathWrap _path;
private IDirectoryWrap _directory;
private ITrackedFileStore _trackedFileStore;
private IFileWrap _file;
public DirectoryCrawler(IPathWrap path, ITrackedFileStore trackedFileStore, IDirectoryWrap directory, IFileWrap file)
{
_path = path;
_trackedFileStore = trackedFileStore;
_directory = directory;
_file = file;
}
public void CheckDirectoryContents(string baseDirectory)
{
var trackedFiles = _trackedFileStore.GetTrackedFilesInPath(baseDirectory);
}
}
我通过以下方式进行单元测试:
[TestClass]
public class DirectoryCrawlerTests
{
private MockingContainer<DirectoryCrawler> _mockContainer;
[TestInitialize]
public void Setup()
{
_mockContainer = new MockingContainer<DirectoryCrawler>();
}
[TestMethod]
public void Requests_Tracked_Files_In_Path()
{
var instance = _mockContainer.Instance;
instance.CheckDirectoryContents("C:\\Test");
_mockContainer.Assert<ITrackedFileStore>(x => x.GetTrackedFilesInPath(Arg.IsAny<string>()), Occurs.Once());
}
}
但是,断言未能声明Result Message: Occurrence expectation failed. Expected exactly 1 call. Calls so far: 0
为什么JustMock没有正确检测到这种情况?这是最新的JustMock精简版Nuget包(2014.1.1317.4)
答案 0 :(得分:0)
如评论中所述,使用自动模拟时,通话验证会有所不同。
您必须Arrange
调用automocked依赖项方法,并使用MustBeCalled()
指定它。