简体   繁体   中英

Why is JustMock claiming my mocked method is never getting called?

I have the following code in my application:

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);
    }
}

I'm unit testing it via:

[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());
    }
}

However, the assert is failing claiming Result Message: Occurrence expectation failed. Expected exactly 1 call. Calls so far: 0 Result Message: Occurrence expectation failed. Expected exactly 1 call. Calls so far: 0

Why is JustMock not detecting the occurrence correctly? This is with the latest JustMock lite Nuget package (2014.1.1317.4)

As stated in the comments, call verification is different when you use AutoMocking.

You must Arrange the automocked dependency method to be called and specify it with MustBeCalled() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM