I am learning to use/perform/write tests for my code and started using FakeItEasy for my fake/mock objects, now I have encountered a problem :
I have the following class that implements IEnumerable
and internal class that implements IEnumerator
(not complete code below) :
public interface IEnumarableString : IEnumarable
{ }
public class AdvancedString : IEnumarableString
{
private string[] _strings;
private class StringEnumerator : IEnumerator
{
private IEnumerator GetEnumerator()
{
return (IEnumerator)this;
}
public object Current {get; set;}
public bool MoveNext()
{
_position++;
return _position < strings.Length;
}
public void Reset()
{
_position = -1;
}
}
public IEnumerator GetEnumerator()
{
return new StringEnumerator(_strings);
}
}
I want to use FakeItEasy on my tests and "fake" its iterative behavior, I tried the following code but it does not iterate through itself when it needs to (just skip the foreach like there are no elements) :
IEnumarableString stringFake = A.Fake<IEnumarableString>();
A.CallTo(() => stringFake.GetEnumerator().MoveNext()).Returns(false).Once();
A.CallTo(() => stringFake.GetEnumerator().MoveNext()).Returns(true).Once();
tried to search the net for example but could not find any.
for now my question is how do I configure the stringFake.GetEnumerator()
to return the right object so the iteration will work or am I doing something wrong here ?
Any help would be appreciated.
Thanks