Answered MoleNotImplementedException

  • 23 April 2012 12:40
     
      Memiliki Kode

    Hi,

    I'm a newbie with Moles so forgive the simple question but according to documentation I think this should work:

    MDataServiceCollection<string> dataServiceCollectionMock =
    new MDataServiceCollection<string>(); new MCollection<string>(dataServiceCollectionMock) { SystemCollectionsIEnumerableGetEnumerator = () => { return new List<string>(new string[] { "a", "b", "c" }).GetEnumerator(); } }; string result = string.Empty; foreach (string s in dataServiceCollectionMock.Instance) { result += s; }

    I'm replacing GetEnumerator with my own implementation so that I can inject the values I iterate through when using an instance of DataServiceCollection. I'm expecting s to return "abc". However I get the following exception thrown:

    Microsoft.Moles.Framework.Moles.MoleNotImplementedException: Collection`1.GetEnumerator() was not moled.

    Any help greatly appreciated.


    Regards, Chris.

Semua Balasan

  • 24 April 2012 8:46
    Moderator
     
     

    Hi Christopher,

    As the PEX and Mole team mentioned that they will  migrate to forums  stackoverflow.com, you could get better help from there.

    Hope this could help you.


    Tony Xiao [MSFT]
    MSDN Community Support | Feedback to us


  • 25 April 2012 8:07
     
     Jawab Memiliki Kode

    Worked out the answer.

    Rather than:

    SystemCollectionsIEnumerableGetEnumerator = () =>
                {
                    return new List<string>(new string[] { "a", "b", "c" }).GetEnumerator();
                }
    

    Should be:

    GetEnumerator = () =>
                {
                    return new List<string>(new string[] { "a", "b", "c" }).GetEnumerator();
                }
    


    Regards, Chris.