The problem here is with delayed execution. This is not until the IEnumerable<string> is listed that the list of elements is “built”. Because Rhino.Mocks simply records what is called, it never "uses" the method arguments, and therefore the list is never built or enumerated. As you saw, adding ToList () or ToArray () lists and creates a list so that the test passes if you use one of these methods.
One workaround is to grab the list that was passed to the method and do your check:
var list = (IEnumerable<int>) myBob.GetArgumentsForCallsMadeOn(b => b.DoThings(null))[0][0]; Assert.AreEqual(10, list.Count());
This test passes and does not require any changes to your code.
PatrickSteele
source share