If you can't just provide a concrete IEnumerable<string>
as @TimS suggested, because you need extra functionality, I think I have a solution for you.
I think the problem you're having is because the unconfigured GetEnumerator()
on stringFake
will always return a new enumerator (FakeItEasy will have unconfigured properties always return the same value, but unconfigured methods do not cache their return values and will give new values easy time).
If you configure it to return a particular enumerator, you should have better luck. I don't have a compiler with me, but something like:
IEnumarableString stringFake = A.Fake<IEnumarableString>();
IEnumerator<string> fakeEnumerator = A.Fake<IEnumerator<string>>();
A.CallTo(() => stringFake.GetEnumerator()).Returns(fakeEnumerator);
A.CallTo(() => fakeEnumerator.MoveNext()).ReturnsNextFromSequence(true, false);
Or something. Note that you'll also have to set up the behaviour on fakeEnumerator.Current
. There is already a question that deal with faking an enumerator. You should be able to see it for additional details—Faking an enumerator in FakeItEasy