0

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.

cmo999
  • 2,409
  • 1
  • 14
  • 2

1 Answers1

0

Worked out the solution - calling the wrong method to mole.

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();
        }
cmo999
  • 2,409
  • 1
  • 14
  • 2