0

嗨,我有一个方法,女巫有两个 for 循环。方法如下所示:

 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;
    }

我想要两个为它创建两个单元测试。一个用于验证第一个 foreach 循环被调用了多少次。第二个用于验证第二个 foreach 循环被调用了多少次。

我使用 moq 作为我的模拟框架,通常在这种情况下,我会从外部类调用一些附加方法,使用它我可以确定在循环中调用了多少次该方法。但在我当前场景我找不到测试这个的方法。

谁能给我一些关于我应该如何进行的想法?

4

0 回答 0