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

Untitled

By: a guest on May 15th, 2012  |  syntax: None  |  size: 0.64 KB  |  hits: 15  |  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 a public readonly field
  2. public abstract class DataService
  3. {
  4.     public readonly string DataDirectory; //I need to mock the return value
  5.  
  6.     protected DataService()
  7.     {
  8.         DataDirectory = "c:temp";
  9.     }
  10. }
  11.        
  12. public abstract class DataService
  13. {
  14.     public readonly DirectoryInfo DataDirectory;
  15.  
  16.     protected GitService()
  17.     {
  18.         DataDirectory = new DirectoryInfo("c:temp");
  19.     }
  20.  
  21.     public virtual object GetRepositoryByName(string name)
  22.     {
  23.          //Locate the repo, build it and return it
  24.          string path = Path.Combine(DataDirectory.FullName, name);
  25.          return new BuildRepository(path);      
  26.     }
  27. }