You can use dependancy injection and abstraction over Server.MapPath
public interface IPathProvider
{
string MapPath(string path);
}
And production implementation would be:
public class ServerPathProvider : IPathProvider
{
public string MapPath(string path)
{
return HttpContext.Current.Server.MapPath(path);
}
}
While testing one:
public class TestPathProvider : IPathProvider
{
public string MapPath(string path)
{
return Path.Combine(@"C:project",path);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…