One of the best solutions would be to put the material that happens in "// do magic" in a separate method so that it can be a unit test in isolation - without having to call the while loop from the inside, which StreamReader processes.
The problem you see is related to lazy enumeration evaluation. Since none of your test codes actually lists “things,” the state machine that is created “behind the scenes” to process the iterator block is never processed.
You will need to list the elements for the actual execution of the logic in the Parse method. You can do this with the Rhino.Mocks "WhenCalled" method (I show the AAA syntax since I don’t remember how to use the record / play semantics):
NOTE. This is unverified code.
datamanager.Stub(d => d.Save(null)).IgnoreArguments().WhenCalled(m => int count = ((IEnumerable<string>)m.Arguments[0]).Count());
What happens when the Save method is called on your stub, "WhenCalled" passes the parameter (m), which contains information about the called method. Take the first argument (things), drop it until IEnumerable<string> and get its score. This will result in an evaluation of the enumerable.
source share