I try to make my simple mock to work, but it’s too tedious.
I get one mistake in this place
(string s1, string s2) => { return (string)(s1 + s2); });
The message says that
“Delegate ‘System.Func’ does not take 2 arguments”
but in this article all works
all my code here.
public interface IWriteTwoString
{
string WriteTwoStrings(string s1, string s2);
}
public MyPriceReducerTest()
{
Mock<IWriteTwoString> writeMock = new Mock<IWriteTwoString>(MockBehavior.Strict);
writeMock.Setup(m => m.WriteTwoStrings(It.IsAny<string>(), It.IsAny<string>()))
.Returns<string>((string s1, string s2) => { return (string)(s1 + s2); });
}
Your problem is with the expression:
Returns<string>which tells moq that yourWriteTwoStringshas onestringparameter, but you have two therefore you get an error.So you need to write:
Or you can leave out the types completely because the compiler can infer them: