I am learning unit test for c# web application. I am stuck in above mention scenario. I am not if I am doing it in correct way. I have FakePath class for unit test. How do I write unit test for static method,Abc.log(), in MSTest?
public class Abc{
public static void log(string msg)
{
string path=getPath(new ServerPath());
//Read on Write on path;
}
public static string getPath(IServerPath path)
{
return path.MapPath("file.txt");
}
}
interface IServerPath(){
string MapPath(string file);
}
class ServerPath:IServerPath
{
string MapPath(string file){
return HttpContext.Current.Server.MapPath(file);
}
}
class FakeServerPath:IServerPath
{
string MapPath(string file){
return @"C:\"+file;
}
Aucun commentaire:
Enregistrer un commentaire