public class MyClass
{
public virtual void Method1(string par1, int par2)
{
// ...
var result = new Dictionary<byte, string>();
for(var i = 0; i < 100; i++)
{
if(someCondition) break;
Method2(par1, out byte res1, out string res2);
result[res1] = res2;
}
// ...
}
public virtual void Method2(string par1, out byte res1, out string res2)
{
// ...
res1 = 1;
res2 = "res2";
// ...
}
}
// test class
public class MyClassTests
{
[Fact]
public void TestMethod()
{
string par1 = "value";
int par2 = 2;
var myClassMock = new Mock<MyClass>() { CallBase = true };
myClassMock.Verify(v => v.Method1(par1, par2), Times.Once);
myClassMock.Verify(v => v.Method2(It.IsAny<string>(), out ?, out ?), Times.AtMost(3));
}
}
In dependency of some condition, count of calls of Method2 should not be more than 3. Test is checking, does that logic work as expected for a concrete query.
The issue is: nobody can exactly know which values should be returned. Also, it may be a very large set. I guess, It.IsAny<>() would be in a right place here, but it doesn't work with out parameters.
Is there something for such cases?