I'm trying to test the following code:
public ICollection<RawCatalog> ReadCatalog(string familyName)
{
// Root folder for the family
string familyFolder = this.GetFamilyFolder(familyName);
DirectoryInfo familyFolderInfo = new DirectoryInfo(familyFolder);
foreach (DirectoryInfo subFamilyFolderInfo in familyFolderInfo.EnumerateDirectories())
{
// Do stuff
}
}
I expected that this would 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 is not working as seems that fakeDirectoryInfo is not being returned in the constructor. How should I do the test? (I should not change the source code as it's working code if possible).
I've read something about future mocking and using DoNothing() but not sure if this apply to my own situation.
Thanks in advance.
new
expressions is pretty high on our list of features-to-be, but it wouldn't hurt if you voted for it in the JustMock feedback portal: feedback.telerik.com/Project/105/Feedback/Details/… – Crystacrystal