none
MoleNotImplementedException

    Question

  • 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.

    Monday, April 23, 2012 12:40 PM

Answers

  • 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.

    Wednesday, April 25, 2012 8:07 AM

All replies

  • 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


    Tuesday, April 24, 2012 8:46 AM
  • 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.

    Wednesday, April 25, 2012 8:07 AM