I have a class that takes an instance of MethodInfo and extracts some information from it, but I would like to mock this class. This is complicated at the moment, because it accepts MethodInfo, so I planned to create a wrapper for the MethodInfo class and implement an interface on it. For instance:
public interface IMethodInfo
{
string Name { get; }
}
public class MethodInfoProxy : IMethodInfo
{
private readonly MethodInfo _method;
public MethodInfoProxy(MethodInfo method)
{
_method = method;
}
public string Name { get { return _method.Name; } }
}
public class MyClass
{
public MyClass(IMethodInfo method)
{
...
}
}
Another example is the File.Exists method. The idea would be to create IFile.Exists and put it in the FileProxy class, which would simply delegate File.Exists.
Since I am new to the world of unit testing, I would like to know if this would be considered a good approach?
source
share