I found the post titled MOQ: Returning value that was passed into a method which was quite helpful in that I can get one of the values passed in to provide as a return value.
The issue I am faced with is that I need to convert the value (a string) to an IEnumerable as the one and only item in the enumeration, and I am getting tripped up on the syntax for doing so.
Here is what I have so far:
var aggregator = new Mock<IUrlAggregator>();
aggregator
.Setup(x => x.ProcessUrl(It.IsAny<IUrlFileLineInfo>()))
.Returns((IUrlFileLineInfo x) => x.Url); <-- Need to return IEnumerable<string> here, not string
The ProcessUrl signature looks like this:
IEnumerable<string> ProcessUrl(IUrlFileLineInfo urlInfo);
And the IUrlFileLineInfo interface:
public interface IUrlFileLineInfo
{
string Url { get; set; }
string Mode { get; set; }
}
So how can I convert the string value to an IEnumerable within the context of a lamba expression (through the .Returns() method)?
Update
This is what I ended up with. Thanks for the help. Hopefully this will help others who are new to lambdas.
var aggregator = new Mock<IUrlAggregator>();
aggregator
.Setup(x => x.ProcessUrl(It.IsAny<IUrlFileLineInfo>()))
.Returns((IUrlFileLineInfo x) => new List<string>() { x.Url });