Hello,
I'm trying to test the following code:
I expected that this would work:
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.
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.