
Untitled
By: a guest on
May 15th, 2012 | syntax:
None | size: 0.64 KB | hits: 15 | expires: Never
How to mock a public readonly field
public abstract class DataService
{
public readonly string DataDirectory; //I need to mock the return value
protected DataService()
{
DataDirectory = "c:temp";
}
}
public abstract class DataService
{
public readonly DirectoryInfo DataDirectory;
protected GitService()
{
DataDirectory = new DirectoryInfo("c:temp");
}
public virtual object GetRepositoryByName(string name)
{
//Locate the repo, build it and return it
string path = Path.Combine(DataDirectory.FullName, name);
return new BuildRepository(path);
}
}