Hi there, gurus.
I'm sure a lot of you were thinking 'Thank goodness THAT guy disappeared', but I'm here to disappoint you.
My question this time about using Moq with C# to create a mock that will return each letter of a supplied string each time it is called. A simplified example of what I want is:
var sourceText = "abcdefg";
var myMock = new Mock<IThingy>():
myMock.Setup((mm) => mm.NextChar()).Returns(() => { =some code= });
var result = myMock.NextChar();
result = myMock.NextChar();
...
I know I could do this with
Sequence(), but that involves hardcoding the return values, which I don't want to do.
What I have tried:
I tried using
yield return, but
yield is not valid in an anonymous method.
I tried setting up a method that uses
yield return, and that would be called by
=some code=, but that method would need to return an
IEnumerable<string> which means
=some code= returns a collection, not a single consecutive character each time.