chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hi,

Can you please assist me with faking the iteration in the foreach loop in the following code?

  public class Class1
  { 
        MySystem system;

        private void GenerateObjectXML(IObject obj)
        { 
            NodeRef nodeRef = new StructureNodeRef(obj); 
            IStructureN structureNode = system.currentManager.Operations.GetNode(nodeRef); 
            IStructureNCollection structureNodeCollection = structureNode.ListDescendents();
 
            if (structureNodeCollection != null) 
            { 
                foreach (IStructureNode node in structureNodeCollection)  
                {
                    String name = node.GetName;
                } 
            }

        }
  }
asked by Crispin (1.6k points)

2 Answers

0 votes
I think that this is what you are looking for:
Isolate.WhenCalled(()=>system.currentManager.Operations.GetNode(null).ListDescendents()).WillReturnCollectionOf(new [] { Isolate.Fake.Instance<IStructureNode>()});
answered by alex (17k points)
0 votes
Thanks, that did the trick :D
answered by Crispin (1.6k points)
...