I am trying to test the following code:
public ICollection<RawCatalog> ReadCatalog(string familyName)
{
string familyFolder = this.GetFamilyFolder(familyName);
DirectoryInfo familyFolderInfo = new DirectoryInfo(familyFolder);
foreach (DirectoryInfo subFamilyFolderInfo in familyFolderInfo.EnumerateDirectories())
{
}
}
I expected this to work:
// Arrange
DirectoryInfo fakeDirectoryInfo = Mock.Create<DirectoryInfo>(Constructor.Mocked);
Mock.Arrange(() => new DirectoryInfo(@"testRoot\DrivesData\TestFamily")).Returns(fakeDirectoryInfo);
Mock.Arrange(() => directoryInfo.EnumerateDirectories()).Returns(new DirectoryInfo[] { });
But it does not work, it seems that fakeDirectoryInfo is not returned in the constructor. How do I pass the test? (I should not change the source code as working code, if possible).
I read something about the future of ridicule and the use of DoNothing (), but I'm not sure if this applies to my own situation.
Thanks in advance.
source
share