I have an issue with Mocking methods Please see below:
This is the interface
public interface IShop
{
string CheckNames(string[] names);
}
Here is my Mock
var names = "A,B,C";
var shopMock = new Mock<IShop>(MockBehavior.Strict);
shopMock.Setup(s => s.CheckNames(names.Split(','))).Returns("GoodNames");
However when I call this method in my test, this method is failed with Moq.MockException : IShop.CheckNames(["A", "B", "C"]) invocation failed with mock behavior Strict.
var obj = shopMock.Object;
Assert.AreEqual("GoodNames", obj.CheckNames(names.Split(',')));
To make it work, I need to
var names = "A,B,C";
var shopMock = new Mock<IShop>(MockBehavior.Strict);
var nameList = names.Split(',');
shopMock.Setup(s => s.CheckNames(nameList)).Returns("GoodNames");
var obj = shopMock.Object;
Assert.AreEqual("GoodNames", obj.CheckNames(names.Split(',')));
Why I need to create nameList here to make it to work? Thanks