Hi,
Welcome to the forum :-)
:arrow: It seems that you want to mock the FillStringList() and instead of calling the real code, you want to mock it, but you want to perform some action on the argument passed and actually fill the List with fake data.
:idea: The Args is used to
verify that the arguments passed are expected.
GetFilledNewsList() will be called
before the mock is created and then the list passed to
FillStringList will be validated to be the same value as the list created in GetFilledNewsList(), this is not true and your test will fail.
:arrow: There are a few ways that you can perform actions on an argument.
The most used are
DynamicReturnValue and
Custom Argument Checkers
Here is an example:
[Test]
public void GetNewsList()
{
MockManager.Init();
Mock classToMock = MockManager.Mock(typeof (ClassToMock));
// use dynamic return on a void method
classToMock.ExpectAndReturn("FillStringList",new DynamicReturnValue(GetFilledNewsList));
List<string> stringList = MyClass.GetStringList();
Assert.AreEqual(2, stringList.Count);
Assert.AreEqual("Mocked one!", stringList[0]);
Assert.AreEqual("Mocked two!", stringList[1]);
MockManager.Verify();
}
private static object GetFilledNewsList(object[] parameters, object context)
{
// get first parameter
List<string> stringList = (List<string>)parameters[0];
stringList.Add("Mocked one!");
stringList.Add("Mocked two!");
return null; // void method
}