I have a private method which is being called in a method I am testing.I want to verify the correct parameters are being passed to this private method. I have written the following setup in Moq which will test what I want, however it doesn’t really allow me to follow the Arrange, Act, Assert pattern.
Is there any way I can perform a similar test where by the assert can appear with all of my other asserts? At the moment the code below lives within the Arrange.
myClass.Setup(
x =>
x.myMethod(
It.IsAny<Person>>(),
It.IsAny<string>(),
It.IsAny<Person>(),
It.IsAny<ICollection<string>>(),
It.IsAny<ICollection<string>>(),
It.IsAny<bool>())).Callback
<Person, string, Person, Person, ICollection<string>, bool>(
(a, b, c, d, e, f) =>
{
Assert.AreEqual("NameA", a.Name);
Assert.AreEqual("StringB", b);
Assert.AreEqual("NameC", c.Name);
Assert.AreEqual(2, d);
var dList = d.ToList().OrderBy(x => x.Name);
Assert.AreEqual("PersonA", dList[0].Name)
Assert.AreEqual("PersonB", dList[1].Name);
});
I should say, I am aware that you can perfom a verify to check whether a method has been called with certain inputs, however I am not aware of any way of matching the ICollection params.
If you are using those assertions to check the parameters, you can do it in your setup. If your mock uses strict behavior, it will fail if a parameter doesn’t match the predicate.