I have an interface:
public interface IRepeater
{
void Each(string path, Action<string> action);
}
I want to mock this interface using Moq. Now I can obviously do the following:
var mock = new Mock<IRepeater>();
mock.Setup(m => m.Each(It.IsAny<string>(), It.IsAny<Action<string>>());
However, to help testing, I want to be able to mock stringthat which is passed in Action<string>. Can this be done with Moq? If so, how?
Update
To clarify, I'm testing another classthat has a dependency on IRepeater. I want to make fun IRepeater.Eachso that I can control stringwhich one gets Action, so I can check the behavior.
exampleSo, if I have class, like that.
public class Service
{
private readonly IRepeater _repeater;
public Service(IRepeater repeater)
{
_repeater = repeater;
}
public string Parse(string path)
{
var builder = new StringBuilder();
_repeater.Each(path, line => builder.Append(line));
return builder.ToString();
}
}
How can I make fun IRepeater.Eachso I can test Service.Parse?