I\'ve a method. which retrieve a document from hard disk. I can\'t test this from unit testing. It always throw an exception invalid null path or something. How to test that
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);
}
}