Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use FakeItEasy to fake Enumerable class
    primarykey
    data
    text
    <p>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 :</p> <p>I have the following class that implements <code>IEnumerable</code> and internal class that implements <code>IEnumerator</code> (not complete code below) :</p> <pre><code>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 &lt; strings.Length; } public void Reset() { _position = -1; } } public IEnumerator GetEnumerator() { return new StringEnumerator(_strings); } } </code></pre> <p>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) :</p> <pre><code>IEnumarableString stringFake = A.Fake&lt;IEnumarableString&gt;(); A.CallTo(() =&gt; stringFake.GetEnumerator().MoveNext()).Returns(false).Once(); A.CallTo(() =&gt; stringFake.GetEnumerator().MoveNext()).Returns(true).Once(); </code></pre> <p>tried to search the net for example but could not find any. for now my question is how do I configure the <code>stringFake.GetEnumerator()</code> to return the right object so the iteration will work or am I doing something wrong here ?</p> <p>Any help would be appreciated.</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload