Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 17th, 2012  |  syntax: None  |  size: 0.72 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to mock DirectoryInfo class?
  2. public interface IDirectoryInfoWrapper
  3.   {
  4.     public IFileInfoWrapper[] GetFiles(string searchPattern, SearchOption searchType);
  5.     public IDirectoryInfoWrapper[] GetDirectories();
  6.   }
  7.        
  8. // Check that the directory is valid
  9.   DirectoryInfo directoryInfo = new DirectoryInfo( argPath );
  10.   if ( directoryInfo.Exists == false )
  11.   {
  12.     throw new ArgumentException
  13.         ("Invalid IFileFinder.FindFiles Directory Path: " + argPath);
  14.   }
  15.        
  16. DirectoryInfo directoryInfo = new DirectoryInfo( argPath );
  17.        
  18. class Factory : IFactory
  19. {
  20.   IDirectoryInfoWrapper Create(string arg)
  21.   {
  22.     var dirInfo = new DirectoryInfo(arg);
  23.     var wrapper = new DirectoryInfoWrapper(dirInfo);
  24.     return wrapper;
  25.   }
  26. }