c# - Testing how many time a for loop has run -


hi have method witch has 2 loops.the method looks this:

 public elearningsessionsdto filterelearningsession(ienumerable<getelearningsessionsforstudent_result> elearningsession)     {         var elearningsessiondto = new elearningsessionsdto();         var clossedlessons = new list<lessonsinelearningdto>();         var plannedlessons = new list<lessonsinelearningdto>();          var grouplessons = elearningsession.groupby(key => new { key.lessonnumber, key.lessontitle, key.targetdate },                                                     data => new { data.status, data.eventtitle });          foreach (var grouplesson in grouplessons)         {             bool isplanned = false;              var lessoninelearningdto = new lessonsinelearningdto             {                 lessonnumber = grouplesson.key.lessonnumber,                 lessontitle = grouplesson.key.lessontitle,                 targetdate = grouplesson.key.targetdate             };             var assignmentsinlessondto = new list<assignmentsinlessondto>();              foreach (var assignment in grouplesson)             {                 var assignmentinlessondto = new assignmentsinlessondto                 {                     eventtitle = assignment.eventtitle,                     status = assignment.status                 };                  if (assignment.status != (int)elearningeventsubscriptionstatuses.closed)                 {                     isplanned = true;                 }                 assignmentsinlessondto.add(assignmentinlessondto);             }              lessoninelearningdto.lessonsassignments = assignmentsinlessondto;              if (isplanned)             {                 plannedlessons.add(lessoninelearningdto);             }             else             {                 clossedlessons.add(lessoninelearningdto);             }         }          elearningsessiondto.clossedlessons = clossedlessons;         elearningsessiondto.plannedlessons = plannedlessons;          return elearningsessiondto;     } 

i want 2 create 2 unit tests it.one verifying how many times first foreach loop called.and second verifying how many times second foreach loop called.

i using moq mocking framework , in kind of scenarios have aditional method called external class , using able determine how many times in loop method called.but in current scenario can not find way test this.

can give ideea on how should proceed?


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -