I'm very new to mock object. First time in my head is try to instantiate
a DynamicMock() object and then continue with it's ExpectAndReturn() method.
For IGrouping interface, there's only one property, Key. So if I want to set up ExpectAndReturn to make it work in foreach, maybe I have to go to implement the Current, Next(), Reset() of IEnumerator.
That's not easy to set up mock object and waste a lot of development time.
Now my solution is like this:
//prepare expected list of objects that want to be tested
List<MyObject> list = new List<MyObject>();
list.Add(new MyObject() {BookingNo="111",...});
list.Add(new MyObject() {BookingNo="111",...});
// grouping objects in list
IEnumberable<IGrouping<string, MyObject>> group = list.GroupBy(p => p.BookingNo);
//in my test method
myReturnObj obj = MethodA(group.First());
Assert.xx(...);
Thank you very much, David B!