I'm trying to fake a call to a method with an out parameter, with a ReturnsLazily with some basic logic in it. Ideally, I could assign a value via AssignsOutAndRefParameters based on the ReturnsLazily. However, AssignsOutAndRefParameters only accepts a value up front when the expression is compiled, is there any 'Lazily' type behavior that I'm missing?
Random r = new Random();
int[] value = new int[] { 1 };
A.CallTo(() => loader.TryLoad(A<int>.Ignored, out value))
.WithAnyArguments()
.ReturnsLazily((int key, int[] inValue) =>
{
List<int> result = new List<int>();
if (key > 0)
{
for (int i = 0; i < r.Next(100); i++)
{
result.Add(r.Next());
}
}
value = result.ToArray();
return result.Count > 0;
})
.AssignsOutAndRefParameters(value); //Assigns [1], instead of [r,a,n,d,o,m,i,n,t,s]